LCOV - code coverage report
Current view: top level - linguistic/source - misc2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 52 62 83.9 %
Date: 2012-08-25 Functions: 4 5 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 70 158 44.3 %

           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                 :            : #include <tools/string.hxx>
      30                 :            : #include <tools/fsys.hxx>
      31                 :            : #include <tools/urlobj.hxx>
      32                 :            : #include <ucbhelper/content.hxx>
      33                 :            : #include <tools/debug.hxx>
      34                 :            : #include <unotools/pathoptions.hxx>
      35                 :            : #include <comphelper/processfactory.hxx>
      36                 :            : #include <unotools/localfilehelper.hxx>
      37                 :            : #include <unotools/localedatawrapper.hxx>
      38                 :            : #include <unotools/ucbhelper.hxx>
      39                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      40                 :            : #include <com/sun/star/beans/XFastPropertySet.hpp>
      41                 :            : 
      42                 :            : #include <com/sun/star/beans/PropertyValues.hpp>
      43                 :            : #include <com/sun/star/uno/Sequence.hxx>
      44                 :            : #include <com/sun/star/uno/Reference.h>
      45                 :            : 
      46                 :            : #include "linguistic/misc.hxx"
      47                 :            : 
      48                 :            : using namespace com::sun::star;
      49                 :            : 
      50                 :            : namespace linguistic
      51                 :            : {
      52                 :            : 
      53                 :            : 
      54                 :        168 : sal_Bool FileExists( const String &rMainURL )
      55                 :            : {
      56                 :        168 :     sal_Bool bExists = sal_False;
      57         [ +  - ]:        168 :     if (rMainURL.Len())
      58                 :            :     {
      59                 :            :         try
      60                 :            :         {
      61                 :            :             ::ucbhelper::Content aContent( rMainURL,
      62 [ +  - ][ +  - ]:        168 :                     uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >());
      63 [ +  - ][ #  # ]:        168 :             bExists = aContent.isDocument();
                 [ +  - ]
      64                 :            :         }
      65                 :          0 :         catch (uno::Exception &)
      66                 :            :         {
      67                 :            :         }
      68                 :            :     }
      69                 :        168 :     return bExists;
      70                 :            : }
      71                 :            : 
      72                 :        140 : static uno::Sequence< rtl::OUString > GetMultiPaths_Impl(
      73                 :            :     const rtl::OUString &rPathPrefix,
      74                 :            :     sal_Int16 nPathFlags )
      75                 :            : {
      76         [ +  - ]:        140 :     uno::Sequence< rtl::OUString >   aRes;
      77         [ +  - ]:        140 :     uno::Sequence< rtl::OUString >   aInternalPaths;
      78         [ +  - ]:        140 :     uno::Sequence< rtl::OUString >   aUserPaths;
      79                 :        140 :     rtl::OUString                    aWritablePath;
      80                 :            : 
      81                 :        140 :     bool bSuccess = true;
      82         [ +  - ]:        140 :     uno::Reference< lang::XMultiServiceFactory >  xMgr( comphelper::getProcessServiceFactory() );
      83         [ +  - ]:        140 :     if (xMgr.is())
      84                 :            :     {
      85                 :            :         try
      86                 :            :         {
      87         [ +  - ]:        140 :             String aInternal( rPathPrefix );
      88         [ +  - ]:        140 :             String aUser( rPathPrefix );
      89         [ +  - ]:        140 :             String aWriteable( rPathPrefix );
      90         [ +  - ]:        140 :             aInternal .AppendAscii( "_internal" );
      91         [ +  - ]:        140 :             aUser     .AppendAscii( "_user" );
      92         [ +  - ]:        140 :             aWriteable.AppendAscii( "_writable" );
      93                 :            : 
      94         [ +  - ]:        140 :             uno::Reference< beans::XPropertySet > xPathSettings( xMgr->createInstance(
      95 [ +  - ][ +  - ]:        140 :                     A2OU( "com.sun.star.util.PathSettings" ) ), uno::UNO_QUERY_THROW );
                 [ +  - ]
      96 [ +  - ][ +  - ]:        140 :             xPathSettings->getPropertyValue( aInternal )  >>= aInternalPaths;
         [ +  - ][ +  - ]
      97 [ +  - ][ +  - ]:        140 :             xPathSettings->getPropertyValue( aUser )      >>= aUserPaths;
         [ +  - ][ +  - ]
      98 [ +  - ][ +  - ]:        140 :             xPathSettings->getPropertyValue( aWriteable ) >>= aWritablePath;
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
                 [ +  - ]
      99                 :            :         }
     100         [ #  # ]:          0 :         catch (uno::Exception &)
     101                 :            :         {
     102                 :          0 :             bSuccess = false;
     103                 :            :         }
     104                 :            :     }
     105         [ +  - ]:        140 :     if (bSuccess)
     106                 :            :     {
     107                 :            :         // build resulting sequence by adding the paths in the following order:
     108                 :            :         // 1. writable path
     109                 :            :         // 2. all user paths
     110                 :            :         // 3. all internal paths
     111                 :        140 :         sal_Int32 nMaxEntries = aInternalPaths.getLength() + aUserPaths.getLength();
     112         [ +  - ]:        140 :         if (!aWritablePath.isEmpty())
     113                 :        140 :             ++nMaxEntries;
     114         [ +  - ]:        140 :         aRes.realloc( nMaxEntries );
     115         [ +  - ]:        140 :         rtl::OUString *pRes = aRes.getArray();
     116                 :        140 :         sal_Int32 nCount = 0;   // number of actually added entries
     117 [ +  - ][ +  - ]:        140 :         if ((nPathFlags & PATH_FLAG_WRITABLE) && !aWritablePath.isEmpty())
                 [ +  - ]
     118                 :        140 :             pRes[ nCount++ ] = aWritablePath;
     119         [ +  + ]:        420 :         for (int i = 0;  i < 2;  ++i)
     120                 :            :         {
     121         [ +  + ]:        280 :             const uno::Sequence< rtl::OUString > &rPathSeq = i == 0 ? aUserPaths : aInternalPaths;
     122                 :        280 :             const rtl::OUString *pPathSeq = rPathSeq.getConstArray();
     123         [ +  + ]:        420 :             for (sal_Int32 k = 0;  k < rPathSeq.getLength();  ++k)
     124                 :            :             {
     125 [ -  + ][ #  # ]:        140 :                 const bool bAddUser     = &rPathSeq == &aUserPaths     && (nPathFlags & PATH_FLAG_USER);
     126 [ +  - ][ +  + ]:        140 :                 const bool bAddInternal = &rPathSeq == &aInternalPaths && (nPathFlags & PATH_FLAG_INTERNAL);
     127 [ +  - ][ +  + ]:        140 :                 if ((bAddUser || bAddInternal) && !pPathSeq[k].isEmpty())
         [ +  - ][ +  + ]
     128                 :         42 :                     pRes[ nCount++ ] = pPathSeq[k];
     129                 :            :             }
     130                 :            :         }
     131         [ +  - ]:        140 :         aRes.realloc( nCount );
     132                 :            :     }
     133                 :            : 
     134 [ +  - ][ +  - ]:        140 :     return aRes;
     135                 :            : }
     136                 :            : 
     137                 :         98 : rtl::OUString GetDictionaryWriteablePath()
     138                 :            : {
     139 [ +  - ][ +  - ]:         98 :     uno::Sequence< rtl::OUString > aPaths( GetMultiPaths_Impl( A2OU("Dictionary"), PATH_FLAG_WRITABLE ) );
     140                 :            :     DBG_ASSERT( aPaths.getLength() == 1, "Dictionary_writable path corrupted?" );
     141         [ +  - ]:         98 :     String aRes;
     142         [ +  - ]:         98 :     if (aPaths.getLength() > 0)
     143 [ +  - ][ +  - ]:         98 :         aRes = aPaths[0];
     144 [ +  - ][ +  - ]:         98 :     return aRes;
                 [ +  - ]
     145                 :            : }
     146                 :            : 
     147                 :         42 : uno::Sequence< rtl::OUString > GetDictionaryPaths( sal_Int16 nPathFlags )
     148                 :            : {
     149         [ +  - ]:         42 :     return GetMultiPaths_Impl( A2OU("Dictionary"), nPathFlags );
     150                 :            : }
     151                 :            : 
     152                 :          0 : String  GetWritableDictionaryURL( const String &rDicName )
     153                 :            : {
     154                 :            :     // new user writable dictionaries should be created in the 'writable' path
     155 [ #  # ][ #  # ]:          0 :     String aDirName( GetDictionaryWriteablePath() );
     156                 :            : 
     157                 :            :     // build URL to use for a new (persistent) dictionary
     158         [ #  # ]:          0 :     INetURLObject aURLObj;
     159                 :          0 :     aURLObj.SetSmartProtocol( INET_PROT_FILE );
     160 [ #  # ][ #  # ]:          0 :     aURLObj.SetSmartURL( aDirName );
     161                 :            :     DBG_ASSERT(!aURLObj.HasError(), "lng : invalid URL");
     162 [ #  # ][ #  # ]:          0 :     aURLObj.Append( rDicName, INetURLObject::ENCODE_ALL );
     163                 :            :     DBG_ASSERT(!aURLObj.HasError(), "lng : invalid URL");
     164                 :            : 
     165                 :            :     // NO_DECODE preserves the escape sequences that might be included in aDirName
     166                 :            :     // depending on the characters used in the path string. (Needed when comparing
     167                 :            :     // the dictionary URL with GetDictionaryWriteablePath in DicList::createDictionary.)
     168 [ #  # ][ #  # ]:          0 :     return aURLObj.GetMainURL( INetURLObject::NO_DECODE );
         [ #  # ][ #  # ]
     169                 :            : }
     170                 :            : 
     171                 :            : }   // namespace linguistic
     172                 :            : 
     173                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10