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