LCOV - code coverage report
Current view: top level - linguistic/source - convdiclist.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 4 293 1.4 %
Date: 2012-08-25 Functions: 1 39 2.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 700 0.1 %

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

Generated by: LCOV version 1.10