update dev300-m58
[ooovba.git] / xmlsecurity / source / dialogs / resourcemanager.cxx
blobd7f3deb203d1eb7f508c0714acd4a288415d4094
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: resourcemanager.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlsecurity.hxx"
34 #include "resourcemanager.hxx"
36 #include <vcl/svapp.hxx>
37 #include <vcl/fixed.hxx>
38 #include <svtools/stdctrl.hxx>
39 #include <svtools/solar.hrc>
40 #include <svtools/syslocale.hxx>
43 namespace XmlSec
45 static ResMgr* pResMgr = 0;
46 static SvtSysLocale* pSysLocale = 0;
48 ResMgr* GetResMgr( void )
50 if( !pResMgr )
52 ByteString aName( "xmlsec" );
53 // pResMgr = ResMgr::CreateResMgr( aName.GetBuffer(), Application::GetSettings().GetUILanguage() );
54 // LanguageType aLang( LANGUAGE_ENGLISH_US );
55 // pResMgr = ResMgr::CreateResMgr( aName.GetBuffer(), aLang );
56 // MT: Change to Locale
57 pResMgr = ResMgr::CreateResMgr( aName.GetBuffer() );
60 return pResMgr;
63 const LocaleDataWrapper& GetLocaleData( void )
65 if (!pSysLocale)
66 pSysLocale = new SvtSysLocale;
67 return pSysLocale->GetLocaleData();
70 DateTime GetDateTime( const ::com::sun::star::util::DateTime& _rDT )
72 return DateTime(
73 Date( _rDT.Day, _rDT.Month, _rDT.Year ),
74 Time( _rDT.Hours, _rDT.Minutes, _rDT.Seconds, _rDT.HundredthSeconds ) );
77 String GetDateTimeString( const ::com::sun::star::util::DateTime& _rDT )
79 // --> PB 2004-10-12 #i20172# String with date and time information
80 DateTime aDT( GetDateTime( _rDT ) );
81 const LocaleDataWrapper& rLoDa = GetLocaleData();
82 String sRet( rLoDa.getDate( aDT ) );
83 sRet += ' ';
84 sRet += rLoDa.getTime( aDT );
85 return sRet;
88 String GetDateTimeString( const rtl::OUString& _rDate, const rtl::OUString& _rTime )
90 String sDay( _rDate, 6, 2 );
91 String sMonth( _rDate, 4, 2 );
92 String sYear( _rDate, 0, 4 );
94 String sHour( _rTime, 0, 2 );
95 String sMin( _rTime, 4, 2 );
96 String sSec( _rTime, 6, 2 );
99 Date aDate( (USHORT)sDay.ToInt32(), (USHORT) sMonth.ToInt32(), (USHORT)sYear.ToInt32() );
100 Time aTime( sHour.ToInt32(), sMin.ToInt32(), sSec.ToInt32(), 0 );
101 const LocaleDataWrapper& rLoDa = GetLocaleData();
102 String aStr( rLoDa.getDate( aDate ) );
103 aStr.AppendAscii( " " );
104 aStr += rLoDa.getTime( aTime );
105 return aStr;
108 String GetDateString( const ::com::sun::star::util::DateTime& _rDT )
110 return GetLocaleData().getDate( GetDateTime( _rDT ) );
113 String GetPureContent( const String& _rRawString, const char* _pCommaReplacement, bool _bPreserveId )
115 enum STATE { PRE_ID, ID, EQUALSIGN, PRE_CONT, CONT };
116 String s;
117 STATE e = _bPreserveId? PRE_ID : ID;
119 const sal_Unicode* p = _rRawString.GetBuffer();
120 sal_Unicode c;
121 const sal_Unicode cComma = ',';
122 const sal_Unicode cEqualSign = '=';
123 const sal_Unicode cSpace = ' ';
124 String aCommaReplacement;
125 if( _pCommaReplacement )
126 aCommaReplacement = String::CreateFromAscii( _pCommaReplacement );
128 while( *p )
130 c = *p;
131 switch( e )
133 case PRE_ID:
134 if( c != cSpace )
136 s += c;
137 e = ID;
139 break;
140 case ID:
141 if( _bPreserveId )
142 s += c;
144 if( c == cEqualSign )
145 e = _bPreserveId? PRE_CONT : CONT;
146 break;
147 case EQUALSIGN:
148 break;
149 case PRE_CONT:
150 if( c != cSpace )
152 s += c;
153 e = CONT;
155 break;
156 case CONT:
157 if( c == cComma )
159 s += aCommaReplacement;
160 e = _bPreserveId? PRE_ID : ID;
162 else
163 s += c;
164 break;
167 ++p;
170 // xub_StrLen nEquPos = _rRawString.SearchAscii( "=" );
171 // if( nEquPos == STRING_NOTFOUND )
172 // s = _rRawString;
173 // else
174 // {
175 // ++nEquPos;
176 // s = String( _rRawString, nEquPos, STRING_MAXLEN );
177 // s.EraseLeadingAndTrailingChars();
178 // }
180 return s;
183 String GetContentPart( const String& _rRawString, const String& _rPartId )
185 String s;
187 xub_StrLen nContStart = _rRawString.Search( _rPartId );
188 if( nContStart != STRING_NOTFOUND )
190 nContStart = nContStart + _rPartId.Len();
191 ++nContStart; // now it's start of content, directly after Id
193 xub_StrLen nContEnd = _rRawString.Search( sal_Unicode( ',' ), nContStart );
195 s = String( _rRawString, nContStart, nContEnd - nContStart );
198 return s;
202 * This Method should consider some string like "C=CN-XXX , O=SUN-XXX , CN=Jack" ,
203 * here the first CN represent china , and the second CN represent the common name ,
204 * so I changed the method to handle this .
205 * By CP , mailto : chandler.peng@sun.com
207 String GetContentPart( const String& _rRawString )
209 // search over some parts to find a string
210 //static char* aIDs[] = { "CN", "OU", "O", "E", NULL };
211 static char const * aIDs[] = { "CN=", "OU=", "O=", "E=", NULL };// By CP
212 String sPart;
213 int i = 0;
214 while ( aIDs[i] )
216 String sPartId = String::CreateFromAscii( aIDs[i++] );
217 xub_StrLen nContStart = _rRawString.Search( sPartId );
218 if ( nContStart != STRING_NOTFOUND )
220 nContStart = nContStart + sPartId.Len();
221 //++nContStart; // now it's start of content, directly after Id // delete By CP
222 xub_StrLen nContEnd = _rRawString.Search( sal_Unicode( ',' ), nContStart );
223 sPart = String( _rRawString, nContStart, nContEnd - nContStart );
224 break;
228 return sPart;
231 String GetHexString( const ::com::sun::star::uno::Sequence< sal_Int8 >& _rSeq, const char* _pSep, UINT16 _nLineBreak )
233 const sal_Int8* pSerNumSeq = _rSeq.getConstArray();
234 int nCnt = _rSeq.getLength();
235 String aStr;
236 const char pHexDigs[ 17 ] = "0123456789ABCDEF";
237 char pBuffer[ 3 ] = " ";
238 UINT8 nNum;
239 UINT16 nBreakStart = _nLineBreak? _nLineBreak : 1;
240 UINT16 nBreak = nBreakStart;
241 for( int i = 0 ; i < nCnt ; ++i )
243 nNum = UINT8( pSerNumSeq[ i ] );
245 //MM : exchange the buffer[0] and buffer[1], which make it consistent with Mozilla and Windows
246 pBuffer[ 1 ] = pHexDigs[ nNum & 0x0F ];
247 nNum >>= 4;
248 pBuffer[ 0 ] = pHexDigs[ nNum ];
249 aStr.AppendAscii( pBuffer );
251 --nBreak;
252 if( nBreak )
253 aStr.AppendAscii( _pSep );
254 else
256 nBreak = nBreakStart;
257 aStr.AppendAscii( "\n" );
261 return aStr;
264 long ShrinkToFitWidth( Control& _rCtrl, long _nOffs )
266 long nWidth = _rCtrl.GetTextWidth( _rCtrl.GetText() );
267 Size aSize( _rCtrl.GetSizePixel() );
268 nWidth += _nOffs;
269 aSize.Width() = nWidth;
270 _rCtrl.SetSizePixel( aSize );
271 return nWidth;
274 void AlignAfterImage( const FixedImage& _rImage, Control& _rCtrl, long _nXOffset )
276 Point aPos( _rImage.GetPosPixel() );
277 Size aSize( _rImage.GetSizePixel() );
278 long n = aPos.X();
279 n += aSize.Width();
280 n += _nXOffset;
281 aPos.X() = n;
282 n = aPos.Y();
283 n += aSize.Height() / 2; // y-position is in the middle of the image
284 n -= _rCtrl.GetSizePixel().Height() / 2; // center Control
285 aPos.Y() = n;
286 _rCtrl.SetPosPixel( aPos );
289 void AlignAfterImage( const FixedImage& _rImage, FixedInfo& _rFI, long _nXOffset )
291 AlignAfterImage( _rImage, static_cast< Control& >( _rFI ), _nXOffset );
292 ShrinkToFitWidth( _rFI );
295 void AlignAndFitImageAndControl( FixedImage& _rImage, FixedInfo& _rFI, long _nXOffset )
297 _rImage.SetSizePixel( _rImage.GetImage().GetSizePixel() );
298 AlignAfterImage( _rImage, _rFI, _nXOffset );