LCOV - code coverage report
Current view: top level - linguistic/source - convdiclist.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 290 0.0 %
Date: 2014-04-14 Functions: 0 39 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10