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 :
21 : #include <tools/stream.hxx>
22 : #include <tools/urlobj.hxx>
23 : #include <unotools/pathoptions.hxx>
24 : #include <unotools/useroptions.hxx>
25 : #include <unotools/lingucfg.hxx>
26 : #include <rtl/instance.hxx>
27 : #include <cppuhelper/factory.hxx> // helper for factories
28 : #include <unotools/localfilehelper.hxx>
29 : #include <com/sun/star/linguistic2/XConversionDictionaryList.hpp>
30 : #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
31 : #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
32 : #include <com/sun/star/util/XFlushable.hpp>
33 : #include <com/sun/star/lang/Locale.hpp>
34 : #include <com/sun/star/uno/Reference.h>
35 : #include <com/sun/star/registry/XRegistryKey.hpp>
36 : #include <com/sun/star/container/XNameContainer.hpp>
37 : #include <comphelper/processfactory.hxx>
38 : #include <ucbhelper/content.hxx>
39 :
40 : #include "convdiclist.hxx"
41 : #include "convdic.hxx"
42 : #include "hhconvdic.hxx"
43 : #include "linguistic/misc.hxx"
44 : #include "defs.hxx"
45 :
46 : using namespace osl;
47 : using namespace com::sun::star;
48 : using namespace com::sun::star::lang;
49 : using namespace com::sun::star::uno;
50 : using namespace com::sun::star::container;
51 : using namespace com::sun::star::linguistic2;
52 : using namespace linguistic;
53 :
54 :
55 : #define SN_CONV_DICTIONARY_LIST "com.sun.star.linguistic2.ConversionDictionaryList"
56 :
57 :
58 :
59 0 : bool operator == ( const Locale &r1, const Locale &r2 )
60 : {
61 0 : return r1.Language == r2.Language &&
62 0 : r1.Country == r2.Country &&
63 0 : r1.Variant == r2.Variant;
64 : }
65 :
66 :
67 0 : String GetConvDicMainURL( const String &rDicName, const String &rDirectoryURL )
68 : {
69 : // build URL to use for new (persistent) dictionaries
70 :
71 0 : OUString aFullDicName = OUString(rDicName) + CONV_DIC_DOT_EXT;
72 :
73 0 : INetURLObject aURLObj;
74 0 : aURLObj.SetSmartProtocol( INET_PROT_FILE );
75 0 : aURLObj.SetSmartURL( rDirectoryURL );
76 0 : aURLObj.Append( aFullDicName, INetURLObject::ENCODE_ALL );
77 : DBG_ASSERT(!aURLObj.HasError(), "invalid URL");
78 0 : if (aURLObj.HasError())
79 0 : return String();
80 : else
81 0 : return aURLObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
82 : }
83 :
84 :
85 : class ConvDicNameContainer :
86 : public cppu::WeakImplHelper1
87 : <
88 : ::com::sun::star::container::XNameContainer
89 : >
90 : {
91 : uno::Sequence< uno::Reference< XConversionDictionary > > aConvDics;
92 : ConvDicList &rConvDicList;
93 :
94 : // disallow copy-constructor and assignment-operator for now
95 : ConvDicNameContainer(const ConvDicNameContainer &);
96 : ConvDicNameContainer & operator = (const ConvDicNameContainer &);
97 :
98 : sal_Int32 GetIndexByName_Impl( const OUString& rName );
99 :
100 : public:
101 : ConvDicNameContainer( ConvDicList &rMyConvDicList );
102 : virtual ~ConvDicNameContainer();
103 :
104 : // XElementAccess
105 : virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException);
106 : virtual sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException);
107 :
108 : // XNameAccess
109 : virtual ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
110 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames( ) throw (::com::sun::star::uno::RuntimeException);
111 : virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw (::com::sun::star::uno::RuntimeException);
112 :
113 : // XNameReplace
114 : virtual void SAL_CALL replaceByName( const OUString& aName, const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
115 :
116 : // XNameContainer
117 : virtual void SAL_CALL insertByName( const OUString& aName, const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
118 : virtual void SAL_CALL removeByName( const OUString& Name ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
119 :
120 :
121 : // looks for conversion dictionaries with the specified extension
122 : // in the directory and adds them to the container
123 : void AddConvDics( const String &rSearchDirPathURL, const String &rExtension );
124 :
125 : // calls Flush for the dictionaries that support XFlushable
126 : void FlushDics() const;
127 :
128 0 : sal_Int32 GetCount() const { return aConvDics.getLength(); }
129 : uno::Reference< XConversionDictionary > GetByName( const OUString& rName );
130 :
131 0 : const uno::Reference< XConversionDictionary > GetByIndex( sal_Int32 nIdx )
132 : {
133 0 : return aConvDics.getConstArray()[nIdx];
134 : }
135 : };
136 :
137 :
138 0 : ConvDicNameContainer::ConvDicNameContainer( ConvDicList &rMyConvDicList ) :
139 0 : rConvDicList( rMyConvDicList )
140 : {
141 0 : }
142 :
143 :
144 0 : ConvDicNameContainer::~ConvDicNameContainer()
145 : {
146 0 : }
147 :
148 :
149 0 : void ConvDicNameContainer::FlushDics() const
150 : {
151 0 : sal_Int32 nLen = aConvDics.getLength();
152 0 : const uno::Reference< XConversionDictionary > *pDic = aConvDics.getConstArray();
153 0 : for (sal_Int32 i = 0; i < nLen; ++i)
154 : {
155 0 : uno::Reference< util::XFlushable > xFlush( pDic[i] , UNO_QUERY );
156 0 : if (xFlush.is())
157 : {
158 : try
159 : {
160 0 : xFlush->flush();
161 : }
162 0 : catch(Exception &)
163 : {
164 : OSL_FAIL( "flushing of conversion dictionary failed" );
165 : }
166 : }
167 0 : }
168 0 : }
169 :
170 :
171 0 : sal_Int32 ConvDicNameContainer::GetIndexByName_Impl(
172 : const OUString& rName )
173 : {
174 0 : sal_Int32 nRes = -1;
175 0 : sal_Int32 nLen = aConvDics.getLength();
176 0 : const uno::Reference< XConversionDictionary > *pDic = aConvDics.getConstArray();
177 0 : for (sal_Int32 i = 0; i < nLen && nRes == -1; ++i)
178 : {
179 0 : if (rName == pDic[i]->getName())
180 0 : nRes = i;
181 : }
182 0 : return nRes;
183 : }
184 :
185 :
186 0 : uno::Reference< XConversionDictionary > ConvDicNameContainer::GetByName(
187 : const OUString& rName )
188 : {
189 0 : uno::Reference< XConversionDictionary > xRes;
190 0 : sal_Int32 nIdx = GetIndexByName_Impl( rName );
191 0 : if ( nIdx != -1)
192 0 : xRes = aConvDics.getArray()[nIdx];
193 0 : return xRes;
194 : }
195 :
196 :
197 0 : uno::Type SAL_CALL ConvDicNameContainer::getElementType( )
198 : throw (RuntimeException)
199 : {
200 0 : MutexGuard aGuard( GetLinguMutex() );
201 0 : return uno::Type( ::getCppuType( (uno::Reference< XConversionDictionary > *) 0) );
202 : }
203 :
204 :
205 0 : sal_Bool SAL_CALL ConvDicNameContainer::hasElements( )
206 : throw (RuntimeException)
207 : {
208 0 : MutexGuard aGuard( GetLinguMutex() );
209 0 : return aConvDics.getLength() > 0;
210 : }
211 :
212 :
213 0 : uno::Any SAL_CALL ConvDicNameContainer::getByName( const OUString& rName )
214 : throw (NoSuchElementException, WrappedTargetException, RuntimeException)
215 : {
216 0 : MutexGuard aGuard( GetLinguMutex() );
217 0 : uno::Reference< XConversionDictionary > xRes( GetByName( rName ) );
218 0 : if (!xRes.is())
219 0 : throw NoSuchElementException();
220 0 : return makeAny( xRes );
221 : }
222 :
223 :
224 0 : uno::Sequence< OUString > SAL_CALL ConvDicNameContainer::getElementNames( )
225 : throw (RuntimeException)
226 : {
227 0 : MutexGuard aGuard( GetLinguMutex() );
228 :
229 0 : sal_Int32 nLen = aConvDics.getLength();
230 0 : uno::Sequence< OUString > aRes( nLen );
231 0 : OUString *pName = aRes.getArray();
232 0 : const uno::Reference< XConversionDictionary > *pDic = aConvDics.getConstArray();
233 0 : for (sal_Int32 i = 0; i < nLen; ++i)
234 0 : pName[i] = pDic[i]->getName();
235 0 : return aRes;
236 : }
237 :
238 :
239 0 : sal_Bool SAL_CALL ConvDicNameContainer::hasByName( const OUString& rName )
240 : throw (RuntimeException)
241 : {
242 0 : MutexGuard aGuard( GetLinguMutex() );
243 0 : return GetByName( rName ).is();
244 : }
245 :
246 :
247 0 : void SAL_CALL ConvDicNameContainer::replaceByName(
248 : const OUString& rName,
249 : const uno::Any& rElement )
250 : throw (IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
251 : {
252 0 : MutexGuard aGuard( GetLinguMutex() );
253 :
254 0 : sal_Int32 nRplcIdx = GetIndexByName_Impl( rName );
255 0 : if (nRplcIdx == -1)
256 0 : throw NoSuchElementException();
257 0 : uno::Reference< XConversionDictionary > xNew;
258 0 : rElement >>= xNew;
259 0 : if (!xNew.is() || xNew->getName() != rName)
260 0 : throw IllegalArgumentException();
261 0 : aConvDics.getArray()[ nRplcIdx ] = xNew;
262 0 : }
263 :
264 :
265 0 : void SAL_CALL ConvDicNameContainer::insertByName(
266 : const OUString& rName,
267 : const Any& rElement )
268 : throw (IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
269 : {
270 0 : MutexGuard aGuard( GetLinguMutex() );
271 :
272 0 : if (GetByName( rName ).is())
273 0 : throw ElementExistException();
274 0 : uno::Reference< XConversionDictionary > xNew;
275 0 : rElement >>= xNew;
276 0 : if (!xNew.is() || xNew->getName() != rName)
277 0 : throw IllegalArgumentException();
278 :
279 0 : sal_Int32 nLen = aConvDics.getLength();
280 0 : aConvDics.realloc( nLen + 1 );
281 0 : aConvDics.getArray()[ nLen ] = xNew;
282 0 : }
283 :
284 :
285 0 : void SAL_CALL ConvDicNameContainer::removeByName( const OUString& rName )
286 : throw (NoSuchElementException, WrappedTargetException, RuntimeException)
287 : {
288 0 : MutexGuard aGuard( GetLinguMutex() );
289 :
290 0 : sal_Int32 nRplcIdx = GetIndexByName_Impl( rName );
291 0 : if (nRplcIdx == -1)
292 0 : throw NoSuchElementException();
293 :
294 : // physically remove dictionary
295 0 : uno::Reference< XConversionDictionary > xDel = aConvDics.getArray()[nRplcIdx];
296 0 : String aName( xDel->getName() );
297 0 : String aDicMainURL( GetConvDicMainURL( aName, GetDictionaryWriteablePath() ) );
298 0 : INetURLObject aObj( aDicMainURL );
299 : DBG_ASSERT( aObj.GetProtocol() == INET_PROT_FILE, "+HangulHanjaOptionsDialog::OkHdl(): non-file URLs cannot be deleted" );
300 0 : if( aObj.GetProtocol() == INET_PROT_FILE )
301 : {
302 : try
303 : {
304 : ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ),
305 : uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(),
306 0 : comphelper::getProcessComponentContext() );
307 0 : aCnt.executeCommand( "delete", makeAny( sal_Bool( sal_True ) ) );
308 : }
309 0 : catch( ::com::sun::star::ucb::CommandAbortedException& )
310 : {
311 : SAL_WARN( "linguistic", "HangulHanjaOptionsDialog::OkHdl(): CommandAbortedException" );
312 : }
313 0 : catch( ... )
314 : {
315 : SAL_WARN( "linguistic", "HangulHanjaOptionsDialog::OkHdl(): Any other exception" );
316 : }
317 : }
318 :
319 0 : sal_Int32 nLen = aConvDics.getLength();
320 0 : uno::Reference< XConversionDictionary > *pDic = aConvDics.getArray();
321 0 : for (sal_Int32 i = nRplcIdx; i < nLen - 1; ++i)
322 0 : pDic[i] = pDic[i + 1];
323 0 : aConvDics.realloc( nLen - 1 );
324 0 : }
325 :
326 :
327 0 : void ConvDicNameContainer::AddConvDics(
328 : const String &rSearchDirPathURL,
329 : const String &rExtension )
330 : {
331 : const Sequence< OUString > aDirCnt(
332 0 : utl::LocalFileHelper::GetFolderContents( rSearchDirPathURL, sal_False ) );
333 0 : const OUString *pDirCnt = aDirCnt.getConstArray();
334 0 : sal_Int32 nEntries = aDirCnt.getLength();
335 :
336 0 : for (sal_Int32 i = 0; i < nEntries; ++i)
337 : {
338 0 : String aURL( pDirCnt[i] );
339 :
340 0 : xub_StrLen nPos = aURL.SearchBackward('.');
341 0 : String aExt(aURL.Copy(nPos + 1));
342 0 : aExt.ToLowerAscii();
343 0 : String aSearchExt( rExtension );
344 0 : aSearchExt.ToLowerAscii();
345 0 : if(aExt != aSearchExt)
346 0 : continue; // skip other files
347 :
348 : sal_Int16 nLang;
349 : sal_Int16 nConvType;
350 0 : if (IsConvDic( aURL, nLang, nConvType ))
351 : {
352 : // get decoded dictionary file name
353 0 : INetURLObject aURLObj( aURL );
354 : String aDicName = aURLObj.getBase( INetURLObject::LAST_SEGMENT,
355 : true, INetURLObject::DECODE_WITH_CHARSET,
356 0 : RTL_TEXTENCODING_UTF8 );
357 :
358 0 : uno::Reference < XConversionDictionary > xDic;
359 0 : if (nLang == LANGUAGE_KOREAN &&
360 0 : nConvType == ConversionDictionaryType::HANGUL_HANJA)
361 : {
362 0 : xDic = new HHConvDic( aDicName, aURL );
363 : }
364 0 : else if ((nLang == LANGUAGE_CHINESE_SIMPLIFIED || nLang == LANGUAGE_CHINESE_TRADITIONAL) &&
365 0 : nConvType == ConversionDictionaryType::SCHINESE_TCHINESE)
366 : {
367 0 : xDic = new ConvDic( aDicName, nLang, nConvType, sal_False, aURL );
368 : }
369 :
370 0 : if (xDic.is())
371 : {
372 0 : uno::Any aAny;
373 0 : aAny <<= xDic;
374 0 : insertByName( xDic->getName(), aAny );
375 0 : }
376 : }
377 0 : }
378 0 : }
379 :
380 :
381 : namespace
382 : {
383 : struct StaticConvDicList : public rtl::StaticWithInit<
384 : uno::Reference<XInterface>, StaticConvDicList> {
385 0 : uno::Reference<XInterface> operator () () {
386 0 : return (cppu::OWeakObject *) new ConvDicList;
387 : }
388 : };
389 : }
390 :
391 :
392 0 : void ConvDicList::MyAppExitListener::AtExit()
393 : {
394 0 : rMyDicList.FlushDics();
395 0 : StaticConvDicList::get().clear();
396 0 : }
397 :
398 0 : ConvDicList::ConvDicList() :
399 0 : aEvtListeners( GetLinguMutex() )
400 : {
401 0 : pNameContainer = 0;
402 0 : bDisposing = sal_False;
403 :
404 0 : pExitListener = new MyAppExitListener( *this );
405 0 : xExitListener = pExitListener;
406 0 : pExitListener->Activate();
407 0 : }
408 :
409 :
410 0 : ConvDicList::~ConvDicList()
411 : {
412 :
413 0 : if (!bDisposing && pNameContainer)
414 0 : pNameContainer->FlushDics();
415 :
416 0 : pExitListener->Deactivate();
417 0 : }
418 :
419 :
420 0 : void ConvDicList::FlushDics()
421 : {
422 : // check only pointer to avoid creating the container when
423 : // the dictionaries were not accessed yet
424 0 : if (pNameContainer)
425 0 : pNameContainer->FlushDics();
426 0 : }
427 :
428 :
429 0 : ConvDicNameContainer & ConvDicList::GetNameContainer()
430 : {
431 0 : if (!pNameContainer)
432 : {
433 0 : pNameContainer = new ConvDicNameContainer( *this );
434 0 : pNameContainer->AddConvDics( GetDictionaryWriteablePath(), OUString(CONV_DIC_EXT) );
435 0 : xNameContainer = pNameContainer;
436 :
437 : // access list of text conversion dictionaries to activate
438 0 : SvtLinguOptions aOpt;
439 0 : SvtLinguConfig().GetOptions( aOpt );
440 0 : sal_Int32 nLen = aOpt.aActiveConvDics.getLength();
441 0 : const OUString *pActiveConvDics = aOpt.aActiveConvDics.getConstArray();
442 0 : for (sal_Int32 i = 0; i < nLen; ++i)
443 : {
444 : uno::Reference< XConversionDictionary > xDic =
445 0 : pNameContainer->GetByName( pActiveConvDics[i] );
446 0 : if (xDic.is())
447 0 : xDic->setActive( sal_True );
448 0 : }
449 :
450 : // since there is no UI to active/deactivate the dictionaries
451 : // for chinese text conversion they should be activated by default
452 : uno::Reference< XConversionDictionary > xS2TDic(
453 0 : pNameContainer->GetByName( "ChineseS2T" ), UNO_QUERY );
454 : uno::Reference< XConversionDictionary > xT2SDic(
455 0 : pNameContainer->GetByName( "ChineseT2S" ), UNO_QUERY );
456 0 : if (xS2TDic.is())
457 0 : xS2TDic->setActive( sal_True );
458 0 : if (xT2SDic.is())
459 0 : xT2SDic->setActive( sal_True );
460 :
461 : }
462 0 : return *pNameContainer;
463 : }
464 :
465 :
466 0 : uno::Reference< container::XNameContainer > SAL_CALL ConvDicList::getDictionaryContainer( ) throw (RuntimeException)
467 : {
468 0 : MutexGuard aGuard( GetLinguMutex() );
469 0 : GetNameContainer();
470 : DBG_ASSERT( xNameContainer.is(), "missing name container" );
471 0 : return xNameContainer;
472 : }
473 :
474 :
475 0 : uno::Reference< XConversionDictionary > SAL_CALL ConvDicList::addNewDictionary(
476 : const OUString& rName,
477 : const Locale& rLocale,
478 : sal_Int16 nConvDicType )
479 : throw (NoSupportException, ElementExistException, RuntimeException)
480 : {
481 0 : MutexGuard aGuard( GetLinguMutex() );
482 :
483 0 : sal_Int16 nLang = LinguLocaleToLanguage( rLocale );
484 :
485 0 : if (GetNameContainer().hasByName( rName ))
486 0 : throw ElementExistException();
487 :
488 0 : uno::Reference< XConversionDictionary > xRes;
489 0 : String aDicMainURL( GetConvDicMainURL( rName, GetDictionaryWriteablePath() ) );
490 0 : if (nLang == LANGUAGE_KOREAN &&
491 : nConvDicType == ConversionDictionaryType::HANGUL_HANJA)
492 : {
493 0 : xRes = new HHConvDic( rName, aDicMainURL );
494 : }
495 0 : else if ((nLang == LANGUAGE_CHINESE_SIMPLIFIED || nLang == LANGUAGE_CHINESE_TRADITIONAL) &&
496 : nConvDicType == ConversionDictionaryType::SCHINESE_TCHINESE)
497 : {
498 0 : xRes = new ConvDic( rName, nLang, nConvDicType, sal_False, aDicMainURL );
499 : }
500 :
501 0 : if (!xRes.is())
502 0 : throw NoSupportException();
503 : else
504 : {
505 0 : xRes->setActive( sal_True );
506 0 : uno::Any aAny;
507 0 : aAny <<= xRes;
508 0 : GetNameContainer().insertByName( rName, aAny );
509 : }
510 0 : return xRes;
511 : }
512 :
513 :
514 0 : uno::Sequence< OUString > SAL_CALL ConvDicList::queryConversions(
515 : const OUString& rText,
516 : sal_Int32 nStartPos,
517 : sal_Int32 nLength,
518 : const Locale& rLocale,
519 : sal_Int16 nConversionDictionaryType,
520 : ConversionDirection eDirection,
521 : sal_Int32 nTextConversionOptions )
522 : throw (IllegalArgumentException, NoSupportException, RuntimeException)
523 : {
524 0 : MutexGuard aGuard( GetLinguMutex() );
525 :
526 0 : sal_Int32 nCount = 0;
527 0 : uno::Sequence< OUString > aRes( 20 );
528 0 : OUString *pRes = aRes.getArray();
529 :
530 0 : sal_Bool bSupported = sal_False;
531 0 : sal_Int32 nLen = GetNameContainer().GetCount();
532 0 : for (sal_Int32 i = 0; i < nLen; ++i)
533 : {
534 0 : const uno::Reference< XConversionDictionary > xDic( GetNameContainer().GetByIndex(i) );
535 0 : sal_Bool bMatch = xDic.is() &&
536 0 : xDic->getLocale() == rLocale &&
537 0 : xDic->getConversionType() == nConversionDictionaryType;
538 0 : bSupported |= bMatch;
539 0 : if (bMatch && xDic->isActive())
540 : {
541 0 : Sequence< OUString > aNewConv( xDic->getConversions(
542 : rText, nStartPos, nLength,
543 0 : eDirection, nTextConversionOptions ) );
544 0 : sal_Int32 nNewLen = aNewConv.getLength();
545 0 : if (nNewLen > 0)
546 : {
547 0 : if (nCount + nNewLen > aRes.getLength())
548 : {
549 0 : aRes.realloc( nCount + nNewLen + 20 );
550 0 : pRes = aRes.getArray();
551 : }
552 0 : const OUString *pNewConv = aNewConv.getConstArray();
553 0 : for (sal_Int32 k = 0; k < nNewLen; ++k)
554 0 : pRes[nCount++] = pNewConv[k];
555 0 : }
556 : }
557 0 : }
558 :
559 0 : if (!bSupported)
560 0 : throw NoSupportException();
561 :
562 0 : aRes.realloc( nCount );
563 0 : return aRes;
564 : }
565 :
566 :
567 0 : sal_Int16 SAL_CALL ConvDicList::queryMaxCharCount(
568 : const Locale& rLocale,
569 : sal_Int16 nConversionDictionaryType,
570 : ConversionDirection eDirection )
571 : throw (RuntimeException)
572 : {
573 0 : MutexGuard aGuard( GetLinguMutex() );
574 :
575 0 : sal_Int16 nRes = 0;
576 0 : GetNameContainer();
577 0 : sal_Int32 nLen = GetNameContainer().GetCount();
578 0 : for (sal_Int32 i = 0; i < nLen; ++i)
579 : {
580 0 : const uno::Reference< XConversionDictionary > xDic( GetNameContainer().GetByIndex(i) );
581 0 : if (xDic.is() &&
582 0 : xDic->getLocale() == rLocale &&
583 0 : xDic->getConversionType() == nConversionDictionaryType)
584 : {
585 0 : sal_Int16 nC = xDic->getMaxCharCount( eDirection );
586 0 : if (nC > nRes)
587 0 : nRes = nC;
588 : }
589 0 : }
590 0 : return nRes;
591 : }
592 :
593 :
594 0 : void SAL_CALL ConvDicList::dispose( )
595 : throw (RuntimeException)
596 : {
597 0 : MutexGuard aGuard( GetLinguMutex() );
598 0 : if (!bDisposing)
599 : {
600 0 : bDisposing = sal_True;
601 0 : EventObject aEvtObj( (XConversionDictionaryList *) this );
602 0 : aEvtListeners.disposeAndClear( aEvtObj );
603 :
604 0 : FlushDics();
605 0 : }
606 0 : }
607 :
608 :
609 0 : void SAL_CALL ConvDicList::addEventListener(
610 : const uno::Reference< XEventListener >& rxListener )
611 : throw (RuntimeException)
612 : {
613 0 : MutexGuard aGuard( GetLinguMutex() );
614 0 : if (!bDisposing && rxListener.is())
615 0 : aEvtListeners.addInterface( rxListener );
616 0 : }
617 :
618 :
619 0 : void SAL_CALL ConvDicList::removeEventListener(
620 : const uno::Reference< XEventListener >& rxListener )
621 : throw (RuntimeException)
622 : {
623 0 : MutexGuard aGuard( GetLinguMutex() );
624 0 : if (!bDisposing && rxListener.is())
625 0 : aEvtListeners.removeInterface( rxListener );
626 0 : }
627 :
628 :
629 0 : OUString SAL_CALL ConvDicList::getImplementationName( )
630 : throw (RuntimeException)
631 : {
632 0 : MutexGuard aGuard( GetLinguMutex() );
633 0 : return getImplementationName_Static();
634 : }
635 :
636 :
637 0 : sal_Bool SAL_CALL ConvDicList::supportsService( const OUString& rServiceName )
638 : throw (RuntimeException)
639 : {
640 0 : MutexGuard aGuard( GetLinguMutex() );
641 0 : return rServiceName == SN_CONV_DICTIONARY_LIST;
642 : }
643 :
644 :
645 0 : uno::Sequence< OUString > SAL_CALL ConvDicList::getSupportedServiceNames( )
646 : throw (RuntimeException)
647 : {
648 0 : MutexGuard aGuard( GetLinguMutex() );
649 0 : return getSupportedServiceNames_Static();
650 : }
651 :
652 :
653 0 : uno::Sequence< OUString > ConvDicList::getSupportedServiceNames_Static()
654 : throw()
655 : {
656 0 : uno::Sequence< OUString > aSNS( 1 );
657 0 : aSNS.getArray()[0] = SN_CONV_DICTIONARY_LIST;
658 0 : return aSNS;
659 : }
660 :
661 :
662 :
663 0 : uno::Reference< uno::XInterface > SAL_CALL ConvDicList_CreateInstance(
664 : const uno::Reference< XMultiServiceFactory > & /*rSMgr*/ )
665 : throw(Exception)
666 : {
667 0 : return StaticConvDicList::get();
668 : }
669 :
670 0 : void * SAL_CALL ConvDicList_getFactory(
671 : const sal_Char * pImplName,
672 : XMultiServiceFactory * pServiceManager, void * )
673 : {
674 0 : void * pRet = 0;
675 0 : if ( !ConvDicList::getImplementationName_Static().compareToAscii( pImplName ) )
676 : {
677 : uno::Reference< XSingleServiceFactory > xFactory =
678 : cppu::createOneInstanceFactory(
679 : pServiceManager,
680 : ConvDicList::getImplementationName_Static(),
681 : ConvDicList_CreateInstance,
682 0 : ConvDicList::getSupportedServiceNames_Static());
683 : // acquire, because we return an interface pointer instead of a reference
684 0 : xFactory->acquire();
685 0 : pRet = xFactory.get();
686 : }
687 0 : return pRet;
688 : }
689 :
690 :
691 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|