1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: resourcemanager.cxx,v $
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>
45 static ResMgr
* pResMgr
= 0;
46 static SvtSysLocale
* pSysLocale
= 0;
48 ResMgr
* GetResMgr( void )
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() );
63 const LocaleDataWrapper
& GetLocaleData( void )
66 pSysLocale
= new SvtSysLocale
;
67 return pSysLocale
->GetLocaleData();
70 DateTime
GetDateTime( const ::com::sun::star::util::DateTime
& _rDT
)
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
) );
84 sRet
+= rLoDa
.getTime( aDT
);
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
);
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
};
117 STATE e
= _bPreserveId
? PRE_ID
: ID
;
119 const sal_Unicode
* p
= _rRawString
.GetBuffer();
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
);
144 if( c
== cEqualSign
)
145 e
= _bPreserveId
? PRE_CONT
: CONT
;
159 s
+= aCommaReplacement
;
160 e
= _bPreserveId
? PRE_ID
: ID
;
170 // xub_StrLen nEquPos = _rRawString.SearchAscii( "=" );
171 // if( nEquPos == STRING_NOTFOUND )
176 // s = String( _rRawString, nEquPos, STRING_MAXLEN );
177 // s.EraseLeadingAndTrailingChars();
183 String
GetContentPart( const String
& _rRawString
, const String
& _rPartId
)
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
);
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
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
);
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();
236 const char pHexDigs
[ 17 ] = "0123456789ABCDEF";
237 char pBuffer
[ 3 ] = " ";
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 ];
248 pBuffer
[ 0 ] = pHexDigs
[ nNum
];
249 aStr
.AppendAscii( pBuffer
);
253 aStr
.AppendAscii( _pSep
);
256 nBreak
= nBreakStart
;
257 aStr
.AppendAscii( "\n" );
264 long ShrinkToFitWidth( Control
& _rCtrl
, long _nOffs
)
266 long nWidth
= _rCtrl
.GetTextWidth( _rCtrl
.GetText() );
267 Size
aSize( _rCtrl
.GetSizePixel() );
269 aSize
.Width() = nWidth
;
270 _rCtrl
.SetSizePixel( aSize
);
274 void AlignAfterImage( const FixedImage
& _rImage
, Control
& _rCtrl
, long _nXOffset
)
276 Point
aPos( _rImage
.GetPosPixel() );
277 Size
aSize( _rImage
.GetSizePixel() );
283 n
+= aSize
.Height() / 2; // y-position is in the middle of the image
284 n
-= _rCtrl
.GetSizePixel().Height() / 2; // center Control
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
);