Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include "stringresource.hxx"
21 : : #include <com/sun/star/io/XTextInputStream.hpp>
22 : : #include <com/sun/star/io/XTextOutputStream.hpp>
23 : : #include <com/sun/star/io/XActiveDataSink.hpp>
24 : : #include <com/sun/star/io/XActiveDataSource.hpp>
25 : : #include <com/sun/star/io/XStream.hpp>
26 : : #include <com/sun/star/io/XSeekable.hpp>
27 : : #include <com/sun/star/embed/ElementModes.hpp>
28 : : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
29 : : #include <cppuhelper/implementationentry.hxx>
30 : : #include <com/sun/star/beans/XPropertySet.hpp>
31 : : #include <com/sun/star/container/XNameAccess.hpp>
32 : : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
33 : :
34 : :
35 : : #include <rtl/ustrbuf.hxx>
36 : : #include <rtl/strbuf.hxx>
37 : : #include <tools/urlobj.hxx>
38 : :
39 : : using namespace ::com::sun::star;
40 : : using namespace ::com::sun::star::lang;
41 : : using namespace ::com::sun::star::uno;
42 : : using namespace ::com::sun::star::ucb;
43 : : using namespace ::com::sun::star::util;
44 : : using namespace ::com::sun::star::embed;
45 : : using namespace ::com::sun::star::container;
46 : :
47 : :
48 : : //.........................................................................
49 : : namespace stringresource
50 : : {
51 : : //.........................................................................
52 : :
53 : : // =============================================================================
54 : : // mutex
55 : : // =============================================================================
56 : :
57 : 0 : ::osl::Mutex& getMutex()
58 : : {
59 : : static ::osl::Mutex* s_pMutex = 0;
60 : 0 : if ( !s_pMutex )
61 : : {
62 : 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
63 : 0 : if ( !s_pMutex )
64 : : {
65 : 0 : static ::osl::Mutex s_aMutex;
66 : 0 : s_pMutex = &s_aMutex;
67 : 0 : }
68 : : }
69 : 0 : return *s_pMutex;
70 : : }
71 : :
72 : :
73 : : // =============================================================================
74 : : // StringResourceImpl
75 : : // =============================================================================
76 : :
77 : : // component operations
78 : 0 : static Sequence< ::rtl::OUString > getSupportedServiceNames_StringResourceImpl()
79 : : {
80 : 0 : Sequence< ::rtl::OUString > names(1);
81 : 0 : names[0] = ::rtl::OUString( "com.sun.star.resource.StringResource" );
82 : 0 : return names;
83 : : }
84 : :
85 : 0 : static ::rtl::OUString getImplementationName_StringResourceImpl()
86 : : {
87 : 0 : return ::rtl::OUString( "com.sun.star.comp.scripting.StringResource" );
88 : : }
89 : :
90 : 0 : static Reference< XInterface > SAL_CALL create_StringResourceImpl(
91 : : Reference< XComponentContext > const & xContext )
92 : : SAL_THROW(())
93 : : {
94 : 0 : return static_cast< ::cppu::OWeakObject * >( new StringResourcePersistenceImpl( xContext ) );
95 : : }
96 : :
97 : :
98 : : // =============================================================================
99 : :
100 : 0 : StringResourceImpl::StringResourceImpl( const Reference< XComponentContext >& rxContext )
101 : : : m_xContext( rxContext )
102 : : , m_pCurrentLocaleItem( NULL )
103 : : , m_pDefaultLocaleItem( NULL )
104 : : , m_bDefaultModified( false )
105 : 0 : , m_aListenerContainer( getMutex() )
106 : : , m_bModified( false )
107 : : , m_bReadOnly( false )
108 : 0 : , m_nNextUniqueNumericId( UNIQUE_NUMBER_NEEDS_INITIALISATION )
109 : : {
110 : 0 : }
111 : :
112 : : // =============================================================================
113 : :
114 : 0 : StringResourceImpl::~StringResourceImpl()
115 : : {
116 : 0 : for( LocaleItemVectorIt it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
117 : : {
118 : 0 : LocaleItem* pLocaleItem = *it;
119 : 0 : delete pLocaleItem;
120 : : }
121 : :
122 : 0 : for( LocaleItemVectorIt it = m_aDeletedLocaleItemVector.begin(); it != m_aDeletedLocaleItemVector.end(); ++it )
123 : : {
124 : 0 : LocaleItem* pLocaleItem = *it;
125 : 0 : delete pLocaleItem;
126 : : }
127 : 0 : }
128 : :
129 : :
130 : : // =============================================================================
131 : : // XServiceInfo
132 : :
133 : 0 : ::rtl::OUString StringResourceImpl::getImplementationName( ) throw (RuntimeException)
134 : : {
135 : 0 : return getImplementationName_StringResourceImpl();
136 : : }
137 : :
138 : 0 : sal_Bool StringResourceImpl::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
139 : : {
140 : 0 : Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
141 : 0 : const ::rtl::OUString* pNames = aNames.getConstArray();
142 : 0 : const ::rtl::OUString* pEnd = pNames + aNames.getLength();
143 : 0 : for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
144 : : ;
145 : :
146 : 0 : return pNames != pEnd;
147 : : }
148 : :
149 : 0 : Sequence< ::rtl::OUString > StringResourceImpl::getSupportedServiceNames( ) throw (RuntimeException)
150 : : {
151 : 0 : return getSupportedServiceNames_StringResourceImpl();
152 : : }
153 : :
154 : :
155 : : // =============================================================================
156 : : // XModifyBroadcaster
157 : :
158 : 0 : void StringResourceImpl::addModifyListener( const Reference< XModifyListener >& aListener )
159 : : throw (RuntimeException)
160 : : {
161 : 0 : if( !aListener.is() )
162 : 0 : throw RuntimeException();
163 : :
164 : 0 : ::osl::MutexGuard aGuard( getMutex() );
165 : 0 : Reference< XInterface > xIface( aListener, UNO_QUERY );
166 : 0 : m_aListenerContainer.addInterface( xIface );
167 : 0 : }
168 : :
169 : 0 : void StringResourceImpl::removeModifyListener( const Reference< XModifyListener >& aListener )
170 : : throw (RuntimeException)
171 : : {
172 : 0 : if( !aListener.is() )
173 : 0 : throw RuntimeException();
174 : :
175 : 0 : ::osl::MutexGuard aGuard( getMutex() );
176 : 0 : Reference< XInterface > xIface( aListener, UNO_QUERY );
177 : 0 : m_aListenerContainer.removeInterface( xIface );
178 : 0 : }
179 : :
180 : :
181 : : // =============================================================================
182 : : // XStringResourceResolver
183 : :
184 : 0 : ::rtl::OUString StringResourceImpl::implResolveString
185 : : ( const ::rtl::OUString& ResourceID, LocaleItem* pLocaleItem )
186 : : throw (::com::sun::star::resource::MissingResourceException)
187 : : {
188 : 0 : ::rtl::OUString aRetStr;
189 : 0 : bool bSuccess = false;
190 : 0 : if( pLocaleItem != NULL && loadLocale( pLocaleItem ) )
191 : : {
192 : 0 : IdToStringMap::iterator it = pLocaleItem->m_aIdToStringMap.find( ResourceID );
193 : 0 : if( !( it == pLocaleItem->m_aIdToStringMap.end() ) )
194 : : {
195 : 0 : aRetStr = (*it).second;
196 : 0 : bSuccess = true;
197 : : }
198 : : }
199 : 0 : if( !bSuccess )
200 : : {
201 : 0 : ::rtl::OUString errorMsg("StringResourceImpl: No entry for ResourceID: ");
202 : 0 : errorMsg.concat( ResourceID );
203 : 0 : throw ::com::sun::star::resource::MissingResourceException( errorMsg, Reference< XInterface >() );
204 : : }
205 : 0 : return aRetStr;
206 : : }
207 : :
208 : 0 : ::rtl::OUString StringResourceImpl::resolveString( const ::rtl::OUString& ResourceID )
209 : : throw (::com::sun::star::resource::MissingResourceException, RuntimeException)
210 : : {
211 : 0 : ::osl::MutexGuard aGuard( getMutex() );
212 : 0 : return implResolveString( ResourceID, m_pCurrentLocaleItem );
213 : : }
214 : :
215 : 0 : ::rtl::OUString StringResourceImpl::resolveStringForLocale( const ::rtl::OUString& ResourceID, const Locale& locale )
216 : : throw ( ::com::sun::star::resource::MissingResourceException, RuntimeException)
217 : : {
218 : 0 : ::osl::MutexGuard aGuard( getMutex() );
219 : 0 : LocaleItem* pLocaleItem = getItemForLocale( locale, false );
220 : 0 : return implResolveString( ResourceID, pLocaleItem );
221 : : }
222 : :
223 : 0 : sal_Bool StringResourceImpl::implHasEntryForId( const ::rtl::OUString& ResourceID, LocaleItem* pLocaleItem )
224 : : {
225 : 0 : bool bSuccess = false;
226 : 0 : if( pLocaleItem != NULL && loadLocale( pLocaleItem ) )
227 : : {
228 : 0 : IdToStringMap::iterator it = pLocaleItem->m_aIdToStringMap.find( ResourceID );
229 : 0 : if( !( it == pLocaleItem->m_aIdToStringMap.end() ) )
230 : 0 : bSuccess = true;
231 : : }
232 : 0 : return bSuccess;
233 : : }
234 : :
235 : 0 : sal_Bool StringResourceImpl::hasEntryForId( const ::rtl::OUString& ResourceID )
236 : : throw (RuntimeException)
237 : : {
238 : 0 : ::osl::MutexGuard aGuard( getMutex() );
239 : 0 : return implHasEntryForId( ResourceID, m_pCurrentLocaleItem );
240 : : }
241 : :
242 : 0 : sal_Bool StringResourceImpl::hasEntryForIdAndLocale( const ::rtl::OUString& ResourceID,
243 : : const Locale& locale )
244 : : throw (RuntimeException)
245 : : {
246 : 0 : ::osl::MutexGuard aGuard( getMutex() );
247 : 0 : LocaleItem* pLocaleItem = getItemForLocale( locale, false );
248 : 0 : return implHasEntryForId( ResourceID, pLocaleItem );
249 : : }
250 : :
251 : 0 : Sequence< ::rtl::OUString > StringResourceImpl::implGetResourceIDs( LocaleItem* pLocaleItem )
252 : : {
253 : 0 : Sequence< ::rtl::OUString > aIDSeq( 0 );
254 : 0 : if( pLocaleItem && loadLocale( pLocaleItem ) )
255 : : {
256 : 0 : const IdToStringMap& rHashMap = pLocaleItem->m_aIdToStringMap;
257 : 0 : sal_Int32 nResourceIDCount = rHashMap.size();
258 : 0 : aIDSeq.realloc( nResourceIDCount );
259 : 0 : ::rtl::OUString* pStrings = aIDSeq.getArray();
260 : :
261 : 0 : IdToStringMap::const_iterator it;
262 : 0 : int iTarget = 0;
263 : 0 : for( it = rHashMap.begin(); it != rHashMap.end(); ++it )
264 : : {
265 : 0 : ::rtl::OUString aStr = (*it).first;
266 : 0 : pStrings[iTarget] = aStr;
267 : 0 : iTarget++;
268 : 0 : }
269 : : }
270 : 0 : return aIDSeq;
271 : : }
272 : :
273 : 0 : Sequence< ::rtl::OUString > StringResourceImpl::getResourceIDsForLocale
274 : : ( const Locale& locale ) throw (::com::sun::star::uno::RuntimeException)
275 : : {
276 : 0 : ::osl::MutexGuard aGuard( getMutex() );
277 : 0 : LocaleItem* pLocaleItem = getItemForLocale( locale, false );
278 : 0 : return implGetResourceIDs( pLocaleItem );
279 : : }
280 : :
281 : 0 : Sequence< ::rtl::OUString > StringResourceImpl::getResourceIDs( )
282 : : throw (RuntimeException)
283 : : {
284 : 0 : ::osl::MutexGuard aGuard( getMutex() );
285 : 0 : return implGetResourceIDs( m_pCurrentLocaleItem );
286 : : }
287 : :
288 : 0 : Locale StringResourceImpl::getCurrentLocale()
289 : : throw (RuntimeException)
290 : : {
291 : 0 : ::osl::MutexGuard aGuard( getMutex() );
292 : :
293 : 0 : Locale aRetLocale;
294 : 0 : if( m_pCurrentLocaleItem != NULL )
295 : 0 : aRetLocale = m_pCurrentLocaleItem->m_locale;
296 : 0 : return aRetLocale;
297 : : }
298 : :
299 : 0 : Locale StringResourceImpl::getDefaultLocale( )
300 : : throw (RuntimeException)
301 : : {
302 : 0 : ::osl::MutexGuard aGuard( getMutex() );
303 : :
304 : 0 : Locale aRetLocale;
305 : 0 : if( m_pDefaultLocaleItem != NULL )
306 : 0 : aRetLocale = m_pDefaultLocaleItem->m_locale;
307 : 0 : return aRetLocale;
308 : : }
309 : :
310 : 0 : Sequence< Locale > StringResourceImpl::getLocales( )
311 : : throw (RuntimeException)
312 : : {
313 : 0 : ::osl::MutexGuard aGuard( getMutex() );
314 : :
315 : 0 : sal_Int32 nSize = m_aLocaleItemVector.size();
316 : 0 : Sequence< Locale > aLocalSeq( nSize );
317 : 0 : Locale* pLocales = aLocalSeq.getArray();
318 : 0 : int iTarget = 0;
319 : 0 : for( LocaleItemVectorConstIt it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
320 : : {
321 : 0 : LocaleItem* pLocaleItem = *it;
322 : 0 : pLocales[iTarget] = pLocaleItem->m_locale;
323 : 0 : iTarget++;
324 : : }
325 : 0 : return aLocalSeq;
326 : : }
327 : :
328 : :
329 : : // =============================================================================
330 : : // XStringResourceManager
331 : :
332 : 0 : void StringResourceImpl::implCheckReadOnly( const sal_Char* pExceptionMsg )
333 : : throw (NoSupportException)
334 : : {
335 : 0 : if( m_bReadOnly )
336 : : {
337 : 0 : ::rtl::OUString errorMsg = ::rtl::OUString::createFromAscii( pExceptionMsg );
338 : 0 : throw NoSupportException( errorMsg, Reference< XInterface >() );
339 : : }
340 : 0 : }
341 : :
342 : 0 : sal_Bool StringResourceImpl::isReadOnly()
343 : : throw (RuntimeException)
344 : : {
345 : 0 : return m_bReadOnly;
346 : : }
347 : :
348 : 0 : void StringResourceImpl::implSetCurrentLocale( const Locale& locale,
349 : : sal_Bool FindClosestMatch, sal_Bool bUseDefaultIfNoMatch )
350 : : throw (IllegalArgumentException, RuntimeException)
351 : : {
352 : 0 : ::osl::MutexGuard aGuard( getMutex() );
353 : :
354 : 0 : LocaleItem* pLocaleItem = NULL;
355 : 0 : if( FindClosestMatch )
356 : 0 : pLocaleItem = getClosestMatchItemForLocale( locale );
357 : : else
358 : 0 : pLocaleItem = getItemForLocale( locale, true );
359 : :
360 : 0 : if( pLocaleItem == NULL && bUseDefaultIfNoMatch )
361 : 0 : pLocaleItem = m_pDefaultLocaleItem;
362 : :
363 : 0 : if( pLocaleItem != NULL )
364 : : {
365 : 0 : loadLocale( pLocaleItem );
366 : 0 : m_pCurrentLocaleItem = pLocaleItem;
367 : :
368 : : // Only notify without modifying
369 : 0 : implNotifyListeners();
370 : 0 : }
371 : 0 : }
372 : :
373 : 0 : void StringResourceImpl::setCurrentLocale( const Locale& locale, sal_Bool FindClosestMatch )
374 : : throw (IllegalArgumentException, RuntimeException)
375 : : {
376 : 0 : sal_Bool bUseDefaultIfNoMatch = false;
377 : 0 : implSetCurrentLocale( locale, FindClosestMatch, bUseDefaultIfNoMatch );
378 : 0 : }
379 : :
380 : 0 : void StringResourceImpl::setDefaultLocale( const Locale& locale )
381 : : throw (IllegalArgumentException, RuntimeException,NoSupportException)
382 : : {
383 : 0 : ::osl::MutexGuard aGuard( getMutex() );
384 : 0 : implCheckReadOnly( "StringResourceImpl::setDefaultLocale(): Read only" );
385 : :
386 : 0 : LocaleItem* pLocaleItem = getItemForLocale( locale, true );
387 : 0 : if( pLocaleItem && pLocaleItem != m_pDefaultLocaleItem )
388 : : {
389 : 0 : if( m_pDefaultLocaleItem )
390 : : {
391 : 0 : LocaleItem* pChangedDefaultLocaleItem = new LocaleItem( m_pDefaultLocaleItem->m_locale );
392 : 0 : m_aChangedDefaultLocaleVector.push_back( pChangedDefaultLocaleItem );
393 : : }
394 : :
395 : 0 : m_pDefaultLocaleItem = pLocaleItem;
396 : 0 : m_bDefaultModified = true;
397 : 0 : implModified();
398 : 0 : }
399 : 0 : }
400 : :
401 : 0 : void StringResourceImpl::implSetString( const ::rtl::OUString& ResourceID,
402 : : const ::rtl::OUString& Str, LocaleItem* pLocaleItem )
403 : : {
404 : 0 : if( pLocaleItem != NULL && loadLocale( pLocaleItem ) )
405 : : {
406 : 0 : IdToStringMap& rHashMap = pLocaleItem->m_aIdToStringMap;
407 : :
408 : 0 : IdToStringMap::iterator it = rHashMap.find( ResourceID );
409 : 0 : bool bNew = ( it == rHashMap.end() );
410 : 0 : if( bNew )
411 : : {
412 : 0 : IdToIndexMap& rIndexMap = pLocaleItem->m_aIdToIndexMap;
413 : 0 : rIndexMap[ ResourceID ] = pLocaleItem->m_nNextIndex++;
414 : 0 : implScanIdForNumber( ResourceID );
415 : : }
416 : 0 : rHashMap[ ResourceID ] = Str;
417 : 0 : pLocaleItem->m_bModified = true;
418 : 0 : implModified();
419 : : }
420 : 0 : }
421 : :
422 : 0 : void StringResourceImpl::setString( const ::rtl::OUString& ResourceID, const ::rtl::OUString& Str )
423 : : throw (NoSupportException, RuntimeException)
424 : : {
425 : 0 : ::osl::MutexGuard aGuard( getMutex() );
426 : 0 : implCheckReadOnly( "StringResourceImpl::setString(): Read only" );
427 : 0 : implSetString( ResourceID, Str, m_pCurrentLocaleItem );
428 : 0 : }
429 : :
430 : 0 : void StringResourceImpl::setStringForLocale
431 : : ( const ::rtl::OUString& ResourceID, const ::rtl::OUString& Str, const Locale& locale )
432 : : throw (NoSupportException, RuntimeException)
433 : : {
434 : 0 : ::osl::MutexGuard aGuard( getMutex() );
435 : 0 : implCheckReadOnly( "StringResourceImpl::setStringForLocale(): Read only" );
436 : 0 : LocaleItem* pLocaleItem = getItemForLocale( locale, false );
437 : 0 : implSetString( ResourceID, Str, pLocaleItem );
438 : 0 : }
439 : :
440 : 0 : void StringResourceImpl::implRemoveId( const ::rtl::OUString& ResourceID, LocaleItem* pLocaleItem )
441 : : throw (::com::sun::star::resource::MissingResourceException)
442 : : {
443 : 0 : if( pLocaleItem != NULL && loadLocale( pLocaleItem ) )
444 : : {
445 : 0 : IdToStringMap& rHashMap = pLocaleItem->m_aIdToStringMap;
446 : 0 : IdToStringMap::iterator it = rHashMap.find( ResourceID );
447 : 0 : if( it == rHashMap.end() )
448 : : {
449 : 0 : ::rtl::OUString errorMsg("StringResourceImpl: No entries for ResourceID: ");
450 : 0 : errorMsg.concat( ResourceID );
451 : 0 : throw ::com::sun::star::resource::MissingResourceException( errorMsg, Reference< XInterface >() );
452 : : }
453 : 0 : rHashMap.erase( it );
454 : 0 : pLocaleItem->m_bModified = true;
455 : 0 : implModified();
456 : : }
457 : 0 : }
458 : :
459 : 0 : void StringResourceImpl::removeId( const ::rtl::OUString& ResourceID )
460 : : throw (::com::sun::star::resource::MissingResourceException, RuntimeException, NoSupportException)
461 : : {
462 : 0 : ::osl::MutexGuard aGuard( getMutex() );
463 : 0 : implCheckReadOnly( "StringResourceImpl::removeId(): Read only" );
464 : 0 : implRemoveId( ResourceID, m_pCurrentLocaleItem );
465 : 0 : }
466 : :
467 : 0 : void StringResourceImpl::removeIdForLocale( const ::rtl::OUString& ResourceID, const Locale& locale )
468 : : throw (::com::sun::star::resource::MissingResourceException, RuntimeException, NoSupportException)
469 : : {
470 : 0 : ::osl::MutexGuard aGuard( getMutex() );
471 : 0 : implCheckReadOnly( "StringResourceImpl::removeIdForLocale(): Read only" );
472 : 0 : LocaleItem* pLocaleItem = getItemForLocale( locale, false );
473 : 0 : implRemoveId( ResourceID, pLocaleItem );
474 : 0 : }
475 : :
476 : 0 : void StringResourceImpl::newLocale( const Locale& locale )
477 : : throw (ElementExistException, IllegalArgumentException, RuntimeException, NoSupportException)
478 : : {
479 : 0 : ::osl::MutexGuard aGuard( getMutex() );
480 : 0 : implCheckReadOnly( "StringResourceImpl::newLocale(): Read only" );
481 : :
482 : 0 : if( getItemForLocale( locale, false ) != NULL )
483 : : {
484 : 0 : ::rtl::OUString errorMsg("StringResourceImpl: locale already exists");
485 : 0 : throw ElementExistException( errorMsg, Reference< XInterface >() );
486 : : }
487 : :
488 : : // TODO?: Check if locale is valid? How?
489 : 0 : bool bValid = true;
490 : 0 : if( bValid )
491 : : {
492 : 0 : LocaleItem* pLocaleItem = new LocaleItem( locale );
493 : 0 : m_aLocaleItemVector.push_back( pLocaleItem );
494 : 0 : pLocaleItem->m_bModified = true;
495 : :
496 : : // Copy strings from default locale
497 : 0 : LocaleItem* pCopyFromItem = m_pDefaultLocaleItem;
498 : 0 : if( pCopyFromItem == NULL )
499 : 0 : pCopyFromItem = m_pCurrentLocaleItem;
500 : 0 : if( pCopyFromItem != NULL && loadLocale( pCopyFromItem ) )
501 : : {
502 : 0 : const IdToStringMap& rSourceMap = pCopyFromItem->m_aIdToStringMap;
503 : 0 : IdToStringMap& rTargetMap = pLocaleItem->m_aIdToStringMap;
504 : 0 : IdToStringMap::const_iterator it;
505 : 0 : for( it = rSourceMap.begin(); it != rSourceMap.end(); ++it )
506 : : {
507 : 0 : ::rtl::OUString aId = (*it).first;
508 : 0 : ::rtl::OUString aStr = (*it).second;
509 : 0 : rTargetMap[ aId ] = aStr;
510 : 0 : }
511 : :
512 : 0 : const IdToIndexMap& rSourceIndexMap = pCopyFromItem->m_aIdToIndexMap;
513 : 0 : IdToIndexMap& rTargetIndexMap = pLocaleItem->m_aIdToIndexMap;
514 : 0 : IdToIndexMap::const_iterator it_index;
515 : 0 : for( it_index = rSourceIndexMap.begin(); it_index != rSourceIndexMap.end(); ++it_index )
516 : : {
517 : 0 : ::rtl::OUString aId = (*it_index).first;
518 : 0 : sal_Int32 nIndex = (*it_index).second;
519 : 0 : rTargetIndexMap[ aId ] = nIndex;
520 : 0 : }
521 : 0 : pLocaleItem->m_nNextIndex = pCopyFromItem->m_nNextIndex;
522 : : }
523 : :
524 : 0 : if( m_pCurrentLocaleItem == NULL )
525 : 0 : m_pCurrentLocaleItem = pLocaleItem;
526 : :
527 : 0 : if( m_pDefaultLocaleItem == NULL )
528 : : {
529 : 0 : m_pDefaultLocaleItem = pLocaleItem;
530 : 0 : m_bDefaultModified = true;
531 : : }
532 : :
533 : 0 : implModified();
534 : : }
535 : : else
536 : : {
537 : 0 : ::rtl::OUString errorMsg("StringResourceImpl: Invalid locale");
538 : 0 : throw IllegalArgumentException( errorMsg, Reference< XInterface >(), 0 );
539 : 0 : }
540 : 0 : }
541 : :
542 : 0 : void StringResourceImpl::removeLocale( const Locale& locale )
543 : : throw (IllegalArgumentException, RuntimeException, NoSupportException)
544 : : {
545 : 0 : ::osl::MutexGuard aGuard( getMutex() );
546 : 0 : implCheckReadOnly( "StringResourceImpl::removeLocale(): Read only" );
547 : :
548 : 0 : LocaleItem* pRemoveItem = getItemForLocale( locale, true );
549 : 0 : if( pRemoveItem )
550 : : {
551 : : // Last locale?
552 : 0 : sal_Int32 nLocaleCount = m_aLocaleItemVector.size();
553 : 0 : if( nLocaleCount > 1 )
554 : : {
555 : 0 : LocaleItem* pFallbackItem = NULL;
556 : 0 : if( m_pCurrentLocaleItem == pRemoveItem ||
557 : : m_pDefaultLocaleItem == pRemoveItem )
558 : : {
559 : 0 : for( LocaleItemVectorIt it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
560 : : {
561 : 0 : LocaleItem* pLocaleItem = *it;
562 : 0 : if( pLocaleItem != pRemoveItem )
563 : : {
564 : 0 : pFallbackItem = pLocaleItem;
565 : 0 : break;
566 : : }
567 : : }
568 : 0 : if( m_pCurrentLocaleItem == pRemoveItem )
569 : : {
570 : 0 : sal_Bool FindClosestMatch = false;
571 : 0 : setCurrentLocale( pFallbackItem->m_locale, FindClosestMatch );
572 : : }
573 : 0 : if( m_pDefaultLocaleItem == pRemoveItem )
574 : : {
575 : 0 : setDefaultLocale( pFallbackItem->m_locale );
576 : : }
577 : : }
578 : : }
579 : 0 : for( LocaleItemVectorIt it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
580 : : {
581 : 0 : LocaleItem* pLocaleItem = *it;
582 : 0 : if( pLocaleItem == pRemoveItem )
583 : : {
584 : : // Remember locale item to delete file while storing
585 : 0 : m_aDeletedLocaleItemVector.push_back( pLocaleItem );
586 : :
587 : : // Last locale?
588 : 0 : if( nLocaleCount == 1 )
589 : : {
590 : 0 : m_nNextUniqueNumericId = 0;
591 : 0 : if( m_pDefaultLocaleItem )
592 : : {
593 : 0 : LocaleItem* pChangedDefaultLocaleItem = new LocaleItem( m_pDefaultLocaleItem->m_locale );
594 : 0 : m_aChangedDefaultLocaleVector.push_back( pChangedDefaultLocaleItem );
595 : : }
596 : 0 : m_pCurrentLocaleItem = NULL;
597 : 0 : m_pDefaultLocaleItem = NULL;
598 : : }
599 : :
600 : 0 : m_aLocaleItemVector.erase( it );
601 : :
602 : 0 : implModified();
603 : : break;
604 : : }
605 : : }
606 : 0 : }
607 : 0 : }
608 : :
609 : 0 : void StringResourceImpl::implScanIdForNumber( const ::rtl::OUString& ResourceID )
610 : : {
611 : 0 : const sal_Unicode* pSrc = ResourceID.getStr();
612 : 0 : sal_Int32 nLen = ResourceID.getLength();
613 : :
614 : 0 : sal_Int32 nNumber = 0;
615 : 0 : for( sal_Int32 i = 0 ; i < nLen ; i++ )
616 : : {
617 : 0 : sal_Unicode c = pSrc[i];
618 : 0 : if( c >= '0' && c <= '9' )
619 : : {
620 : 0 : sal_uInt16 nDigitVal = c - '0';
621 : 0 : nNumber = 10*nNumber + nDigitVal;
622 : : }
623 : : else
624 : 0 : break;
625 : : }
626 : :
627 : 0 : if( m_nNextUniqueNumericId < nNumber + 1 )
628 : 0 : m_nNextUniqueNumericId = nNumber + 1;
629 : 0 : }
630 : :
631 : 0 : sal_Int32 StringResourceImpl::getUniqueNumericId( )
632 : : throw (RuntimeException, NoSupportException)
633 : : {
634 : 0 : if( m_nNextUniqueNumericId == UNIQUE_NUMBER_NEEDS_INITIALISATION )
635 : : {
636 : 0 : implLoadAllLocales();
637 : 0 : m_nNextUniqueNumericId = 0;
638 : : }
639 : :
640 : 0 : if( m_nNextUniqueNumericId < UNIQUE_NUMBER_NEEDS_INITIALISATION )
641 : : {
642 : 0 : ::rtl::OUString errorMsg("getUniqueNumericId: Extended sal_Int32 range");
643 : 0 : throw NoSupportException( errorMsg, Reference< XInterface >() );
644 : : }
645 : 0 : return m_nNextUniqueNumericId;
646 : : }
647 : :
648 : :
649 : : // =============================================================================
650 : : // Private helper methods
651 : :
652 : 0 : LocaleItem* StringResourceImpl::getItemForLocale
653 : : ( const Locale& locale, sal_Bool bException )
654 : : throw (::com::sun::star::lang::IllegalArgumentException)
655 : : {
656 : 0 : LocaleItem* pRetItem = NULL;
657 : :
658 : : // Search for locale
659 : 0 : for( LocaleItemVectorConstIt it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
660 : : {
661 : 0 : LocaleItem* pLocaleItem = *it;
662 : 0 : if( pLocaleItem )
663 : : {
664 : 0 : Locale& cmp_locale = pLocaleItem->m_locale;
665 : 0 : if( cmp_locale.Language == locale.Language &&
666 : 0 : cmp_locale.Country == locale.Country &&
667 : 0 : cmp_locale.Variant == locale.Variant )
668 : : {
669 : 0 : pRetItem = pLocaleItem;
670 : 0 : break;
671 : : }
672 : : }
673 : : }
674 : :
675 : 0 : if( pRetItem == NULL && bException )
676 : : {
677 : 0 : ::rtl::OUString errorMsg("StringResourceImpl: Invalid locale");
678 : 0 : throw IllegalArgumentException( errorMsg, Reference< XInterface >(), 0 );
679 : : }
680 : 0 : return pRetItem;
681 : : }
682 : :
683 : : // Returns the LocalItem for a given locale, if it exists, otherwise NULL
684 : : // This method performes a closest match search, at least the language must match
685 : 0 : LocaleItem* StringResourceImpl::getClosestMatchItemForLocale( const Locale& locale )
686 : : {
687 : 0 : LocaleItem* pRetItem = NULL;
688 : :
689 : : // Search for locale
690 : 0 : for( sal_Int32 iPass = 0 ; iPass <= 2 ; ++iPass )
691 : : {
692 : 0 : for( LocaleItemVectorConstIt it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
693 : : {
694 : 0 : LocaleItem* pLocaleItem = *it;
695 : 0 : if( pLocaleItem )
696 : : {
697 : 0 : Locale& cmp_locale = pLocaleItem->m_locale;
698 : 0 : if( cmp_locale.Language == locale.Language &&
699 : 0 : (iPass > 1 || cmp_locale.Country == locale.Country) &&
700 : 0 : (iPass > 0 || cmp_locale.Variant == locale.Variant) )
701 : : {
702 : 0 : pRetItem = pLocaleItem;
703 : 0 : break;
704 : : }
705 : : }
706 : : }
707 : 0 : if( pRetItem )
708 : 0 : break;
709 : : }
710 : :
711 : 0 : return pRetItem;
712 : : }
713 : :
714 : 0 : void StringResourceImpl::implModified( void )
715 : : {
716 : 0 : m_bModified = true;
717 : 0 : implNotifyListeners();
718 : 0 : }
719 : :
720 : 0 : void StringResourceImpl::implNotifyListeners( void )
721 : : {
722 : 0 : EventObject aEvent;
723 : 0 : aEvent.Source = static_cast< XInterface* >( (OWeakObject*)this );
724 : :
725 : 0 : ::cppu::OInterfaceIteratorHelper it( m_aListenerContainer );
726 : 0 : while( it.hasMoreElements() )
727 : : {
728 : 0 : Reference< XInterface > xIface = it.next();
729 : 0 : Reference< XModifyListener > xListener( xIface, UNO_QUERY );
730 : : try
731 : : {
732 : 0 : xListener->modified( aEvent );
733 : : }
734 : 0 : catch(RuntimeException&)
735 : : {
736 : 0 : it.remove();
737 : : }
738 : 0 : }
739 : 0 : }
740 : :
741 : :
742 : : // =============================================================================
743 : : // Loading
744 : :
745 : 0 : bool StringResourceImpl::loadLocale( LocaleItem* pLocaleItem )
746 : : {
747 : : // Base implementation has nothing to load
748 : : (void)pLocaleItem;
749 : 0 : return true;
750 : : }
751 : :
752 : 0 : void StringResourceImpl::implLoadAllLocales( void )
753 : : {
754 : : // Base implementation has nothing to load
755 : 0 : }
756 : :
757 : :
758 : 0 : Reference< XMultiComponentFactory > StringResourceImpl::getMultiComponentFactory( void )
759 : : {
760 : 0 : ::osl::MutexGuard aGuard( getMutex() );
761 : :
762 : 0 : if( !m_xMCF.is() )
763 : : {
764 : 0 : Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager(), UNO_QUERY );
765 : 0 : if( !xSMgr.is() )
766 : : {
767 : : throw RuntimeException(
768 : : ::rtl::OUString( "StringResourceImpl::getMultiComponentFactory: Couldn't instantiate MultiComponentFactory" ),
769 : 0 : Reference< XInterface >() );
770 : : }
771 : 0 : m_xMCF = xSMgr;
772 : : }
773 : 0 : return m_xMCF;
774 : : }
775 : :
776 : :
777 : : // =============================================================================
778 : : // StringResourcePersistenceImpl
779 : : // =============================================================================
780 : :
781 : 0 : StringResourcePersistenceImpl::StringResourcePersistenceImpl( const Reference< XComponentContext >& rxContext )
782 : 0 : : StringResourcePersistenceImpl_BASE( rxContext )
783 : : {
784 : 0 : }
785 : :
786 : : // -----------------------------------------------------------------------------
787 : :
788 : 0 : StringResourcePersistenceImpl::~StringResourcePersistenceImpl()
789 : : {
790 : 0 : }
791 : :
792 : : // -----------------------------------------------------------------------------
793 : : // XServiceInfo
794 : : // -----------------------------------------------------------------------------
795 : :
796 : 0 : ::rtl::OUString StringResourcePersistenceImpl::getImplementationName( )
797 : : throw (RuntimeException)
798 : : {
799 : : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM
800 : 0 : ( "com.sun.star.comp.scripting.StringResourceWithLocation") );
801 : : }
802 : :
803 : : // -----------------------------------------------------------------------------
804 : :
805 : 0 : sal_Bool StringResourcePersistenceImpl::supportsService( const ::rtl::OUString& rServiceName )
806 : : throw (RuntimeException)
807 : : {
808 : 0 : return StringResourceImpl::supportsService( rServiceName );
809 : : }
810 : :
811 : : // -----------------------------------------------------------------------------
812 : :
813 : 0 : Sequence< ::rtl::OUString > StringResourcePersistenceImpl::getSupportedServiceNames( )
814 : : throw (RuntimeException)
815 : : {
816 : 0 : return StringResourceImpl::getSupportedServiceNames();
817 : : }
818 : :
819 : : // -----------------------------------------------------------------------------
820 : : // XInitialization base functionality for derived classes
821 : : // -----------------------------------------------------------------------------
822 : :
823 : 0 : static ::rtl::OUString aNameBaseDefaultStr("strings");
824 : :
825 : 0 : void StringResourcePersistenceImpl::implInitializeCommonParameters
826 : : ( const Sequence< Any >& aArguments )
827 : : throw (Exception, RuntimeException)
828 : : {
829 : 0 : bool bReadOnlyOk = (aArguments[1] >>= m_bReadOnly);
830 : 0 : if( !bReadOnlyOk )
831 : : {
832 : 0 : ::rtl::OUString errorMsg("XInitialization::initialize: Expected ReadOnly flag");
833 : 0 : throw IllegalArgumentException( errorMsg, Reference< XInterface >(), 1 );
834 : : }
835 : :
836 : 0 : com::sun::star::lang::Locale aCurrentLocale;
837 : 0 : bool bLocaleOk = (aArguments[2] >>= aCurrentLocale);
838 : 0 : if( !bLocaleOk )
839 : : {
840 : 0 : ::rtl::OUString errorMsg("XInitialization::initialize: Expected Locale");
841 : 0 : throw IllegalArgumentException( errorMsg, Reference< XInterface >(), 2 );
842 : : }
843 : :
844 : 0 : bool bNameBaseOk = (aArguments[3] >>= m_aNameBase);
845 : 0 : if( !bNameBaseOk )
846 : : {
847 : 0 : ::rtl::OUString errorMsg("XInitialization::initialize: Expected NameBase string");
848 : 0 : throw IllegalArgumentException( errorMsg, Reference< XInterface >(), 3 );
849 : : }
850 : 0 : if( m_aNameBase.isEmpty() )
851 : 0 : m_aNameBase = aNameBaseDefaultStr;
852 : :
853 : 0 : bool bCommentOk = (aArguments[4] >>= m_aComment);
854 : 0 : if( !bCommentOk )
855 : : {
856 : 0 : ::rtl::OUString errorMsg("XInitialization::initialize: Expected Comment string");
857 : 0 : throw IllegalArgumentException( errorMsg, Reference< XInterface >(), 4 );
858 : : }
859 : :
860 : 0 : implScanLocales();
861 : :
862 : 0 : sal_Bool FindClosestMatch = true;
863 : 0 : sal_Bool bUseDefaultIfNoMatch = true;
864 : 0 : implSetCurrentLocale( aCurrentLocale, FindClosestMatch, bUseDefaultIfNoMatch );
865 : 0 : }
866 : :
867 : : // -----------------------------------------------------------------------------
868 : : // Forwarding calls to base class
869 : :
870 : : // XModifyBroadcaster
871 : 0 : void StringResourcePersistenceImpl::addModifyListener( const Reference< XModifyListener >& aListener )
872 : : throw (RuntimeException)
873 : : {
874 : 0 : StringResourceImpl::addModifyListener( aListener );
875 : 0 : }
876 : 0 : void StringResourcePersistenceImpl::removeModifyListener( const Reference< XModifyListener >& aListener )
877 : : throw (RuntimeException)
878 : : {
879 : 0 : StringResourceImpl::removeModifyListener( aListener );
880 : 0 : }
881 : :
882 : : // XStringResourceResolver
883 : 0 : ::rtl::OUString StringResourcePersistenceImpl::resolveString( const ::rtl::OUString& ResourceID )
884 : : throw (::com::sun::star::resource::MissingResourceException, RuntimeException)
885 : : {
886 : 0 : return StringResourceImpl::resolveString( ResourceID ) ;
887 : : }
888 : 0 : ::rtl::OUString StringResourcePersistenceImpl::resolveStringForLocale( const ::rtl::OUString& ResourceID, const Locale& locale )
889 : : throw ( ::com::sun::star::resource::MissingResourceException, RuntimeException)
890 : : {
891 : 0 : return StringResourceImpl::resolveStringForLocale( ResourceID, locale );
892 : : }
893 : 0 : sal_Bool StringResourcePersistenceImpl::hasEntryForId( const ::rtl::OUString& ResourceID )
894 : : throw (RuntimeException)
895 : : {
896 : 0 : return StringResourceImpl::hasEntryForId( ResourceID ) ;
897 : : }
898 : 0 : sal_Bool StringResourcePersistenceImpl::hasEntryForIdAndLocale( const ::rtl::OUString& ResourceID,
899 : : const Locale& locale )
900 : : throw (RuntimeException)
901 : : {
902 : 0 : return StringResourceImpl::hasEntryForIdAndLocale( ResourceID, locale );
903 : : }
904 : 0 : Locale StringResourcePersistenceImpl::getCurrentLocale()
905 : : throw (RuntimeException)
906 : : {
907 : 0 : return StringResourceImpl::getCurrentLocale();
908 : : }
909 : 0 : Locale StringResourcePersistenceImpl::getDefaultLocale( )
910 : : throw (RuntimeException)
911 : : {
912 : 0 : return StringResourceImpl::getDefaultLocale();
913 : : }
914 : 0 : Sequence< Locale > StringResourcePersistenceImpl::getLocales( )
915 : : throw (RuntimeException)
916 : : {
917 : 0 : return StringResourceImpl::getLocales();
918 : : }
919 : :
920 : : // XStringResourceManager
921 : 0 : sal_Bool StringResourcePersistenceImpl::isReadOnly()
922 : : throw (RuntimeException)
923 : : {
924 : 0 : return StringResourceImpl::isReadOnly();
925 : : }
926 : 0 : void StringResourcePersistenceImpl::setCurrentLocale( const Locale& locale, sal_Bool FindClosestMatch )
927 : : throw (IllegalArgumentException, RuntimeException)
928 : : {
929 : 0 : StringResourceImpl::setCurrentLocale( locale, FindClosestMatch );
930 : 0 : }
931 : 0 : void StringResourcePersistenceImpl::setDefaultLocale( const Locale& locale )
932 : : throw (IllegalArgumentException, RuntimeException,NoSupportException)
933 : : {
934 : 0 : StringResourceImpl::setDefaultLocale( locale );
935 : 0 : }
936 : 0 : Sequence< ::rtl::OUString > StringResourcePersistenceImpl::getResourceIDs( )
937 : : throw (RuntimeException)
938 : : {
939 : 0 : return StringResourceImpl::getResourceIDs();
940 : : }
941 : 0 : void StringResourcePersistenceImpl::setString( const ::rtl::OUString& ResourceID, const ::rtl::OUString& Str )
942 : : throw (NoSupportException, RuntimeException)
943 : : {
944 : 0 : StringResourceImpl::setString( ResourceID, Str );
945 : 0 : }
946 : 0 : void StringResourcePersistenceImpl::setStringForLocale
947 : : ( const ::rtl::OUString& ResourceID, const ::rtl::OUString& Str, const Locale& locale )
948 : : throw (NoSupportException, RuntimeException)
949 : : {
950 : 0 : StringResourceImpl::setStringForLocale( ResourceID, Str, locale );
951 : 0 : }
952 : 0 : Sequence< ::rtl::OUString > StringResourcePersistenceImpl::getResourceIDsForLocale
953 : : ( const Locale& locale ) throw (::com::sun::star::uno::RuntimeException)
954 : : {
955 : 0 : return StringResourceImpl::getResourceIDsForLocale( locale );
956 : : }
957 : 0 : void StringResourcePersistenceImpl::removeId( const ::rtl::OUString& ResourceID )
958 : : throw (::com::sun::star::resource::MissingResourceException, RuntimeException, NoSupportException)
959 : : {
960 : 0 : StringResourceImpl::removeId( ResourceID );
961 : 0 : }
962 : 0 : void StringResourcePersistenceImpl::removeIdForLocale( const ::rtl::OUString& ResourceID, const Locale& locale )
963 : : throw (::com::sun::star::resource::MissingResourceException, RuntimeException, NoSupportException)
964 : : {
965 : 0 : StringResourceImpl::removeIdForLocale( ResourceID, locale );
966 : 0 : }
967 : 0 : void StringResourcePersistenceImpl::newLocale( const Locale& locale )
968 : : throw (ElementExistException, IllegalArgumentException, RuntimeException, NoSupportException)
969 : : {
970 : 0 : StringResourceImpl::newLocale( locale );
971 : 0 : }
972 : 0 : void StringResourcePersistenceImpl::removeLocale( const Locale& locale )
973 : : throw (IllegalArgumentException, RuntimeException, NoSupportException)
974 : : {
975 : 0 : StringResourceImpl::removeLocale( locale );
976 : 0 : }
977 : 0 : sal_Int32 StringResourcePersistenceImpl::getUniqueNumericId( )
978 : : throw (RuntimeException, NoSupportException)
979 : : {
980 : 0 : return StringResourceImpl::getUniqueNumericId();
981 : : }
982 : :
983 : : // -----------------------------------------------------------------------------
984 : : // XStringResourcePersistence
985 : :
986 : 0 : void StringResourcePersistenceImpl::store()
987 : : throw (NoSupportException, Exception, RuntimeException)
988 : : {
989 : 0 : }
990 : :
991 : 0 : sal_Bool StringResourcePersistenceImpl::isModified( )
992 : : throw (RuntimeException)
993 : : {
994 : 0 : ::osl::MutexGuard aGuard( getMutex() );
995 : :
996 : 0 : return m_bModified;
997 : : }
998 : :
999 : 0 : void StringResourcePersistenceImpl::setComment( const ::rtl::OUString& Comment )
1000 : : throw (::com::sun::star::uno::RuntimeException)
1001 : : {
1002 : 0 : m_aComment = Comment;
1003 : 0 : }
1004 : :
1005 : 0 : void StringResourcePersistenceImpl::storeToStorage( const Reference< XStorage >& Storage,
1006 : : const ::rtl::OUString& NameBase, const ::rtl::OUString& Comment )
1007 : : throw (Exception, RuntimeException)
1008 : : {
1009 : 0 : ::osl::MutexGuard aGuard( getMutex() );
1010 : :
1011 : 0 : bool bUsedForStore = false;
1012 : 0 : bool bStoreAll = true;
1013 : 0 : implStoreAtStorage( NameBase, Comment, Storage, bUsedForStore, bStoreAll );
1014 : 0 : }
1015 : :
1016 : 0 : void StringResourcePersistenceImpl::implStoreAtStorage
1017 : : (
1018 : : const ::rtl::OUString& aNameBase,
1019 : : const ::rtl::OUString& aComment,
1020 : : const Reference< ::com::sun::star::embed::XStorage >& Storage,
1021 : : bool bUsedForStore,
1022 : : bool bStoreAll
1023 : : )
1024 : : throw (Exception, RuntimeException)
1025 : : {
1026 : : // Delete files for deleted locales
1027 : 0 : if( bUsedForStore )
1028 : : {
1029 : 0 : while( m_aDeletedLocaleItemVector.size() > 0 )
1030 : : {
1031 : 0 : LocaleItemVectorIt it = m_aDeletedLocaleItemVector.begin();
1032 : 0 : LocaleItem* pLocaleItem = *it;
1033 : 0 : if( pLocaleItem != NULL )
1034 : : {
1035 : 0 : ::rtl::OUString aStreamName = implGetFileNameForLocaleItem( pLocaleItem, m_aNameBase );
1036 : 0 : aStreamName += ::rtl::OUString(".properties");
1037 : :
1038 : : try
1039 : : {
1040 : 0 : Storage->removeElement( aStreamName );
1041 : : }
1042 : 0 : catch( Exception& )
1043 : : {}
1044 : :
1045 : 0 : m_aDeletedLocaleItemVector.erase( it );
1046 : 0 : delete pLocaleItem;
1047 : : }
1048 : : }
1049 : : }
1050 : :
1051 : 0 : for( LocaleItemVectorConstIt it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
1052 : : {
1053 : 0 : LocaleItem* pLocaleItem = *it;
1054 : 0 : if( pLocaleItem != NULL && (bStoreAll || pLocaleItem->m_bModified) &&
1055 : 0 : loadLocale( pLocaleItem ) )
1056 : : {
1057 : 0 : ::rtl::OUString aStreamName = implGetFileNameForLocaleItem( pLocaleItem, aNameBase );
1058 : 0 : aStreamName += ::rtl::OUString(".properties");
1059 : :
1060 : : Reference< io::XStream > xElementStream =
1061 : 0 : Storage->openStreamElement( aStreamName, ElementModes::READWRITE );
1062 : :
1063 : 0 : ::rtl::OUString aPropName("MediaType");
1064 : 0 : ::rtl::OUString aMime("text/plain");
1065 : :
1066 : 0 : uno::Reference< beans::XPropertySet > xProps( xElementStream, uno::UNO_QUERY );
1067 : : OSL_ENSURE( xProps.is(), "The StorageStream must implement XPropertySet interface!\n" );
1068 : 0 : if ( xProps.is() )
1069 : : {
1070 : 0 : xProps->setPropertyValue( aPropName, uno::makeAny( aMime ) );
1071 : :
1072 : 0 : aPropName = ::rtl::OUString("UseCommonStoragePasswordEncryption");
1073 : 0 : xProps->setPropertyValue( aPropName, uno::makeAny( sal_True ) );
1074 : : }
1075 : :
1076 : 0 : Reference< io::XOutputStream > xOutputStream = xElementStream->getOutputStream();
1077 : 0 : if( xOutputStream.is() )
1078 : 0 : implWritePropertiesFile( pLocaleItem, xOutputStream, aComment );
1079 : 0 : xOutputStream->closeOutput();
1080 : :
1081 : 0 : if( bUsedForStore )
1082 : 0 : pLocaleItem->m_bModified = false;
1083 : : }
1084 : : }
1085 : :
1086 : : // Delete files for changed defaults
1087 : 0 : if( bUsedForStore )
1088 : : {
1089 : 0 : for( LocaleItemVectorIt it = m_aChangedDefaultLocaleVector.begin();
1090 : 0 : it != m_aChangedDefaultLocaleVector.end(); ++it )
1091 : : {
1092 : 0 : LocaleItem* pLocaleItem = *it;
1093 : 0 : if( pLocaleItem != NULL )
1094 : : {
1095 : 0 : ::rtl::OUString aStreamName = implGetFileNameForLocaleItem( pLocaleItem, m_aNameBase );
1096 : 0 : aStreamName += ::rtl::OUString(".default");
1097 : :
1098 : : try
1099 : : {
1100 : 0 : Storage->removeElement( aStreamName );
1101 : : }
1102 : 0 : catch( Exception& )
1103 : : {}
1104 : :
1105 : 0 : delete pLocaleItem;
1106 : : }
1107 : : }
1108 : 0 : m_aChangedDefaultLocaleVector.clear();
1109 : : }
1110 : :
1111 : : // Default locale
1112 : 0 : if( m_pDefaultLocaleItem != NULL && (bStoreAll || m_bDefaultModified) )
1113 : : {
1114 : 0 : ::rtl::OUString aStreamName = implGetFileNameForLocaleItem( m_pDefaultLocaleItem, aNameBase );
1115 : 0 : aStreamName += ::rtl::OUString(".default");
1116 : :
1117 : : Reference< io::XStream > xElementStream =
1118 : 0 : Storage->openStreamElement( aStreamName, ElementModes::READWRITE );
1119 : :
1120 : 0 : ::rtl::OUString aPropName("MediaType");
1121 : 0 : ::rtl::OUString aMime("text/plain");
1122 : :
1123 : : // Only create stream without content
1124 : 0 : Reference< io::XOutputStream > xOutputStream = xElementStream->getOutputStream();
1125 : 0 : xOutputStream->closeOutput();
1126 : :
1127 : 0 : if( bUsedForStore )
1128 : 0 : m_bDefaultModified = false;
1129 : : }
1130 : 0 : }
1131 : :
1132 : 0 : void StringResourcePersistenceImpl::storeToURL( const ::rtl::OUString& URL,
1133 : : const ::rtl::OUString& NameBase, const ::rtl::OUString& Comment,
1134 : : const Reference< ::com::sun::star::task::XInteractionHandler >& Handler )
1135 : : throw (Exception, RuntimeException)
1136 : : {
1137 : 0 : ::osl::MutexGuard aGuard( getMutex() );
1138 : :
1139 : 0 : bool bUsedForStore = false;
1140 : 0 : bool bStoreAll = true;
1141 : :
1142 : 0 : Reference< ucb::XSimpleFileAccess2 > xFileAccess = ucb::SimpleFileAccess::create(m_xContext);
1143 : 0 : if( xFileAccess.is() && Handler.is() )
1144 : 0 : xFileAccess->setInteractionHandler( Handler );
1145 : :
1146 : 0 : implStoreAtLocation( URL, NameBase, Comment, xFileAccess, bUsedForStore, bStoreAll );
1147 : 0 : }
1148 : :
1149 : 0 : void StringResourcePersistenceImpl::implKillRemovedLocaleFiles
1150 : : (
1151 : : const ::rtl::OUString& Location,
1152 : : const ::rtl::OUString& aNameBase,
1153 : : const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess2 >& xFileAccess
1154 : : )
1155 : : throw (Exception, RuntimeException)
1156 : : {
1157 : : // Delete files for deleted locales
1158 : 0 : while( m_aDeletedLocaleItemVector.size() > 0 )
1159 : : {
1160 : 0 : LocaleItemVectorIt it = m_aDeletedLocaleItemVector.begin();
1161 : 0 : LocaleItem* pLocaleItem = *it;
1162 : 0 : if( pLocaleItem != NULL )
1163 : : {
1164 : : ::rtl::OUString aCompleteFileName =
1165 : 0 : implGetPathForLocaleItem( pLocaleItem, aNameBase, Location );
1166 : 0 : if( xFileAccess->exists( aCompleteFileName ) )
1167 : 0 : xFileAccess->kill( aCompleteFileName );
1168 : :
1169 : 0 : m_aDeletedLocaleItemVector.erase( it );
1170 : 0 : delete pLocaleItem;
1171 : : }
1172 : : }
1173 : 0 : }
1174 : :
1175 : 0 : void StringResourcePersistenceImpl::implKillChangedDefaultFiles
1176 : : (
1177 : : const ::rtl::OUString& Location,
1178 : : const ::rtl::OUString& aNameBase,
1179 : : const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess2 >& xFileAccess
1180 : : )
1181 : : throw (Exception, RuntimeException)
1182 : : {
1183 : : // Delete files for changed defaults
1184 : 0 : for( LocaleItemVectorIt it = m_aChangedDefaultLocaleVector.begin();
1185 : 0 : it != m_aChangedDefaultLocaleVector.end(); ++it )
1186 : : {
1187 : 0 : LocaleItem* pLocaleItem = *it;
1188 : 0 : if( pLocaleItem != NULL )
1189 : : {
1190 : : ::rtl::OUString aCompleteFileName =
1191 : 0 : implGetPathForLocaleItem( pLocaleItem, aNameBase, Location, true );
1192 : 0 : if( xFileAccess->exists( aCompleteFileName ) )
1193 : 0 : xFileAccess->kill( aCompleteFileName );
1194 : :
1195 : 0 : delete pLocaleItem;
1196 : : }
1197 : : }
1198 : 0 : m_aChangedDefaultLocaleVector.clear();
1199 : 0 : }
1200 : :
1201 : 0 : void StringResourcePersistenceImpl::implStoreAtLocation
1202 : : (
1203 : : const ::rtl::OUString& Location,
1204 : : const ::rtl::OUString& aNameBase,
1205 : : const ::rtl::OUString& aComment,
1206 : : const Reference< ucb::XSimpleFileAccess2 >& xFileAccess,
1207 : : bool bUsedForStore,
1208 : : bool bStoreAll,
1209 : : bool bKillAll
1210 : : )
1211 : : throw (Exception, RuntimeException)
1212 : : {
1213 : : // Delete files for deleted locales
1214 : 0 : if( bUsedForStore || bKillAll )
1215 : 0 : implKillRemovedLocaleFiles( Location, aNameBase, xFileAccess );
1216 : :
1217 : 0 : for( LocaleItemVectorConstIt it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
1218 : : {
1219 : 0 : LocaleItem* pLocaleItem = *it;
1220 : 0 : if( pLocaleItem != NULL && (bStoreAll || bKillAll || pLocaleItem->m_bModified) &&
1221 : 0 : loadLocale( pLocaleItem ) )
1222 : : {
1223 : : ::rtl::OUString aCompleteFileName =
1224 : 0 : implGetPathForLocaleItem( pLocaleItem, aNameBase, Location );
1225 : 0 : if( xFileAccess->exists( aCompleteFileName ) )
1226 : 0 : xFileAccess->kill( aCompleteFileName );
1227 : :
1228 : 0 : if( !bKillAll )
1229 : : {
1230 : : // Create Output stream
1231 : 0 : Reference< io::XOutputStream > xOutputStream = xFileAccess->openFileWrite( aCompleteFileName );
1232 : 0 : if( xOutputStream.is() )
1233 : : {
1234 : 0 : implWritePropertiesFile( pLocaleItem, xOutputStream, aComment );
1235 : 0 : xOutputStream->closeOutput();
1236 : : }
1237 : 0 : if( bUsedForStore )
1238 : 0 : pLocaleItem->m_bModified = false;
1239 : 0 : }
1240 : : }
1241 : : }
1242 : :
1243 : : // Delete files for changed defaults
1244 : 0 : if( bUsedForStore || bKillAll )
1245 : 0 : implKillChangedDefaultFiles( Location, aNameBase, xFileAccess );
1246 : :
1247 : : // Default locale
1248 : 0 : if( m_pDefaultLocaleItem != NULL && (bStoreAll || bKillAll || m_bDefaultModified) )
1249 : : {
1250 : : ::rtl::OUString aCompleteFileName =
1251 : 0 : implGetPathForLocaleItem( m_pDefaultLocaleItem, aNameBase, Location, true );
1252 : 0 : if( xFileAccess->exists( aCompleteFileName ) )
1253 : 0 : xFileAccess->kill( aCompleteFileName );
1254 : :
1255 : 0 : if( !bKillAll )
1256 : : {
1257 : : // Create Output stream
1258 : 0 : Reference< io::XOutputStream > xOutputStream = xFileAccess->openFileWrite( aCompleteFileName );
1259 : 0 : if( xOutputStream.is() )
1260 : 0 : xOutputStream->closeOutput();
1261 : :
1262 : 0 : if( bUsedForStore )
1263 : 0 : m_bDefaultModified = false;
1264 : 0 : }
1265 : : }
1266 : 0 : }
1267 : :
1268 : :
1269 : : // -----------------------------------------------------------------------------
1270 : : // BinaryOutput, helper class for exportBinary
1271 : :
1272 : 0 : class BinaryOutput
1273 : : {
1274 : : Reference< XMultiComponentFactory > m_xMCF;
1275 : : Reference< XComponentContext > m_xContext;
1276 : : Reference< XInterface > m_xTempFile;
1277 : : Reference< io::XOutputStream > m_xOutputStream;
1278 : :
1279 : : public:
1280 : : BinaryOutput( Reference< XMultiComponentFactory > xMCF,
1281 : : Reference< XComponentContext > xContext );
1282 : :
1283 : 0 : Reference< io::XOutputStream > getOutputStream() const
1284 : 0 : { return m_xOutputStream; }
1285 : :
1286 : : Sequence< ::sal_Int8 > closeAndGetData();
1287 : :
1288 : : // Template to be used with sal_Int16 and sal_Unicode
1289 : : template< class T >
1290 : : void write16BitInt( T n );
1291 : 0 : void writeInt16( sal_Int16 n )
1292 : 0 : { write16BitInt( n ); }
1293 : 0 : void writeUnicodeChar( sal_Unicode n )
1294 : 0 : { write16BitInt( n ); }
1295 : : void writeInt32( sal_Int32 n );
1296 : : void writeString( const ::rtl::OUString& aStr );
1297 : : };
1298 : :
1299 : 0 : BinaryOutput::BinaryOutput( Reference< XMultiComponentFactory > xMCF,
1300 : : Reference< XComponentContext > xContext )
1301 : : : m_xMCF( xMCF )
1302 : 0 : , m_xContext( xContext )
1303 : : {
1304 : 0 : m_xTempFile = m_xMCF->createInstanceWithContext
1305 : 0 : ( ::rtl::OUString("com.sun.star.io.TempFile"), m_xContext );
1306 : 0 : if( m_xTempFile.is() )
1307 : 0 : m_xOutputStream = Reference< io::XOutputStream >( m_xTempFile, UNO_QUERY );
1308 : 0 : }
1309 : :
1310 : : template< class T >
1311 : 0 : void BinaryOutput::write16BitInt( T n )
1312 : : {
1313 : 0 : if( !m_xOutputStream.is() )
1314 : 0 : return;
1315 : :
1316 : 0 : Sequence< sal_Int8 > aSeq( 2 );
1317 : 0 : sal_Int8* p = aSeq.getArray();
1318 : :
1319 : 0 : sal_Int8 nLow = sal_Int8( n & 0xff );
1320 : 0 : sal_Int8 nHigh = sal_Int8( n >> 8 );
1321 : :
1322 : 0 : p[0] = nLow;
1323 : 0 : p[1] = nHigh;
1324 : 0 : m_xOutputStream->writeBytes( aSeq );
1325 : : }
1326 : :
1327 : 0 : void BinaryOutput::writeInt32( sal_Int32 n )
1328 : : {
1329 : 0 : if( !m_xOutputStream.is() )
1330 : 0 : return;
1331 : :
1332 : 0 : Sequence< sal_Int8 > aSeq( 4 );
1333 : 0 : sal_Int8* p = aSeq.getArray();
1334 : :
1335 : 0 : for( sal_Int16 i = 0 ; i < 4 ; i++ )
1336 : : {
1337 : 0 : p[i] = sal_Int8( n & 0xff );
1338 : 0 : n >>= 8;
1339 : : }
1340 : 0 : m_xOutputStream->writeBytes( aSeq );
1341 : : }
1342 : :
1343 : 0 : void BinaryOutput::writeString( const ::rtl::OUString& aStr )
1344 : : {
1345 : 0 : sal_Int32 nLen = aStr.getLength();
1346 : 0 : const sal_Unicode* pStr = aStr.getStr();
1347 : :
1348 : 0 : for( sal_Int32 i = 0 ; i < nLen ; i++ )
1349 : 0 : writeUnicodeChar( pStr[i] );
1350 : :
1351 : 0 : writeUnicodeChar( 0 );
1352 : 0 : }
1353 : :
1354 : 0 : Sequence< ::sal_Int8 > BinaryOutput::closeAndGetData()
1355 : : {
1356 : 0 : Sequence< ::sal_Int8 > aRetSeq;
1357 : 0 : if( !m_xOutputStream.is() )
1358 : : return aRetSeq;
1359 : :
1360 : 0 : m_xOutputStream->closeOutput();
1361 : :
1362 : 0 : Reference< io::XSeekable> xSeekable( m_xTempFile, UNO_QUERY );
1363 : 0 : if( !xSeekable.is() )
1364 : : return aRetSeq;
1365 : :
1366 : 0 : sal_Int32 nSize = (sal_Int32)xSeekable->getPosition();
1367 : :
1368 : 0 : Reference< io::XInputStream> xInputStream( m_xTempFile, UNO_QUERY );
1369 : 0 : if( !xInputStream.is() )
1370 : : return aRetSeq;
1371 : :
1372 : 0 : xSeekable->seek( 0 );
1373 : 0 : sal_Int32 nRead = xInputStream->readBytes( aRetSeq, nSize );
1374 : : (void)nRead;
1375 : : OSL_ENSURE( nRead == nSize, "BinaryOutput::closeAndGetData: nRead != nSize" );
1376 : :
1377 : 0 : return aRetSeq;
1378 : : }
1379 : :
1380 : :
1381 : : // Binary format:
1382 : :
1383 : : // Header
1384 : : // Byte Content
1385 : : // 0 + 1 sal_Int16: Version, currently 0, low byte first
1386 : : // 2 + 3 sal_Int16: Locale count = n, low byte first
1387 : : // 4 + 5 sal_Int16: Default Locale position in Locale list, == n if none
1388 : : // 6 - 7 sal_Int32: Start index locale block 0, lowest byte first
1389 : : // (n-1) * sal_Int32: Start index locale block 1 to n, lowest byte first
1390 : : // 6 + 4*n sal_Int32: "Start index" non existing locale block n+1,
1391 : : // marks the first invalid index, kind of EOF
1392 : :
1393 : : // Locale block
1394 : : // All strings are stored as 2-Byte-0 terminated sequence
1395 : : // of 16 bit Unicode characters, each with low byte first
1396 : : // Empty strings only contain the 2-Byte-0
1397 : :
1398 : : // Members of com.sun.star.lang.Locale
1399 : : // with l1 = Locale.Language.getLength()
1400 : : // with l2 = Locale.Country.getLength()
1401 : : // with l3 = Locale.Variant.getLength()
1402 : : // pos0 = 0 Locale.Language
1403 : : // pos1 = 2 * (l1 + 1) Locale.Country
1404 : : // pos2 = pos1 + 2 * (l2 + 1) Locale.Variant
1405 : : // pos3 = pos2 + 2 * (l3 + 1)
1406 : : // pos3 Properties file written by implWritePropertiesFile
1407 : :
1408 : 0 : Sequence< sal_Int8 > StringResourcePersistenceImpl::exportBinary( )
1409 : : throw (RuntimeException)
1410 : : {
1411 : 0 : Reference< XMultiComponentFactory > xMCF = getMultiComponentFactory();
1412 : 0 : BinaryOutput aOut( xMCF, m_xContext );
1413 : :
1414 : 0 : sal_Int32 nLocaleCount = m_aLocaleItemVector.size();
1415 : 0 : Sequence< sal_Int8 >* pLocaleDataSeq = new Sequence< sal_Int8 >[ nLocaleCount ];
1416 : :
1417 : 0 : sal_Int32 iLocale = 0;
1418 : 0 : sal_Int32 iDefault = 0;
1419 : 0 : for( LocaleItemVectorConstIt it = m_aLocaleItemVector.begin();
1420 : 0 : it != m_aLocaleItemVector.end(); ++it,++iLocale )
1421 : : {
1422 : 0 : LocaleItem* pLocaleItem = *it;
1423 : 0 : if( pLocaleItem != NULL && loadLocale( pLocaleItem ) )
1424 : : {
1425 : 0 : if( m_pDefaultLocaleItem == pLocaleItem )
1426 : 0 : iDefault = iLocale;
1427 : :
1428 : 0 : BinaryOutput aLocaleOut( m_xMCF, m_xContext );
1429 : 0 : implWriteLocaleBinary( pLocaleItem, aLocaleOut );
1430 : :
1431 : 0 : pLocaleDataSeq[iLocale] = aLocaleOut.closeAndGetData();
1432 : : }
1433 : : }
1434 : :
1435 : : // Write header
1436 : 0 : sal_Int16 nVersion = 0;
1437 : 0 : sal_Int16 nLocaleCount16 = (sal_Int16)nLocaleCount;
1438 : 0 : sal_Int16 iDefault16 = (sal_Int16)iDefault;
1439 : 0 : aOut.writeInt16( nVersion );
1440 : 0 : aOut.writeInt16( nLocaleCount16 );
1441 : 0 : aOut.writeInt16( iDefault16 );
1442 : :
1443 : : // Write data positions
1444 : 0 : sal_Int32 nDataPos = 6 + 4 * (nLocaleCount + 1);
1445 : 0 : for( iLocale = 0; iLocale < nLocaleCount; iLocale++ )
1446 : : {
1447 : 0 : aOut.writeInt32( nDataPos );
1448 : :
1449 : 0 : Sequence< sal_Int8 >& rSeq = pLocaleDataSeq[iLocale];
1450 : 0 : sal_Int32 nSeqLen = rSeq.getLength();
1451 : 0 : nDataPos += nSeqLen;
1452 : : }
1453 : : // Write final position
1454 : 0 : aOut.writeInt32( nDataPos );
1455 : :
1456 : : // Write data
1457 : 0 : Reference< io::XOutputStream > xOutputStream = aOut.getOutputStream();
1458 : 0 : if( xOutputStream.is() )
1459 : : {
1460 : 0 : for( iLocale = 0; iLocale < nLocaleCount; iLocale++ )
1461 : : {
1462 : 0 : Sequence< sal_Int8 >& rSeq = pLocaleDataSeq[iLocale];
1463 : 0 : xOutputStream->writeBytes( rSeq );
1464 : : }
1465 : : }
1466 : :
1467 : 0 : delete[] pLocaleDataSeq;
1468 : :
1469 : 0 : Sequence< sal_Int8 > aRetSeq = aOut.closeAndGetData();
1470 : 0 : return aRetSeq;
1471 : : }
1472 : :
1473 : 0 : void StringResourcePersistenceImpl::implWriteLocaleBinary
1474 : : ( LocaleItem* pLocaleItem, BinaryOutput& rOut )
1475 : : {
1476 : 0 : Reference< io::XOutputStream > xOutputStream = rOut.getOutputStream();
1477 : 0 : if( !xOutputStream.is() )
1478 : 0 : return;
1479 : :
1480 : 0 : Locale& rLocale = pLocaleItem->m_locale;
1481 : 0 : rOut.writeString( rLocale.Language );
1482 : 0 : rOut.writeString( rLocale.Country );
1483 : 0 : rOut.writeString( rLocale.Variant );
1484 : 0 : implWritePropertiesFile( pLocaleItem, xOutputStream, m_aComment );
1485 : : }
1486 : :
1487 : : // -----------------------------------------------------------------------------
1488 : : // BinaryOutput, helper class for exportBinary
1489 : :
1490 : 0 : class BinaryInput
1491 : : {
1492 : : Sequence< sal_Int8 > m_aData;
1493 : : Reference< XMultiComponentFactory > m_xMCF;
1494 : : Reference< XComponentContext > m_xContext;
1495 : :
1496 : : const sal_Int8* m_pData;
1497 : : sal_Int32 m_nCurPos;
1498 : : sal_Int32 m_nSize;
1499 : :
1500 : : public:
1501 : : BinaryInput( Sequence< ::sal_Int8 > aData, Reference< XMultiComponentFactory > xMCF,
1502 : : Reference< XComponentContext > xContext );
1503 : :
1504 : : Reference< io::XInputStream > getInputStreamForSection( sal_Int32 nSize );
1505 : :
1506 : : void seek( sal_Int32 nPos );
1507 : 0 : sal_Int32 getPosition( void ) const
1508 : 0 : { return m_nCurPos; }
1509 : :
1510 : : sal_Int16 readInt16( void );
1511 : : sal_Int32 readInt32( void );
1512 : : sal_Unicode readUnicodeChar( void );
1513 : : ::rtl::OUString readString( void );
1514 : : };
1515 : :
1516 : 0 : BinaryInput::BinaryInput( Sequence< ::sal_Int8 > aData, Reference< XMultiComponentFactory > xMCF,
1517 : : Reference< XComponentContext > xContext )
1518 : : : m_aData( aData )
1519 : : , m_xMCF( xMCF )
1520 : 0 : , m_xContext( xContext )
1521 : : {
1522 : 0 : m_pData = m_aData.getConstArray();
1523 : 0 : m_nCurPos = 0;
1524 : 0 : m_nSize = m_aData.getLength();
1525 : 0 : }
1526 : :
1527 : 0 : Reference< io::XInputStream > BinaryInput::getInputStreamForSection( sal_Int32 nSize )
1528 : : {
1529 : 0 : Reference< io::XInputStream > xIn;
1530 : 0 : if( m_nCurPos + nSize <= m_nSize )
1531 : : {
1532 : 0 : Reference< io::XOutputStream > xTempOut( m_xMCF->createInstanceWithContext
1533 : 0 : ( ::rtl::OUString("com.sun.star.io.TempFile"), m_xContext ), UNO_QUERY );
1534 : 0 : if( xTempOut.is() )
1535 : : {
1536 : 0 : Sequence< sal_Int8 > aSection( m_pData + m_nCurPos, nSize );
1537 : 0 : xTempOut->writeBytes( aSection );
1538 : :
1539 : 0 : Reference< io::XSeekable> xSeekable( xTempOut, UNO_QUERY );
1540 : 0 : if( xSeekable.is() )
1541 : 0 : xSeekable->seek( 0 );
1542 : :
1543 : 0 : xIn = Reference< io::XInputStream>( xTempOut, UNO_QUERY );
1544 : 0 : }
1545 : : }
1546 : : else
1547 : : OSL_FAIL( "BinaryInput::getInputStreamForSection(): Read past end" );
1548 : :
1549 : 0 : return xIn;
1550 : : }
1551 : :
1552 : 0 : void BinaryInput::seek( sal_Int32 nPos )
1553 : : {
1554 : 0 : if( nPos <= m_nSize )
1555 : 0 : m_nCurPos = nPos;
1556 : : else
1557 : : OSL_FAIL( "BinaryInput::seek(): Position past end" );
1558 : 0 : }
1559 : :
1560 : :
1561 : 0 : sal_Int16 BinaryInput::readInt16( void )
1562 : : {
1563 : 0 : sal_Int16 nRet = 0;
1564 : 0 : if( m_nCurPos + 2 <= m_nSize )
1565 : : {
1566 : 0 : nRet = nRet + sal_Int16( sal_uInt8( m_pData[m_nCurPos++] ) );
1567 : 0 : nRet += 256 * sal_Int16( sal_uInt8( m_pData[m_nCurPos++] ) );
1568 : : }
1569 : : else
1570 : : OSL_FAIL( "BinaryInput::readInt16(): Read past end" );
1571 : :
1572 : 0 : return nRet;
1573 : : }
1574 : :
1575 : 0 : sal_Int32 BinaryInput::readInt32( void )
1576 : : {
1577 : 0 : sal_Int32 nRet = 0;
1578 : 0 : if( m_nCurPos + 4 <= m_nSize )
1579 : : {
1580 : 0 : sal_Int32 nFactor = 1;
1581 : 0 : for( sal_Int16 i = 0; i < 4; i++ )
1582 : : {
1583 : 0 : nRet += sal_uInt8( m_pData[m_nCurPos++] ) * nFactor;
1584 : 0 : nFactor *= 256;
1585 : : }
1586 : : }
1587 : : else
1588 : : OSL_FAIL( "BinaryInput::readInt32(): Read past end" );
1589 : :
1590 : 0 : return nRet;
1591 : : }
1592 : :
1593 : 0 : sal_Unicode BinaryInput::readUnicodeChar( void )
1594 : : {
1595 : 0 : sal_uInt16 nRet = 0;
1596 : 0 : if( m_nCurPos + 2 <= m_nSize )
1597 : : {
1598 : 0 : nRet = nRet + sal_uInt8( m_pData[m_nCurPos++] );
1599 : 0 : nRet += 256 * sal_uInt8( m_pData[m_nCurPos++] );
1600 : : }
1601 : : else
1602 : : OSL_FAIL( "BinaryInput::readUnicodeChar(): Read past end" );
1603 : :
1604 : 0 : sal_Unicode cRet = nRet;
1605 : 0 : return cRet;
1606 : : }
1607 : :
1608 : 0 : ::rtl::OUString BinaryInput::readString( void )
1609 : : {
1610 : 0 : ::rtl::OUStringBuffer aBuf;
1611 : : sal_Unicode c;
1612 : 0 : do
1613 : : {
1614 : 0 : c = readUnicodeChar();
1615 : 0 : if( c != 0 )
1616 : 0 : aBuf.append( c );
1617 : : }
1618 : : while( c != 0 );
1619 : :
1620 : 0 : ::rtl::OUString aRetStr = aBuf.makeStringAndClear();
1621 : 0 : return aRetStr;
1622 : : }
1623 : :
1624 : 0 : void StringResourcePersistenceImpl::importBinary( const Sequence< ::sal_Int8 >& Data )
1625 : : throw (IllegalArgumentException, RuntimeException)
1626 : : {
1627 : : // Init: Remove all locales
1628 : 0 : sal_Int32 nOldLocaleCount = 0;
1629 : 0 : do
1630 : : {
1631 : 0 : Sequence< Locale > aLocaleSeq = getLocales();
1632 : 0 : nOldLocaleCount = aLocaleSeq.getLength();
1633 : 0 : if( nOldLocaleCount > 0 )
1634 : : {
1635 : 0 : Locale aLocale = aLocaleSeq[0];
1636 : 0 : removeLocale( aLocale );
1637 : 0 : }
1638 : : }
1639 : : while( nOldLocaleCount > 0 );
1640 : :
1641 : : // Import data
1642 : 0 : Reference< XMultiComponentFactory > xMCF = getMultiComponentFactory();
1643 : 0 : BinaryInput aIn( Data, xMCF, m_xContext );
1644 : :
1645 : 0 : sal_Int32 nVersion = aIn.readInt16();
1646 : : (void)nVersion;
1647 : 0 : sal_Int32 nLocaleCount = aIn.readInt16();
1648 : 0 : sal_Int32 iDefault = aIn.readInt16();
1649 : : (void)iDefault;
1650 : :
1651 : 0 : sal_Int32* pPositions = new sal_Int32[nLocaleCount + 1];
1652 : 0 : for( sal_Int32 i = 0; i < nLocaleCount + 1; i++ )
1653 : 0 : pPositions[i] = aIn.readInt32();
1654 : :
1655 : : // Import locales
1656 : 0 : LocaleItem* pUseAsDefaultItem = NULL;
1657 : 0 : for( sal_Int32 i = 0; i < nLocaleCount; i++ )
1658 : : {
1659 : 0 : sal_Int32 nPos = pPositions[i];
1660 : 0 : aIn.seek( nPos );
1661 : :
1662 : 0 : Locale aLocale;
1663 : 0 : aLocale.Language = aIn.readString();
1664 : 0 : aLocale.Country = aIn.readString();
1665 : 0 : aLocale.Variant = aIn.readString();
1666 : :
1667 : 0 : sal_Int32 nAfterStringPos = aIn.getPosition();
1668 : 0 : sal_Int32 nSize = pPositions[i+1] - nAfterStringPos;
1669 : 0 : Reference< io::XInputStream > xInput = aIn.getInputStreamForSection( nSize );
1670 : 0 : if( xInput.is() )
1671 : : {
1672 : 0 : LocaleItem* pLocaleItem = new LocaleItem( aLocale );
1673 : 0 : if( iDefault == i )
1674 : 0 : pUseAsDefaultItem = pLocaleItem;
1675 : 0 : m_aLocaleItemVector.push_back( pLocaleItem );
1676 : 0 : implReadPropertiesFile( pLocaleItem, xInput );
1677 : : }
1678 : 0 : }
1679 : :
1680 : 0 : if( pUseAsDefaultItem != NULL )
1681 : 0 : setDefaultLocale( pUseAsDefaultItem->m_locale );
1682 : :
1683 : 0 : delete[] pPositions;
1684 : 0 : }
1685 : :
1686 : :
1687 : : // =============================================================================
1688 : : // Private helper methods
1689 : :
1690 : 0 : bool checkNamingSceme( const ::rtl::OUString& aName, const ::rtl::OUString& aNameBase,
1691 : : Locale& aLocale )
1692 : : {
1693 : 0 : bool bSuccess = false;
1694 : :
1695 : 0 : sal_Int32 nNameLen = aName.getLength();
1696 : 0 : sal_Int32 nNameBaseLen = aNameBase.getLength();
1697 : :
1698 : : // Name has to start with NameBase followed
1699 : : // by a '_' and at least one more character
1700 : 0 : if( aName.indexOf( aNameBase ) == 0 && nNameBaseLen < nNameLen-1 &&
1701 : 0 : aName.getStr()[nNameBaseLen] == '_' )
1702 : : {
1703 : 0 : bSuccess = true;
1704 : :
1705 : 0 : sal_Int32 iStart = nNameBaseLen + 1;
1706 : 0 : sal_Int32 iNext_ = aName.indexOf( '_', iStart );
1707 : 0 : if( iNext_ != -1 && iNext_ < nNameLen-1 )
1708 : : {
1709 : 0 : aLocale.Language = aName.copy( iStart, iNext_ - iStart );
1710 : :
1711 : 0 : iStart = iNext_ + 1;
1712 : 0 : iNext_ = aName.indexOf( '_', iStart );
1713 : 0 : if( iNext_ != -1 && iNext_ < nNameLen-1 )
1714 : : {
1715 : 0 : aLocale.Country = aName.copy( iStart, iNext_ - iStart );
1716 : 0 : aLocale.Variant = aName.copy( iNext_ + 1 );
1717 : : }
1718 : : else
1719 : 0 : aLocale.Country = aName.copy( iStart );
1720 : : }
1721 : : else
1722 : 0 : aLocale.Language = aName.copy( iStart );
1723 : : }
1724 : 0 : return bSuccess;
1725 : : }
1726 : :
1727 : 0 : void StringResourcePersistenceImpl::implLoadAllLocales( void )
1728 : : {
1729 : 0 : for( LocaleItemVectorIt it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it )
1730 : : {
1731 : 0 : LocaleItem* pLocaleItem = *it;
1732 : 0 : if( pLocaleItem != NULL )
1733 : 0 : loadLocale( pLocaleItem );
1734 : : }
1735 : 0 : }
1736 : :
1737 : : // Scan locale properties files helper
1738 : 0 : void StringResourcePersistenceImpl::implScanLocaleNames( const Sequence< ::rtl::OUString >& aContentSeq )
1739 : : {
1740 : 0 : Locale aDefaultLocale;
1741 : 0 : bool bDefaultFound = false;
1742 : :
1743 : 0 : sal_Int32 nCount = aContentSeq.getLength();
1744 : 0 : const ::rtl::OUString* pFiles = aContentSeq.getConstArray();
1745 : 0 : for( int i = 0 ; i < nCount ; i++ )
1746 : : {
1747 : 0 : ::rtl::OUString aCompleteName = pFiles[i];
1748 : 0 : rtl::OUString aPureName;
1749 : 0 : rtl::OUString aExtension;
1750 : 0 : sal_Int32 iDot = aCompleteName.lastIndexOf( '.' );
1751 : 0 : sal_Int32 iSlash = aCompleteName.lastIndexOf( '/' );
1752 : 0 : if( iDot != -1 )
1753 : : {
1754 : 0 : sal_Int32 iCopyFrom = (iSlash != -1) ? iSlash + 1 : 0;
1755 : 0 : aPureName = aCompleteName.copy( iCopyFrom, iDot-iCopyFrom );
1756 : 0 : aExtension = aCompleteName.copy( iDot + 1 );
1757 : : }
1758 : :
1759 : 0 : if ( aExtension == "properties" )
1760 : : {
1761 : : //rtl::OUString aName = aInetObj.getBase();
1762 : 0 : Locale aLocale;
1763 : :
1764 : 0 : if( checkNamingSceme( aPureName, m_aNameBase, aLocale ) )
1765 : : {
1766 : 0 : LocaleItem* pLocaleItem = new LocaleItem( aLocale, false );
1767 : 0 : m_aLocaleItemVector.push_back( pLocaleItem );
1768 : :
1769 : 0 : if( m_pCurrentLocaleItem == NULL )
1770 : 0 : m_pCurrentLocaleItem = pLocaleItem;
1771 : :
1772 : 0 : if( m_pDefaultLocaleItem == NULL )
1773 : : {
1774 : 0 : m_pDefaultLocaleItem = pLocaleItem;
1775 : 0 : m_bDefaultModified = true;
1776 : : }
1777 : 0 : }
1778 : : }
1779 : 0 : else if( !bDefaultFound && aExtension == "default" )
1780 : : {
1781 : : //rtl::OUString aName = aInetObj.getBase();
1782 : 0 : Locale aLocale;
1783 : :
1784 : 0 : if( checkNamingSceme( aPureName, m_aNameBase, aDefaultLocale ) )
1785 : 0 : bDefaultFound = true;
1786 : : }
1787 : 0 : }
1788 : 0 : if( bDefaultFound )
1789 : : {
1790 : 0 : LocaleItem* pLocaleItem = getItemForLocale( aDefaultLocale, false );
1791 : 0 : if( pLocaleItem )
1792 : : {
1793 : 0 : m_pDefaultLocaleItem = pLocaleItem;
1794 : 0 : m_bDefaultModified = false;
1795 : : }
1796 : 0 : }
1797 : 0 : }
1798 : :
1799 : : // Scan locale properties files
1800 : 0 : void StringResourcePersistenceImpl::implScanLocales( void )
1801 : : {
1802 : : // Dummy implementation, method not called for this
1803 : : // base class, but pure virtual not possible-
1804 : 0 : }
1805 : :
1806 : 0 : bool StringResourcePersistenceImpl::loadLocale( LocaleItem* pLocaleItem )
1807 : : {
1808 : 0 : bool bSuccess = false;
1809 : :
1810 : : OSL_ENSURE( pLocaleItem, "StringResourcePersistenceImpl::loadLocale(): pLocaleItem == NULL" );
1811 : 0 : if( pLocaleItem )
1812 : : {
1813 : 0 : if( pLocaleItem->m_bLoaded )
1814 : : {
1815 : 0 : bSuccess = true;
1816 : : }
1817 : : else
1818 : : {
1819 : 0 : bSuccess = implLoadLocale( pLocaleItem );
1820 : 0 : pLocaleItem->m_bLoaded = true; // = bSuccess??? -> leads to more tries
1821 : : }
1822 : : }
1823 : 0 : return bSuccess;
1824 : : }
1825 : :
1826 : 0 : bool StringResourcePersistenceImpl::implLoadLocale( LocaleItem* )
1827 : : {
1828 : : // Dummy implementation, method not called for this
1829 : : // base class, but pure virtual not possible-
1830 : 0 : return false;
1831 : : }
1832 : :
1833 : 0 : ::rtl::OUString implGetNameScemeForLocaleItem( const LocaleItem* pLocaleItem )
1834 : : {
1835 : 0 : static ::rtl::OUString aUnder("_");
1836 : :
1837 : : OSL_ENSURE( pLocaleItem,
1838 : : "StringResourcePersistenceImpl::implGetNameScemeForLocaleItem(): pLocaleItem == NULL" );
1839 : 0 : Locale aLocale = pLocaleItem->m_locale;
1840 : :
1841 : 0 : ::rtl::OUString aRetStr = aUnder;
1842 : 0 : aRetStr += aLocale.Language;
1843 : :
1844 : 0 : ::rtl::OUString aCountry = aLocale.Country;
1845 : 0 : if( !aCountry.isEmpty() )
1846 : : {
1847 : 0 : aRetStr += aUnder;
1848 : 0 : aRetStr += aCountry;
1849 : : }
1850 : :
1851 : 0 : ::rtl::OUString aVariant = aLocale.Variant;
1852 : 0 : if( !aVariant.isEmpty() )
1853 : : {
1854 : 0 : aRetStr += aUnder;
1855 : 0 : aRetStr += aVariant;
1856 : : }
1857 : 0 : return aRetStr;
1858 : : }
1859 : :
1860 : 0 : ::rtl::OUString StringResourcePersistenceImpl::implGetFileNameForLocaleItem
1861 : : ( LocaleItem* pLocaleItem, const ::rtl::OUString& aNameBase )
1862 : : {
1863 : 0 : ::rtl::OUString aFileName = aNameBase;
1864 : 0 : if( aFileName.isEmpty() )
1865 : 0 : aFileName = aNameBaseDefaultStr;
1866 : :
1867 : 0 : aFileName += implGetNameScemeForLocaleItem( pLocaleItem );
1868 : 0 : return aFileName;
1869 : : }
1870 : :
1871 : 0 : ::rtl::OUString StringResourcePersistenceImpl::implGetPathForLocaleItem
1872 : : ( LocaleItem* pLocaleItem, const ::rtl::OUString& aNameBase,
1873 : : const ::rtl::OUString& aLocation, bool bDefaultFile )
1874 : : {
1875 : 0 : ::rtl::OUString aFileName = implGetFileNameForLocaleItem( pLocaleItem, aNameBase );
1876 : 0 : INetURLObject aInetObj( aLocation );
1877 : 0 : aInetObj.insertName( aFileName, sal_True, INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
1878 : 0 : if( bDefaultFile )
1879 : 0 : aInetObj.setExtension( ::rtl::OUString( "default" ) );
1880 : : else
1881 : 0 : aInetObj.setExtension( ::rtl::OUString( "properties" ) );
1882 : 0 : ::rtl::OUString aCompleteFileName = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
1883 : 0 : return aCompleteFileName;
1884 : : }
1885 : :
1886 : : // White space according to Java property files specification in
1887 : : // http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html#load(java.io.InputStream)
1888 : 0 : inline bool isWhiteSpace( sal_Unicode c )
1889 : : {
1890 : : bool bWhite = ( c == 0x0020 || // space
1891 : : c == 0x0009 || // tab
1892 : : c == 0x000a || // line feed, not always handled by TextInputStream
1893 : : c == 0x000d || // carriage return, not always handled by TextInputStream
1894 : 0 : c == 0x000C ); // form feed
1895 : 0 : return bWhite;
1896 : : }
1897 : :
1898 : 0 : inline void skipWhites( const sal_Unicode* pBuf, sal_Int32 nLen, sal_Int32& ri )
1899 : : {
1900 : 0 : while( ri < nLen )
1901 : : {
1902 : 0 : if( !isWhiteSpace( pBuf[ri] ) )
1903 : 0 : break;
1904 : 0 : ri++;
1905 : : }
1906 : 0 : }
1907 : :
1908 : 0 : inline bool isHexDigit( sal_Unicode c, sal_uInt16& nDigitVal )
1909 : : {
1910 : 0 : bool bRet = true;
1911 : 0 : if( c >= '0' && c <= '9' )
1912 : 0 : nDigitVal = c - '0';
1913 : 0 : else if( c >= 'a' && c <= 'f' )
1914 : 0 : nDigitVal = c - 'a' + 10;
1915 : 0 : else if( c >= 'A' && c <= 'F' )
1916 : 0 : nDigitVal = c - 'A' + 10;
1917 : : else
1918 : 0 : bRet = false;
1919 : 0 : return bRet;
1920 : : }
1921 : :
1922 : 0 : sal_Unicode getEscapeChar( const sal_Unicode* pBuf, sal_Int32 nLen, sal_Int32& ri )
1923 : : {
1924 : 0 : sal_Int32 i = ri;
1925 : :
1926 : 0 : sal_Unicode cRet = 0;
1927 : 0 : sal_Unicode c = pBuf[i];
1928 : 0 : switch( c )
1929 : : {
1930 : : case 't':
1931 : 0 : cRet = 0x0009;
1932 : 0 : break;
1933 : : case 'n':
1934 : 0 : cRet = 0x000a;
1935 : 0 : break;
1936 : : case 'f':
1937 : 0 : cRet = 0x000c;
1938 : 0 : break;
1939 : : case 'r':
1940 : 0 : cRet = 0x000d;
1941 : 0 : break;
1942 : : case '\\':
1943 : 0 : cRet = '\\';
1944 : 0 : break;
1945 : : case 'u':
1946 : : {
1947 : : // Skip multiple u
1948 : 0 : i++;
1949 : 0 : while( i < nLen && pBuf[i] == 'u' )
1950 : 0 : i++;
1951 : :
1952 : : // Process hex digits
1953 : 0 : sal_Int32 nDigitCount = 0;
1954 : : sal_uInt16 nDigitVal;
1955 : 0 : while( i < nLen && isHexDigit( pBuf[i], nDigitVal ) )
1956 : : {
1957 : 0 : cRet = 16 * cRet + nDigitVal;
1958 : :
1959 : 0 : nDigitCount++;
1960 : 0 : if( nDigitCount == 4 )
1961 : : {
1962 : : // Write back position
1963 : 0 : ri = i;
1964 : 0 : break;
1965 : : }
1966 : 0 : i++;
1967 : : }
1968 : : break;
1969 : : }
1970 : : default:
1971 : 0 : cRet = c;
1972 : : }
1973 : :
1974 : 0 : return cRet;
1975 : : }
1976 : :
1977 : 0 : void CheckContinueInNextLine( Reference< io::XTextInputStream > xTextInputStream,
1978 : : ::rtl::OUString& aLine, bool& bEscapePending, const sal_Unicode*& pBuf,
1979 : : sal_Int32& nLen, sal_Int32& i )
1980 : : {
1981 : 0 : if( i == nLen && bEscapePending )
1982 : : {
1983 : 0 : bEscapePending = false;
1984 : :
1985 : 0 : if( !xTextInputStream->isEOF() )
1986 : : {
1987 : 0 : aLine = xTextInputStream->readLine();
1988 : 0 : nLen = aLine.getLength();
1989 : 0 : pBuf = aLine.getStr();
1990 : 0 : i = 0;
1991 : :
1992 : 0 : skipWhites( pBuf, nLen, i );
1993 : : }
1994 : : }
1995 : 0 : }
1996 : :
1997 : 0 : bool StringResourcePersistenceImpl::implReadPropertiesFile
1998 : : ( LocaleItem* pLocaleItem, const Reference< io::XInputStream >& xInputStream )
1999 : : {
2000 : 0 : if( !xInputStream.is() || pLocaleItem == NULL )
2001 : 0 : return false;
2002 : :
2003 : 0 : bool bSuccess = false;
2004 : 0 : Reference< XMultiComponentFactory > xMCF = getMultiComponentFactory();
2005 : 0 : Reference< io::XTextInputStream > xTextInputStream( xMCF->createInstanceWithContext
2006 : 0 : ( ::rtl::OUString("com.sun.star.io.TextInputStream"), m_xContext ), UNO_QUERY );
2007 : :
2008 : 0 : if( xTextInputStream.is() )
2009 : : {
2010 : 0 : Reference< io::XActiveDataSink> xActiveDataSink( xTextInputStream, UNO_QUERY );
2011 : 0 : if( xActiveDataSink.is() )
2012 : : {
2013 : 0 : bSuccess = true;
2014 : :
2015 : 0 : xActiveDataSink->setInputStream( xInputStream );
2016 : :
2017 : : ::rtl::OUString aEncodingStr = ::rtl::OUString::createFromAscii
2018 : 0 : ( rtl_getMimeCharsetFromTextEncoding( RTL_TEXTENCODING_ISO_8859_1 ) );
2019 : 0 : xTextInputStream->setEncoding( aEncodingStr );
2020 : :
2021 : 0 : ::rtl::OUString aLine;
2022 : 0 : while( !xTextInputStream->isEOF() )
2023 : : {
2024 : 0 : aLine = xTextInputStream->readLine();
2025 : :
2026 : 0 : sal_Int32 nLen = aLine.getLength();
2027 : 0 : if( 0 == nLen )
2028 : 0 : continue;
2029 : 0 : const sal_Unicode* pBuf = aLine.getStr();
2030 : 0 : ::rtl::OUStringBuffer aBuf;
2031 : 0 : sal_Unicode c = 0;
2032 : 0 : sal_Int32 i = 0;
2033 : :
2034 : 0 : skipWhites( pBuf, nLen, i );
2035 : 0 : if( i == nLen )
2036 : 0 : continue; // line contains only white spaces
2037 : :
2038 : : // Comment?
2039 : 0 : c = pBuf[i];
2040 : 0 : if( c == '#' || c == '!' )
2041 : 0 : continue;
2042 : :
2043 : : // Scan key
2044 : 0 : ::rtl::OUString aResourceID;
2045 : 0 : bool bEscapePending = false;
2046 : 0 : bool bStrComplete = false;
2047 : 0 : while( i < nLen && !bStrComplete )
2048 : : {
2049 : 0 : c = pBuf[i];
2050 : 0 : if( bEscapePending )
2051 : : {
2052 : 0 : aBuf.append( getEscapeChar( pBuf, nLen, i ) );
2053 : 0 : bEscapePending = false;
2054 : : }
2055 : : else
2056 : : {
2057 : 0 : if( c == '\\' )
2058 : : {
2059 : 0 : bEscapePending = true;
2060 : : }
2061 : : else
2062 : : {
2063 : 0 : if( c == ':' || c == '=' || isWhiteSpace( c ) )
2064 : 0 : bStrComplete = true;
2065 : : else
2066 : 0 : aBuf.append( c );
2067 : : }
2068 : : }
2069 : 0 : i++;
2070 : :
2071 : 0 : CheckContinueInNextLine( xTextInputStream, aLine, bEscapePending, pBuf, nLen, i );
2072 : 0 : if( i == nLen )
2073 : 0 : bStrComplete = true;
2074 : :
2075 : 0 : if( bStrComplete )
2076 : 0 : aResourceID = aBuf.makeStringAndClear();
2077 : : }
2078 : :
2079 : : // Ignore lines with empty keys
2080 : 0 : if( aResourceID.isEmpty() )
2081 : 0 : continue;
2082 : :
2083 : : // Scan value
2084 : 0 : skipWhites( pBuf, nLen, i );
2085 : :
2086 : 0 : ::rtl::OUString aValueStr;
2087 : 0 : bEscapePending = false;
2088 : 0 : bStrComplete = false;
2089 : 0 : while( i < nLen && !bStrComplete )
2090 : : {
2091 : 0 : c = pBuf[i];
2092 : 0 : if( c == 0x000a || c == 0x000d ) // line feed/carriage return, not always handled by TextInputStream
2093 : : {
2094 : 0 : i++;
2095 : : }
2096 : : else
2097 : : {
2098 : 0 : if( bEscapePending )
2099 : : {
2100 : 0 : aBuf.append( getEscapeChar( pBuf, nLen, i ) );
2101 : 0 : bEscapePending = false;
2102 : : }
2103 : 0 : else if( c == '\\' )
2104 : 0 : bEscapePending = true;
2105 : : else
2106 : 0 : aBuf.append( c );
2107 : 0 : i++;
2108 : :
2109 : 0 : CheckContinueInNextLine( xTextInputStream, aLine, bEscapePending, pBuf, nLen, i );
2110 : : }
2111 : 0 : if( i == nLen )
2112 : 0 : bStrComplete = true;
2113 : :
2114 : 0 : if( bStrComplete )
2115 : 0 : aValueStr = aBuf.makeStringAndClear();
2116 : : }
2117 : :
2118 : : // Push into table
2119 : 0 : pLocaleItem->m_aIdToStringMap[ aResourceID ] = aValueStr;
2120 : 0 : implScanIdForNumber( aResourceID );
2121 : 0 : IdToIndexMap& rIndexMap = pLocaleItem->m_aIdToIndexMap;
2122 : 0 : rIndexMap[ aResourceID ] = pLocaleItem->m_nNextIndex++;
2123 : 0 : }
2124 : 0 : }
2125 : : }
2126 : :
2127 : 0 : return bSuccess;
2128 : : }
2129 : :
2130 : :
2131 : 0 : inline sal_Unicode getHexCharForDigit( sal_uInt16 nDigitVal )
2132 : : {
2133 : 0 : sal_Unicode cRet = ( nDigitVal < 10 ) ? ('0' + nDigitVal) : ('a' + (nDigitVal-10));
2134 : 0 : return cRet;
2135 : : }
2136 : :
2137 : 0 : void implWriteCharToBuffer( ::rtl::OUStringBuffer& aBuf, sal_Unicode cu, bool bKey )
2138 : : {
2139 : 0 : if( cu == '\\' )
2140 : : {
2141 : 0 : aBuf.append( (sal_Unicode)'\\' );
2142 : 0 : aBuf.append( (sal_Unicode)'\\' );
2143 : : }
2144 : 0 : else if( cu == 0x000a )
2145 : : {
2146 : 0 : aBuf.append( (sal_Unicode)'\\' );
2147 : 0 : aBuf.append( (sal_Unicode)'n' );
2148 : : }
2149 : 0 : else if( cu == 0x000d )
2150 : : {
2151 : 0 : aBuf.append( (sal_Unicode)'\\' );
2152 : 0 : aBuf.append( (sal_Unicode)'r' );
2153 : : }
2154 : 0 : else if( bKey && cu == '=' )
2155 : : {
2156 : 0 : aBuf.append( (sal_Unicode)'\\' );
2157 : 0 : aBuf.append( (sal_Unicode)'=' );
2158 : : }
2159 : 0 : else if( bKey && cu == ':' )
2160 : : {
2161 : 0 : aBuf.append( (sal_Unicode)'\\' );
2162 : 0 : aBuf.append( (sal_Unicode)':' );
2163 : : }
2164 : : // ISO/IEC 8859-1 range according to:
2165 : : // http://en.wikipedia.org/wiki/ISO/IEC_8859-1
2166 : 0 : else if( (cu >= 0x20 && cu <= 0x7e) )
2167 : : //TODO: Check why (cu >= 0xa0 && cu <= 0xFF)
2168 : : //is encoded in sample properties files
2169 : : //else if( (cu >= 0x20 && cu <= 0x7e) ||
2170 : : // (cu >= 0xa0 && cu <= 0xFF) )
2171 : : {
2172 : 0 : aBuf.append( cu );
2173 : : }
2174 : : else
2175 : : {
2176 : : // Unicode encoding
2177 : 0 : aBuf.append( (sal_Unicode)'\\' );
2178 : 0 : aBuf.append( (sal_Unicode)'u' );
2179 : :
2180 : 0 : sal_uInt16 nVal = cu;
2181 : 0 : for( sal_uInt16 i = 0 ; i < 4 ; i++ )
2182 : : {
2183 : 0 : sal_uInt16 nDigit = nVal / 0x1000;
2184 : 0 : nVal -= nDigit * 0x1000;
2185 : 0 : nVal *= 0x10;
2186 : 0 : aBuf.append( getHexCharForDigit( nDigit ) );
2187 : : }
2188 : : }
2189 : 0 : }
2190 : :
2191 : 0 : void implWriteStringWithEncoding( const ::rtl::OUString& aStr,
2192 : : Reference< io::XTextOutputStream > xTextOutputStream, bool bKey )
2193 : : {
2194 : : static sal_Unicode cLineFeed = 0xa;
2195 : :
2196 : : (void)aStr;
2197 : : (void)xTextOutputStream;
2198 : :
2199 : 0 : ::rtl::OUStringBuffer aBuf;
2200 : 0 : sal_Int32 nLen = aStr.getLength();
2201 : 0 : const sal_Unicode* pSrc = aStr.getStr();
2202 : 0 : for( sal_Int32 i = 0 ; i < nLen ; i++ )
2203 : : {
2204 : 0 : sal_Unicode cu = pSrc[i];
2205 : 0 : implWriteCharToBuffer( aBuf, cu, bKey );
2206 : : // TODO?: split long lines
2207 : : }
2208 : 0 : if( !bKey )
2209 : 0 : aBuf.append( cLineFeed );
2210 : :
2211 : 0 : ::rtl::OUString aWriteStr = aBuf.makeStringAndClear();
2212 : 0 : xTextOutputStream->writeString( aWriteStr );
2213 : 0 : }
2214 : :
2215 : 0 : bool StringResourcePersistenceImpl::implWritePropertiesFile( LocaleItem* pLocaleItem,
2216 : : const Reference< io::XOutputStream >& xOutputStream, const ::rtl::OUString& aComment )
2217 : : {
2218 : 0 : static ::rtl::OUString aAssignmentStr("=");
2219 : 0 : static ::rtl::OUString aLineFeedStr("\n");
2220 : :
2221 : 0 : if( !xOutputStream.is() || pLocaleItem == NULL )
2222 : 0 : return false;
2223 : :
2224 : 0 : bool bSuccess = false;
2225 : 0 : Reference< XMultiComponentFactory > xMCF = getMultiComponentFactory();
2226 : 0 : Reference< io::XTextOutputStream > xTextOutputStream( xMCF->createInstanceWithContext
2227 : 0 : ( ::rtl::OUString("com.sun.star.io.TextOutputStream"), m_xContext ), UNO_QUERY );
2228 : :
2229 : 0 : if( xTextOutputStream.is() )
2230 : : {
2231 : 0 : Reference< io::XActiveDataSource> xActiveDataSource( xTextOutputStream, UNO_QUERY );
2232 : 0 : if( xActiveDataSource.is() )
2233 : : {
2234 : 0 : xActiveDataSource->setOutputStream( xOutputStream );
2235 : :
2236 : : ::rtl::OUString aEncodingStr = ::rtl::OUString::createFromAscii
2237 : 0 : ( rtl_getMimeCharsetFromTextEncoding( RTL_TEXTENCODING_ISO_8859_1 ) );
2238 : 0 : xTextOutputStream->setEncoding( aEncodingStr );
2239 : :
2240 : 0 : xTextOutputStream->writeString( aComment );
2241 : 0 : xTextOutputStream->writeString( aLineFeedStr );
2242 : :
2243 : 0 : const IdToStringMap& rHashMap = pLocaleItem->m_aIdToStringMap;
2244 : 0 : if( rHashMap.size() > 0 )
2245 : : {
2246 : : // Sort ids according to read order
2247 : 0 : const IdToIndexMap& rIndexMap = pLocaleItem->m_aIdToIndexMap;
2248 : 0 : IdToIndexMap::const_iterator it_index;
2249 : :
2250 : : // Find max/min index
2251 : 0 : sal_Int32 nMinIndex = -1;
2252 : 0 : sal_Int32 nMaxIndex = -1;
2253 : 0 : for( it_index = rIndexMap.begin(); it_index != rIndexMap.end(); ++it_index )
2254 : : {
2255 : 0 : sal_Int32 nIndex = (*it_index).second;
2256 : 0 : if( nMinIndex > nIndex || nMinIndex == -1 )
2257 : 0 : nMinIndex = nIndex;
2258 : 0 : if( nMaxIndex < nIndex )
2259 : 0 : nMaxIndex = nIndex;
2260 : : }
2261 : 0 : sal_Int32 nTabSize = nMaxIndex - nMinIndex + 1;
2262 : :
2263 : : // Create sorted array of pointers to the id strings
2264 : 0 : const ::rtl::OUString** pIdPtrs = new const ::rtl::OUString*[nTabSize];
2265 : : sal_Int32 i;
2266 : 0 : for( i = 0 ; i < nTabSize ; i++ )
2267 : 0 : pIdPtrs[i] = NULL;
2268 : 0 : for( it_index = rIndexMap.begin(); it_index != rIndexMap.end(); ++it_index )
2269 : : {
2270 : 0 : sal_Int32 nIndex = (*it_index).second;
2271 : 0 : pIdPtrs[nIndex - nMinIndex] = &((*it_index).first);
2272 : : }
2273 : :
2274 : : // Write lines in correct order
2275 : 0 : for( i = 0 ; i < nTabSize ; i++ )
2276 : : {
2277 : 0 : const ::rtl::OUString* pStr = pIdPtrs[i];
2278 : 0 : if( pStr != NULL )
2279 : : {
2280 : 0 : ::rtl::OUString aResourceID = *pStr;
2281 : 0 : IdToStringMap::const_iterator it = rHashMap.find( aResourceID );
2282 : 0 : if( !( it == rHashMap.end() ) )
2283 : : {
2284 : 0 : implWriteStringWithEncoding( aResourceID, xTextOutputStream, true );
2285 : 0 : xTextOutputStream->writeString( aAssignmentStr );
2286 : 0 : ::rtl::OUString aValStr = (*it).second;
2287 : 0 : implWriteStringWithEncoding( aValStr, xTextOutputStream, false );
2288 : 0 : }
2289 : : }
2290 : : }
2291 : :
2292 : 0 : delete pIdPtrs;
2293 : : }
2294 : :
2295 : 0 : bSuccess = true;
2296 : 0 : }
2297 : : }
2298 : 0 : return bSuccess;
2299 : : }
2300 : :
2301 : :
2302 : : // =============================================================================
2303 : : // StringResourceWithStorageImpl
2304 : : // =============================================================================
2305 : :
2306 : : // component operations
2307 : 0 : static Sequence< ::rtl::OUString > getSupportedServiceNames_StringResourceWithStorageImpl()
2308 : : {
2309 : 0 : Sequence< ::rtl::OUString > names(1);
2310 : 0 : names[0] = ::rtl::OUString( "com.sun.star.resource.StringResourceWithStorage" );
2311 : 0 : return names;
2312 : : }
2313 : :
2314 : 0 : static ::rtl::OUString getImplementationName_StringResourceWithStorageImpl()
2315 : : {
2316 : 0 : return ::rtl::OUString( "com.sun.star.comp.scripting.StringResourceWithStorage" );
2317 : : }
2318 : :
2319 : 0 : static Reference< XInterface > SAL_CALL create_StringResourceWithStorageImpl(
2320 : : Reference< XComponentContext > const & xContext )
2321 : : SAL_THROW(())
2322 : : {
2323 : 0 : return static_cast< ::cppu::OWeakObject * >( new StringResourceWithStorageImpl( xContext ) );
2324 : : }
2325 : :
2326 : : // -----------------------------------------------------------------------------
2327 : :
2328 : 0 : StringResourceWithStorageImpl::StringResourceWithStorageImpl( const Reference< XComponentContext >& rxContext )
2329 : : : StringResourceWithStorageImpl_BASE( rxContext )
2330 : 0 : , m_bStorageChanged( false )
2331 : : {
2332 : 0 : }
2333 : :
2334 : : // -----------------------------------------------------------------------------
2335 : :
2336 : 0 : StringResourceWithStorageImpl::~StringResourceWithStorageImpl()
2337 : : {
2338 : 0 : }
2339 : :
2340 : : // -----------------------------------------------------------------------------
2341 : : // XServiceInfo
2342 : : // -----------------------------------------------------------------------------
2343 : :
2344 : 0 : ::rtl::OUString StringResourceWithStorageImpl::getImplementationName( ) throw (RuntimeException)
2345 : : {
2346 : 0 : return getImplementationName_StringResourceWithStorageImpl();
2347 : : }
2348 : :
2349 : : // -----------------------------------------------------------------------------
2350 : :
2351 : 0 : sal_Bool StringResourceWithStorageImpl::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
2352 : : {
2353 : 0 : Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
2354 : 0 : const ::rtl::OUString* pNames = aNames.getConstArray();
2355 : 0 : const ::rtl::OUString* pEnd = pNames + aNames.getLength();
2356 : 0 : for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
2357 : : ;
2358 : :
2359 : 0 : return pNames != pEnd;
2360 : : }
2361 : :
2362 : : // -----------------------------------------------------------------------------
2363 : :
2364 : 0 : Sequence< ::rtl::OUString > StringResourceWithStorageImpl::getSupportedServiceNames( ) throw (RuntimeException)
2365 : : {
2366 : 0 : return getSupportedServiceNames_StringResourceWithStorageImpl();
2367 : : }
2368 : :
2369 : : // -----------------------------------------------------------------------------
2370 : : // XInitialization
2371 : : // -----------------------------------------------------------------------------
2372 : :
2373 : 0 : void StringResourceWithStorageImpl::initialize( const Sequence< Any >& aArguments )
2374 : : throw (Exception, RuntimeException)
2375 : : {
2376 : 0 : ::osl::MutexGuard aGuard( getMutex() );
2377 : :
2378 : 0 : if ( aArguments.getLength() != 5 )
2379 : : {
2380 : : throw RuntimeException(
2381 : : ::rtl::OUString( "StringResourceWithStorageImpl::initialize: invalid number of arguments!" ),
2382 : 0 : Reference< XInterface >() );
2383 : : }
2384 : :
2385 : 0 : bool bOk = (aArguments[0] >>= m_xStorage);
2386 : 0 : if( bOk && !m_xStorage.is() )
2387 : 0 : bOk = false;
2388 : :
2389 : 0 : if( !bOk )
2390 : : {
2391 : 0 : ::rtl::OUString errorMsg("StringResourceWithStorageImpl::initialize: invalid storage");
2392 : 0 : throw IllegalArgumentException( errorMsg, Reference< XInterface >(), 0 );
2393 : : }
2394 : :
2395 : 0 : implInitializeCommonParameters( aArguments );
2396 : 0 : }
2397 : :
2398 : : // -----------------------------------------------------------------------------
2399 : : // Forwarding calls to base class
2400 : :
2401 : : // XModifyBroadcaster
2402 : 0 : void StringResourceWithStorageImpl::addModifyListener( const Reference< XModifyListener >& aListener )
2403 : : throw (RuntimeException)
2404 : : {
2405 : 0 : StringResourceImpl::addModifyListener( aListener );
2406 : 0 : }
2407 : 0 : void StringResourceWithStorageImpl::removeModifyListener( const Reference< XModifyListener >& aListener )
2408 : : throw (RuntimeException)
2409 : : {
2410 : 0 : StringResourceImpl::removeModifyListener( aListener );
2411 : 0 : }
2412 : :
2413 : : // XStringResourceResolver
2414 : 0 : ::rtl::OUString StringResourceWithStorageImpl::resolveString( const ::rtl::OUString& ResourceID )
2415 : : throw (::com::sun::star::resource::MissingResourceException, RuntimeException)
2416 : : {
2417 : 0 : return StringResourceImpl::resolveString( ResourceID ) ;
2418 : : }
2419 : 0 : ::rtl::OUString StringResourceWithStorageImpl::resolveStringForLocale( const ::rtl::OUString& ResourceID, const Locale& locale )
2420 : : throw ( ::com::sun::star::resource::MissingResourceException, RuntimeException)
2421 : : {
2422 : 0 : return StringResourceImpl::resolveStringForLocale( ResourceID, locale );
2423 : : }
2424 : 0 : sal_Bool StringResourceWithStorageImpl::hasEntryForId( const ::rtl::OUString& ResourceID )
2425 : : throw (RuntimeException)
2426 : : {
2427 : 0 : return StringResourceImpl::hasEntryForId( ResourceID ) ;
2428 : : }
2429 : 0 : sal_Bool StringResourceWithStorageImpl::hasEntryForIdAndLocale( const ::rtl::OUString& ResourceID,
2430 : : const Locale& locale )
2431 : : throw (RuntimeException)
2432 : : {
2433 : 0 : return StringResourceImpl::hasEntryForIdAndLocale( ResourceID, locale );
2434 : : }
2435 : 0 : Sequence< ::rtl::OUString > StringResourceWithStorageImpl::getResourceIDs( )
2436 : : throw (RuntimeException)
2437 : : {
2438 : 0 : return StringResourceImpl::getResourceIDs();
2439 : : }
2440 : 0 : Sequence< ::rtl::OUString > StringResourceWithStorageImpl::getResourceIDsForLocale
2441 : : ( const Locale& locale ) throw (::com::sun::star::uno::RuntimeException)
2442 : : {
2443 : 0 : return StringResourceImpl::getResourceIDsForLocale( locale );
2444 : : }
2445 : 0 : Locale StringResourceWithStorageImpl::getCurrentLocale()
2446 : : throw (RuntimeException)
2447 : : {
2448 : 0 : return StringResourceImpl::getCurrentLocale();
2449 : : }
2450 : 0 : Locale StringResourceWithStorageImpl::getDefaultLocale( )
2451 : : throw (RuntimeException)
2452 : : {
2453 : 0 : return StringResourceImpl::getDefaultLocale();
2454 : : }
2455 : 0 : Sequence< Locale > StringResourceWithStorageImpl::getLocales( )
2456 : : throw (RuntimeException)
2457 : : {
2458 : 0 : return StringResourceImpl::getLocales();
2459 : : }
2460 : :
2461 : : // XStringResourceManager
2462 : 0 : sal_Bool StringResourceWithStorageImpl::isReadOnly()
2463 : : throw (RuntimeException)
2464 : : {
2465 : 0 : return StringResourceImpl::isReadOnly();
2466 : : }
2467 : 0 : void StringResourceWithStorageImpl::setCurrentLocale( const Locale& locale, sal_Bool FindClosestMatch )
2468 : : throw (IllegalArgumentException, RuntimeException)
2469 : : {
2470 : 0 : StringResourceImpl::setCurrentLocale( locale, FindClosestMatch );
2471 : 0 : }
2472 : 0 : void StringResourceWithStorageImpl::setDefaultLocale( const Locale& locale )
2473 : : throw (IllegalArgumentException, RuntimeException,NoSupportException)
2474 : : {
2475 : 0 : StringResourceImpl::setDefaultLocale( locale );
2476 : 0 : }
2477 : 0 : void StringResourceWithStorageImpl::setString( const ::rtl::OUString& ResourceID, const ::rtl::OUString& Str )
2478 : : throw (NoSupportException, RuntimeException)
2479 : : {
2480 : 0 : StringResourceImpl::setString( ResourceID, Str );
2481 : 0 : }
2482 : 0 : void StringResourceWithStorageImpl::setStringForLocale
2483 : : ( const ::rtl::OUString& ResourceID, const ::rtl::OUString& Str, const Locale& locale )
2484 : : throw (NoSupportException, RuntimeException)
2485 : : {
2486 : 0 : StringResourceImpl::setStringForLocale( ResourceID, Str, locale );
2487 : 0 : }
2488 : 0 : void StringResourceWithStorageImpl::removeId( const ::rtl::OUString& ResourceID )
2489 : : throw (::com::sun::star::resource::MissingResourceException, RuntimeException, NoSupportException)
2490 : : {
2491 : 0 : StringResourceImpl::removeId( ResourceID );
2492 : 0 : }
2493 : 0 : void StringResourceWithStorageImpl::removeIdForLocale( const ::rtl::OUString& ResourceID, const Locale& locale )
2494 : : throw (::com::sun::star::resource::MissingResourceException, RuntimeException, NoSupportException)
2495 : : {
2496 : 0 : StringResourceImpl::removeIdForLocale( ResourceID, locale );
2497 : 0 : }
2498 : 0 : void StringResourceWithStorageImpl::newLocale( const Locale& locale )
2499 : : throw (ElementExistException, IllegalArgumentException, RuntimeException, NoSupportException)
2500 : : {
2501 : 0 : StringResourceImpl::newLocale( locale );
2502 : 0 : }
2503 : 0 : void StringResourceWithStorageImpl::removeLocale( const Locale& locale )
2504 : : throw (IllegalArgumentException, RuntimeException, NoSupportException)
2505 : : {
2506 : 0 : StringResourceImpl::removeLocale( locale );
2507 : 0 : }
2508 : 0 : sal_Int32 StringResourceWithStorageImpl::getUniqueNumericId( )
2509 : : throw (RuntimeException, NoSupportException)
2510 : : {
2511 : 0 : return StringResourceImpl::getUniqueNumericId();
2512 : : }
2513 : :
2514 : : // XStringResourcePersistence
2515 : 0 : void StringResourceWithStorageImpl::store()
2516 : : throw (NoSupportException, Exception, RuntimeException)
2517 : : {
2518 : 0 : ::osl::MutexGuard aGuard( getMutex() );
2519 : 0 : implCheckReadOnly( "StringResourceWithStorageImpl::store(): Read only" );
2520 : :
2521 : 0 : bool bUsedForStore = true;
2522 : 0 : bool bStoreAll = m_bStorageChanged;
2523 : 0 : m_bStorageChanged = false;
2524 : 0 : if( !m_bModified && !bStoreAll )
2525 : 0 : return;
2526 : :
2527 : 0 : implStoreAtStorage( m_aNameBase, m_aComment, m_xStorage, bUsedForStore, bStoreAll );
2528 : 0 : m_bModified = false;
2529 : : }
2530 : :
2531 : 0 : sal_Bool StringResourceWithStorageImpl::isModified( )
2532 : : throw (RuntimeException)
2533 : : {
2534 : 0 : return StringResourcePersistenceImpl::isModified();
2535 : : }
2536 : 0 : void StringResourceWithStorageImpl::setComment( const ::rtl::OUString& Comment )
2537 : : throw (::com::sun::star::uno::RuntimeException)
2538 : : {
2539 : 0 : StringResourcePersistenceImpl::setComment( Comment );
2540 : 0 : }
2541 : 0 : void StringResourceWithStorageImpl::storeToStorage( const Reference< XStorage >& Storage,
2542 : : const ::rtl::OUString& NameBase, const ::rtl::OUString& Comment )
2543 : : throw (Exception, RuntimeException)
2544 : : {
2545 : 0 : StringResourcePersistenceImpl::storeToStorage( Storage, NameBase, Comment );
2546 : 0 : }
2547 : 0 : void StringResourceWithStorageImpl::storeToURL( const ::rtl::OUString& URL,
2548 : : const ::rtl::OUString& NameBase, const ::rtl::OUString& Comment,
2549 : : const Reference< ::com::sun::star::task::XInteractionHandler >& Handler )
2550 : : throw (Exception, RuntimeException)
2551 : : {
2552 : 0 : StringResourcePersistenceImpl::storeToURL( URL, NameBase, Comment, Handler );
2553 : 0 : }
2554 : 0 : Sequence< ::sal_Int8 > StringResourceWithStorageImpl::exportBinary( )
2555 : : throw (RuntimeException)
2556 : : {
2557 : 0 : return StringResourcePersistenceImpl::exportBinary();
2558 : : }
2559 : 0 : void StringResourceWithStorageImpl::importBinary( const Sequence< ::sal_Int8 >& Data )
2560 : : throw (IllegalArgumentException, RuntimeException)
2561 : : {
2562 : 0 : StringResourcePersistenceImpl::importBinary( Data );
2563 : 0 : }
2564 : :
2565 : : // -----------------------------------------------------------------------------
2566 : : // XStringResourceWithStorage
2567 : :
2568 : 0 : void StringResourceWithStorageImpl::storeAsStorage( const Reference< XStorage >& Storage )
2569 : : throw (Exception, RuntimeException)
2570 : : {
2571 : 0 : setStorage( Storage );
2572 : 0 : store();
2573 : 0 : }
2574 : :
2575 : 0 : void StringResourceWithStorageImpl::setStorage( const Reference< XStorage >& Storage )
2576 : : throw (IllegalArgumentException, RuntimeException)
2577 : : {
2578 : 0 : ::osl::MutexGuard aGuard( getMutex() );
2579 : :
2580 : 0 : if( !Storage.is() )
2581 : : {
2582 : : ::rtl::OUString errorMsg(RTL_CONSTASCII_USTRINGPARAM
2583 : 0 : ( "StringResourceWithStorageImpl::setStorage: invalid storage" ));
2584 : 0 : throw IllegalArgumentException( errorMsg, Reference< XInterface >(), 0 );
2585 : : }
2586 : :
2587 : 0 : implLoadAllLocales();
2588 : :
2589 : 0 : m_xStorage = Storage;
2590 : 0 : m_bStorageChanged = true;
2591 : 0 : }
2592 : :
2593 : :
2594 : : // =============================================================================
2595 : : // Private helper methods
2596 : : // =============================================================================
2597 : :
2598 : : // Scan locale properties files
2599 : 0 : void StringResourceWithStorageImpl::implScanLocales( void )
2600 : : {
2601 : 0 : Reference< container::XNameAccess > xNameAccess( m_xStorage, UNO_QUERY );
2602 : 0 : if( xNameAccess.is() )
2603 : : {
2604 : 0 : Sequence< ::rtl::OUString > aContentSeq = xNameAccess->getElementNames();
2605 : 0 : implScanLocaleNames( aContentSeq );
2606 : : }
2607 : :
2608 : 0 : implLoadAllLocales();
2609 : 0 : }
2610 : :
2611 : : // Loading
2612 : 0 : bool StringResourceWithStorageImpl::implLoadLocale( LocaleItem* pLocaleItem )
2613 : : {
2614 : 0 : bool bSuccess = false;
2615 : : try
2616 : : {
2617 : 0 : ::rtl::OUString aStreamName = implGetFileNameForLocaleItem( pLocaleItem, m_aNameBase );
2618 : 0 : aStreamName += ::rtl::OUString( ".properties" );
2619 : :
2620 : : Reference< io::XStream > xElementStream =
2621 : 0 : m_xStorage->openStreamElement( aStreamName, ElementModes::READ );
2622 : :
2623 : 0 : if( xElementStream.is() )
2624 : : {
2625 : 0 : Reference< io::XInputStream > xInputStream = xElementStream->getInputStream();
2626 : 0 : if( xInputStream.is() )
2627 : : {
2628 : 0 : bSuccess = StringResourcePersistenceImpl::implReadPropertiesFile( pLocaleItem, xInputStream );
2629 : 0 : xInputStream->closeInput();
2630 : 0 : }
2631 : 0 : }
2632 : : }
2633 : 0 : catch( uno::Exception& )
2634 : : {}
2635 : :
2636 : 0 : return bSuccess;
2637 : : }
2638 : :
2639 : :
2640 : : // =============================================================================
2641 : : // StringResourceWithLocationImpl
2642 : : // =============================================================================
2643 : :
2644 : : // component operations
2645 : 0 : static Sequence< ::rtl::OUString > getSupportedServiceNames_StringResourceWithLocationImpl()
2646 : : {
2647 : 0 : Sequence< ::rtl::OUString > names(1);
2648 : 0 : names[0] = ::rtl::OUString( "com.sun.star.resource.StringResourceWithLocation" );
2649 : 0 : return names;
2650 : : }
2651 : :
2652 : 0 : static ::rtl::OUString getImplementationName_StringResourceWithLocationImpl()
2653 : : {
2654 : 0 : return ::rtl::OUString( "com.sun.star.comp.scripting.StringResourceWithLocation" );
2655 : : }
2656 : :
2657 : 0 : static Reference< XInterface > SAL_CALL create_StringResourceWithLocationImpl(
2658 : : Reference< XComponentContext > const & xContext )
2659 : : SAL_THROW(())
2660 : : {
2661 : 0 : return static_cast< ::cppu::OWeakObject * >( new StringResourceWithLocationImpl( xContext ) );
2662 : : }
2663 : :
2664 : : // -----------------------------------------------------------------------------
2665 : :
2666 : 0 : StringResourceWithLocationImpl::StringResourceWithLocationImpl( const Reference< XComponentContext >& rxContext )
2667 : : : StringResourceWithLocationImpl_BASE( rxContext )
2668 : 0 : , m_bLocationChanged( false )
2669 : : {
2670 : 0 : }
2671 : :
2672 : : // -----------------------------------------------------------------------------
2673 : :
2674 : 0 : StringResourceWithLocationImpl::~StringResourceWithLocationImpl()
2675 : : {
2676 : 0 : }
2677 : :
2678 : : // -----------------------------------------------------------------------------
2679 : : // XServiceInfo
2680 : : // -----------------------------------------------------------------------------
2681 : :
2682 : 0 : ::rtl::OUString StringResourceWithLocationImpl::getImplementationName( ) throw (RuntimeException)
2683 : : {
2684 : 0 : return getImplementationName_StringResourceWithLocationImpl();
2685 : : }
2686 : :
2687 : : // -----------------------------------------------------------------------------
2688 : :
2689 : 0 : sal_Bool StringResourceWithLocationImpl::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
2690 : : {
2691 : 0 : Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
2692 : 0 : const ::rtl::OUString* pNames = aNames.getConstArray();
2693 : 0 : const ::rtl::OUString* pEnd = pNames + aNames.getLength();
2694 : 0 : for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
2695 : : ;
2696 : :
2697 : 0 : return pNames != pEnd;
2698 : : }
2699 : :
2700 : : // -----------------------------------------------------------------------------
2701 : :
2702 : 0 : Sequence< ::rtl::OUString > StringResourceWithLocationImpl::getSupportedServiceNames( ) throw (RuntimeException)
2703 : : {
2704 : 0 : return getSupportedServiceNames_StringResourceWithLocationImpl();
2705 : : }
2706 : :
2707 : : // -----------------------------------------------------------------------------
2708 : : // XInitialization
2709 : : // -----------------------------------------------------------------------------
2710 : :
2711 : 0 : void StringResourceWithLocationImpl::initialize( const Sequence< Any >& aArguments )
2712 : : throw (Exception, RuntimeException)
2713 : : {
2714 : 0 : ::osl::MutexGuard aGuard( getMutex() );
2715 : :
2716 : 0 : if ( aArguments.getLength() != 6 )
2717 : : {
2718 : : throw RuntimeException(
2719 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM
2720 : : ( "XInitialization::initialize: invalid number of arguments!" ) ),
2721 : 0 : Reference< XInterface >() );
2722 : : }
2723 : :
2724 : 0 : bool bOk = (aArguments[0] >>= m_aLocation);
2725 : 0 : sal_Int32 nLen = m_aLocation.getLength();
2726 : 0 : if( bOk && nLen == 0 )
2727 : : {
2728 : 0 : bOk = false;
2729 : : }
2730 : : else
2731 : : {
2732 : 0 : if( m_aLocation.getStr()[nLen - 1] != '/' )
2733 : 0 : m_aLocation += ::rtl::OUString("/");
2734 : : }
2735 : :
2736 : 0 : if( !bOk )
2737 : : {
2738 : 0 : ::rtl::OUString errorMsg("XInitialization::initialize: invalid URL");
2739 : 0 : throw IllegalArgumentException( errorMsg, Reference< XInterface >(), 0 );
2740 : : }
2741 : :
2742 : :
2743 : 0 : bOk = (aArguments[5] >>= m_xInteractionHandler);
2744 : 0 : if( !bOk )
2745 : : {
2746 : 0 : ::rtl::OUString errorMsg("StringResourceWithStorageImpl::initialize: invalid type");
2747 : 0 : throw IllegalArgumentException( errorMsg, Reference< XInterface >(), 5 );
2748 : : }
2749 : :
2750 : 0 : implInitializeCommonParameters( aArguments );
2751 : 0 : }
2752 : :
2753 : : // -----------------------------------------------------------------------------
2754 : : // Forwarding calls to base class
2755 : :
2756 : : // XModifyBroadcaster
2757 : 0 : void StringResourceWithLocationImpl::addModifyListener( const Reference< XModifyListener >& aListener )
2758 : : throw (RuntimeException)
2759 : : {
2760 : 0 : StringResourceImpl::addModifyListener( aListener );
2761 : 0 : }
2762 : 0 : void StringResourceWithLocationImpl::removeModifyListener( const Reference< XModifyListener >& aListener )
2763 : : throw (RuntimeException)
2764 : : {
2765 : 0 : StringResourceImpl::removeModifyListener( aListener );
2766 : 0 : }
2767 : :
2768 : : // XStringResourceResolver
2769 : 0 : ::rtl::OUString StringResourceWithLocationImpl::resolveString( const ::rtl::OUString& ResourceID )
2770 : : throw (::com::sun::star::resource::MissingResourceException, RuntimeException)
2771 : : {
2772 : 0 : return StringResourceImpl::resolveString( ResourceID ) ;
2773 : : }
2774 : 0 : ::rtl::OUString StringResourceWithLocationImpl::resolveStringForLocale( const ::rtl::OUString& ResourceID, const Locale& locale )
2775 : : throw ( ::com::sun::star::resource::MissingResourceException, RuntimeException)
2776 : : {
2777 : 0 : return StringResourceImpl::resolveStringForLocale( ResourceID, locale );
2778 : : }
2779 : 0 : sal_Bool StringResourceWithLocationImpl::hasEntryForId( const ::rtl::OUString& ResourceID )
2780 : : throw (RuntimeException)
2781 : : {
2782 : 0 : return StringResourceImpl::hasEntryForId( ResourceID ) ;
2783 : : }
2784 : 0 : sal_Bool StringResourceWithLocationImpl::hasEntryForIdAndLocale( const ::rtl::OUString& ResourceID,
2785 : : const Locale& locale )
2786 : : throw (RuntimeException)
2787 : : {
2788 : 0 : return StringResourceImpl::hasEntryForIdAndLocale( ResourceID, locale );
2789 : : }
2790 : 0 : Sequence< ::rtl::OUString > StringResourceWithLocationImpl::getResourceIDs( )
2791 : : throw (RuntimeException)
2792 : : {
2793 : 0 : return StringResourceImpl::getResourceIDs();
2794 : : }
2795 : 0 : Sequence< ::rtl::OUString > StringResourceWithLocationImpl::getResourceIDsForLocale
2796 : : ( const Locale& locale ) throw (::com::sun::star::uno::RuntimeException)
2797 : : {
2798 : 0 : return StringResourceImpl::getResourceIDsForLocale( locale );
2799 : : }
2800 : 0 : Locale StringResourceWithLocationImpl::getCurrentLocale()
2801 : : throw (RuntimeException)
2802 : : {
2803 : 0 : return StringResourceImpl::getCurrentLocale();
2804 : : }
2805 : 0 : Locale StringResourceWithLocationImpl::getDefaultLocale( )
2806 : : throw (RuntimeException)
2807 : : {
2808 : 0 : return StringResourceImpl::getDefaultLocale();
2809 : : }
2810 : 0 : Sequence< Locale > StringResourceWithLocationImpl::getLocales( )
2811 : : throw (RuntimeException)
2812 : : {
2813 : 0 : return StringResourceImpl::getLocales();
2814 : : }
2815 : :
2816 : : // XStringResourceManager
2817 : 0 : sal_Bool StringResourceWithLocationImpl::isReadOnly()
2818 : : throw (RuntimeException)
2819 : : {
2820 : 0 : return StringResourceImpl::isReadOnly();
2821 : : }
2822 : 0 : void StringResourceWithLocationImpl::setCurrentLocale( const Locale& locale, sal_Bool FindClosestMatch )
2823 : : throw (IllegalArgumentException, RuntimeException)
2824 : : {
2825 : 0 : StringResourceImpl::setCurrentLocale( locale, FindClosestMatch );
2826 : 0 : }
2827 : 0 : void StringResourceWithLocationImpl::setDefaultLocale( const Locale& locale )
2828 : : throw (IllegalArgumentException, RuntimeException,NoSupportException)
2829 : : {
2830 : 0 : StringResourceImpl::setDefaultLocale( locale );
2831 : 0 : }
2832 : 0 : void StringResourceWithLocationImpl::setString( const ::rtl::OUString& ResourceID, const ::rtl::OUString& Str )
2833 : : throw (NoSupportException, RuntimeException)
2834 : : {
2835 : 0 : StringResourceImpl::setString( ResourceID, Str );
2836 : 0 : }
2837 : 0 : void StringResourceWithLocationImpl::setStringForLocale
2838 : : ( const ::rtl::OUString& ResourceID, const ::rtl::OUString& Str, const Locale& locale )
2839 : : throw (NoSupportException, RuntimeException)
2840 : : {
2841 : 0 : StringResourceImpl::setStringForLocale( ResourceID, Str, locale );
2842 : 0 : }
2843 : 0 : void StringResourceWithLocationImpl::removeId( const ::rtl::OUString& ResourceID )
2844 : : throw (::com::sun::star::resource::MissingResourceException, RuntimeException, NoSupportException)
2845 : : {
2846 : 0 : StringResourceImpl::removeId( ResourceID );
2847 : 0 : }
2848 : 0 : void StringResourceWithLocationImpl::removeIdForLocale( const ::rtl::OUString& ResourceID, const Locale& locale )
2849 : : throw (::com::sun::star::resource::MissingResourceException, RuntimeException, NoSupportException)
2850 : : {
2851 : 0 : StringResourceImpl::removeIdForLocale( ResourceID, locale );
2852 : 0 : }
2853 : 0 : void StringResourceWithLocationImpl::newLocale( const Locale& locale )
2854 : : throw (ElementExistException, IllegalArgumentException, RuntimeException, NoSupportException)
2855 : : {
2856 : 0 : StringResourceImpl::newLocale( locale );
2857 : 0 : }
2858 : 0 : void StringResourceWithLocationImpl::removeLocale( const Locale& locale )
2859 : : throw (IllegalArgumentException, RuntimeException, NoSupportException)
2860 : : {
2861 : 0 : StringResourceImpl::removeLocale( locale );
2862 : 0 : }
2863 : 0 : sal_Int32 StringResourceWithLocationImpl::getUniqueNumericId( )
2864 : : throw (RuntimeException, NoSupportException)
2865 : : {
2866 : 0 : return StringResourceImpl::getUniqueNumericId();
2867 : : }
2868 : :
2869 : : // XStringResourcePersistence
2870 : 0 : void StringResourceWithLocationImpl::store()
2871 : : throw (NoSupportException, Exception, RuntimeException)
2872 : : {
2873 : 0 : ::osl::MutexGuard aGuard( getMutex() );
2874 : 0 : implCheckReadOnly( "StringResourceWithLocationImpl::store(): Read only" );
2875 : :
2876 : 0 : bool bUsedForStore = true;
2877 : 0 : bool bStoreAll = m_bLocationChanged;
2878 : 0 : m_bLocationChanged = false;
2879 : 0 : if( !m_bModified && !bStoreAll )
2880 : 0 : return;
2881 : :
2882 : 0 : Reference< ucb::XSimpleFileAccess2 > xFileAccess = getFileAccess();
2883 : : implStoreAtLocation( m_aLocation, m_aNameBase, m_aComment,
2884 : 0 : xFileAccess, bUsedForStore, bStoreAll );
2885 : 0 : m_bModified = false;
2886 : : }
2887 : :
2888 : 0 : sal_Bool StringResourceWithLocationImpl::isModified( )
2889 : : throw (RuntimeException)
2890 : : {
2891 : 0 : return StringResourcePersistenceImpl::isModified();
2892 : : }
2893 : 0 : void StringResourceWithLocationImpl::setComment( const ::rtl::OUString& Comment )
2894 : : throw (::com::sun::star::uno::RuntimeException)
2895 : : {
2896 : 0 : StringResourcePersistenceImpl::setComment( Comment );
2897 : 0 : }
2898 : 0 : void StringResourceWithLocationImpl::storeToStorage( const Reference< XStorage >& Storage,
2899 : : const ::rtl::OUString& NameBase, const ::rtl::OUString& Comment )
2900 : : throw (Exception, RuntimeException)
2901 : : {
2902 : 0 : StringResourcePersistenceImpl::storeToStorage( Storage, NameBase, Comment );
2903 : 0 : }
2904 : 0 : void StringResourceWithLocationImpl::storeToURL( const ::rtl::OUString& URL,
2905 : : const ::rtl::OUString& NameBase, const ::rtl::OUString& Comment,
2906 : : const Reference< ::com::sun::star::task::XInteractionHandler >& Handler )
2907 : : throw (Exception, RuntimeException)
2908 : : {
2909 : 0 : StringResourcePersistenceImpl::storeToURL( URL, NameBase, Comment, Handler );
2910 : 0 : }
2911 : 0 : Sequence< ::sal_Int8 > StringResourceWithLocationImpl::exportBinary( )
2912 : : throw (RuntimeException)
2913 : : {
2914 : 0 : return StringResourcePersistenceImpl::exportBinary();
2915 : : }
2916 : 0 : void StringResourceWithLocationImpl::importBinary( const Sequence< ::sal_Int8 >& Data )
2917 : : throw (IllegalArgumentException, RuntimeException)
2918 : : {
2919 : 0 : StringResourcePersistenceImpl::importBinary( Data );
2920 : 0 : }
2921 : :
2922 : : // -----------------------------------------------------------------------------
2923 : : // XStringResourceWithLocation
2924 : :
2925 : : // XStringResourceWithLocation
2926 : 0 : void StringResourceWithLocationImpl::storeAsURL( const ::rtl::OUString& URL )
2927 : : throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
2928 : : {
2929 : 0 : setURL( URL );
2930 : 0 : store();
2931 : 0 : }
2932 : :
2933 : 0 : void StringResourceWithLocationImpl::setURL( const ::rtl::OUString& URL )
2934 : : throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
2935 : : {
2936 : 0 : ::osl::MutexGuard aGuard( getMutex() );
2937 : 0 : implCheckReadOnly( "StringResourceWithLocationImpl::setURL(): Read only" );
2938 : :
2939 : 0 : sal_Int32 nLen = URL.getLength();
2940 : 0 : if( nLen == 0 )
2941 : : {
2942 : : ::rtl::OUString errorMsg(RTL_CONSTASCII_USTRINGPARAM
2943 : 0 : ( "StringResourceWithLocationImpl::setURL: invalid URL" ));
2944 : 0 : throw IllegalArgumentException( errorMsg, Reference< XInterface >(), 0 );
2945 : : }
2946 : :
2947 : 0 : implLoadAllLocales();
2948 : :
2949 : : // Delete files at old location
2950 : 0 : bool bUsedForStore = false;
2951 : 0 : bool bStoreAll = false;
2952 : 0 : bool bKillAll = true;
2953 : : implStoreAtLocation( m_aLocation, m_aNameBase, m_aComment,
2954 : 0 : getFileAccess(), bUsedForStore, bStoreAll, bKillAll );
2955 : :
2956 : 0 : m_aLocation = URL;
2957 : 0 : m_bLocationChanged = true;
2958 : 0 : }
2959 : :
2960 : :
2961 : : // =============================================================================
2962 : : // Private helper methods
2963 : : // =============================================================================
2964 : :
2965 : : // Scan locale properties files
2966 : 0 : void StringResourceWithLocationImpl::implScanLocales( void )
2967 : : {
2968 : 0 : const Reference< ucb::XSimpleFileAccess2 > xFileAccess = getFileAccess();
2969 : 0 : if( xFileAccess.is() && xFileAccess->isFolder( m_aLocation ) )
2970 : : {
2971 : 0 : Sequence< ::rtl::OUString > aContentSeq = xFileAccess->getFolderContents( m_aLocation, false );
2972 : 0 : implScanLocaleNames( aContentSeq );
2973 : 0 : }
2974 : 0 : }
2975 : :
2976 : : // Loading
2977 : 0 : bool StringResourceWithLocationImpl::implLoadLocale( LocaleItem* pLocaleItem )
2978 : : {
2979 : 0 : bool bSuccess = false;
2980 : :
2981 : 0 : const Reference< ucb::XSimpleFileAccess2 > xFileAccess = getFileAccess();
2982 : 0 : if( xFileAccess.is() )
2983 : : {
2984 : : ::rtl::OUString aCompleteFileName =
2985 : 0 : implGetPathForLocaleItem( pLocaleItem, m_aNameBase, m_aLocation );
2986 : :
2987 : 0 : Reference< io::XInputStream > xInputStream;
2988 : : try
2989 : : {
2990 : 0 : xInputStream = xFileAccess->openFileRead( aCompleteFileName );
2991 : : }
2992 : 0 : catch( Exception& )
2993 : : {}
2994 : 0 : if( xInputStream.is() )
2995 : : {
2996 : 0 : bSuccess = StringResourcePersistenceImpl::implReadPropertiesFile( pLocaleItem, xInputStream );
2997 : 0 : xInputStream->closeInput();
2998 : 0 : }
2999 : : }
3000 : :
3001 : 0 : return bSuccess;
3002 : : }
3003 : :
3004 : 0 : const Reference< ucb::XSimpleFileAccess2 > StringResourceWithLocationImpl::getFileAccess( void )
3005 : : {
3006 : 0 : ::osl::MutexGuard aGuard( getMutex() );
3007 : :
3008 : 0 : if( !m_xSFI.is() )
3009 : : {
3010 : 0 : m_xSFI = ucb::SimpleFileAccess::create(m_xContext);
3011 : :
3012 : 0 : if( m_xSFI.is() && m_xInteractionHandler.is() )
3013 : 0 : m_xSFI->setInteractionHandler( m_xInteractionHandler );
3014 : : }
3015 : 0 : return m_xSFI;
3016 : : }
3017 : :
3018 : :
3019 : : // =============================================================================
3020 : : // component export operations
3021 : : // =============================================================================
3022 : :
3023 : : static struct ::cppu::ImplementationEntry s_component_entries [] =
3024 : : {
3025 : : {
3026 : : create_StringResourceImpl, getImplementationName_StringResourceImpl,
3027 : : getSupportedServiceNames_StringResourceImpl,
3028 : : ::cppu::createSingleComponentFactory,
3029 : : 0, 0
3030 : : },
3031 : : {
3032 : : create_StringResourceWithLocationImpl, getImplementationName_StringResourceWithLocationImpl,
3033 : : getSupportedServiceNames_StringResourceWithLocationImpl,
3034 : : ::cppu::createSingleComponentFactory,
3035 : : 0, 0
3036 : : },
3037 : : {
3038 : : create_StringResourceWithStorageImpl, getImplementationName_StringResourceWithStorageImpl,
3039 : : getSupportedServiceNames_StringResourceWithStorageImpl,
3040 : : ::cppu::createSingleComponentFactory,
3041 : : 0, 0
3042 : : },
3043 : : { 0, 0, 0, 0, 0, 0 }
3044 : : };
3045 : :
3046 : :
3047 : : //.........................................................................
3048 : : } // namespace dlgprov
3049 : : //.........................................................................
3050 : :
3051 : :
3052 : : // =============================================================================
3053 : : // component exports
3054 : : // =============================================================================
3055 : :
3056 : : extern "C"
3057 : : {
3058 : 0 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
3059 : : const sal_Char * pImplName, lang::XMultiServiceFactory * pServiceManager,
3060 : : registry::XRegistryKey * pRegistryKey )
3061 : : {
3062 : : return ::cppu::component_getFactoryHelper(
3063 : 0 : pImplName, pServiceManager, pRegistryKey, ::stringresource::s_component_entries );
3064 : : }
3065 : 0 : }
3066 : :
3067 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|