LCOV - code coverage report
Current view: top level - libreoffice/unotools/source/config - pathoptions.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 113 375 30.1 %
Date: 2012-12-27 Functions: 30 115 26.1 %
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 <unotools/pathoptions.hxx>
      21             : #include <unotools/configitem.hxx>
      22             : #include <unotools/configmgr.hxx>
      23             : #include <tools/urlobj.hxx>
      24             : #include <com/sun/star/uno/Any.hxx>
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : #include <osl/mutex.hxx>
      27             : #include <osl/file.hxx>
      28             : #include <unotools/localfilehelper.hxx>
      29             : #include <unotools/bootstrap.hxx>
      30             : 
      31             : #include <unotools/ucbhelper.hxx>
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <comphelper/componentcontext.hxx>
      34             : #include <com/sun/star/beans/XFastPropertySet.hpp>
      35             : #include <com/sun/star/beans/XPropertySet.hpp>
      36             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      37             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      38             : #include <com/sun/star/util/PathSubstitution.hpp>
      39             : #include <com/sun/star/util/XStringSubstitution.hpp>
      40             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      41             : #include <com/sun/star/util/XMacroExpander.hpp>
      42             : #include <rtl/instance.hxx>
      43             : 
      44             : #include <itemholder1.hxx>
      45             : 
      46             : #include <vector>
      47             : #include <boost/unordered_map.hpp>
      48             : 
      49             : using namespace osl;
      50             : using namespace utl;
      51             : using namespace com::sun::star::uno;
      52             : using namespace com::sun::star::beans;
      53             : using namespace com::sun::star::util;
      54             : using namespace com::sun::star::lang;
      55             : 
      56             : using ::rtl::OUString;
      57             : using ::rtl::OString;
      58             : using ::rtl::OStringToOUString;
      59             : 
      60             : #define SEARCHPATH_DELIMITER  ';'
      61             : #define SIGN_STARTVARIABLE    OUString( "$("  )
      62             : #define SIGN_ENDVARIABLE      OUString( ")" )
      63             : 
      64             : // Supported variables by the old SvtPathOptions implementation
      65             : #define SUBSTITUTE_INSTPATH   "$(instpath)"
      66             : #define SUBSTITUTE_PROGPATH   "$(progpath)"
      67             : #define SUBSTITUTE_USERPATH   "$(userpath)"
      68             : #define SUBSTITUTE_PATH       "$(path)"
      69             : 
      70             : #define STRPOS_NOTFOUND       -1
      71             : 
      72             : struct OUStringHashCode
      73             : {
      74           0 :     size_t operator()( const ::rtl::OUString& sString ) const
      75             :     {
      76           0 :         return sString.hashCode();
      77             :     }
      78             : };
      79             : 
      80             : enum VarNameProperty
      81             : {
      82             :     VAR_NEEDS_SYSTEM_PATH,
      83             :     VAR_NEEDS_FILEURL
      84             : };
      85             : 
      86          38 : class NameToHandleMap : public ::boost::unordered_map<  ::rtl::OUString, sal_Int32, OUStringHashCode, ::std::equal_to< ::rtl::OUString > >
      87             : {
      88             :     public:
      89             :         inline void free() { NameToHandleMap().swap( *this ); }
      90             : };
      91             : 
      92          38 : class EnumToHandleMap : public ::boost::unordered_map< sal_Int32, sal_Int32, boost::hash< sal_Int32 >, std::equal_to< sal_Int32 > >
      93             : {
      94             :     public:
      95             :         inline void free() { EnumToHandleMap().swap( *this ); }
      96             : };
      97             : 
      98          38 : class VarNameToEnumMap : public ::boost::unordered_map< OUString, VarNameProperty, OUStringHashCode, ::std::equal_to< OUString > >
      99             : {
     100             :     public:
     101             :         inline void free() { VarNameToEnumMap().swap( *this ); }
     102             : };
     103             : 
     104             : 
     105             : // class SvtPathOptions_Impl ---------------------------------------------
     106          19 : class SvtPathOptions_Impl
     107             : {
     108             :     private:
     109             :         // Local variables to return const references
     110             :         std::vector< String >               m_aPathArray;
     111             :         Reference< XFastPropertySet >       m_xPathSettings;
     112             :         Reference< XStringSubstitution >    m_xSubstVariables;
     113             :         Reference< XMacroExpander >         m_xMacroExpander;
     114             :         mutable EnumToHandleMap             m_aMapEnumToPropHandle;
     115             :         VarNameToEnumMap                    m_aMapVarNamesToEnum;
     116             : 
     117             :         ::com::sun::star::lang::Locale      m_aLocale;
     118             :         String                              m_aEmptyString;
     119             :         mutable ::osl::Mutex                m_aMutex;
     120             : 
     121             :     public:
     122             :                         SvtPathOptions_Impl();
     123             : 
     124             :         // get the paths, not const because of using a mutex
     125             :         const String&   GetPath( SvtPathOptions::Paths );
     126          36 :         const String&   GetAddinPath() { return GetPath( SvtPathOptions::PATH_ADDIN ); }
     127          10 :         const String&   GetAutoCorrectPath() { return GetPath( SvtPathOptions::PATH_AUTOCORRECT ); }
     128           0 :         const String&   GetAutoTextPath() { return GetPath( SvtPathOptions::PATH_AUTOTEXT ); }
     129          59 :         const String&   GetBackupPath() { return GetPath( SvtPathOptions::PATH_BACKUP ); }
     130         929 :         const String&   GetBasicPath() { return GetPath( SvtPathOptions::PATH_BASIC ); }
     131           0 :         const String&   GetBitmapPath() { return GetPath( SvtPathOptions::PATH_BITMAP ); }
     132          19 :         const String&   GetConfigPath() { return GetPath( SvtPathOptions::PATH_CONFIG ); }
     133           0 :         const String&   GetDictionaryPath() { return GetPath( SvtPathOptions::PATH_DICTIONARY ); }
     134           0 :         const String&   GetFavoritesPath() { return GetPath( SvtPathOptions::PATH_FAVORITES ); }
     135           0 :         const String&   GetFilterPath() { return GetPath( SvtPathOptions::PATH_FILTER ); }
     136           0 :         const String&   GetGalleryPath() { return GetPath( SvtPathOptions::PATH_GALLERY ); }
     137           0 :         const String&   GetGraphicPath() { return GetPath( SvtPathOptions::PATH_GRAPHIC ); }
     138           0 :         const String&   GetHelpPath() { return GetPath( SvtPathOptions::PATH_HELP ); }
     139           0 :         const String&   GetLinguisticPath() { return GetPath( SvtPathOptions::PATH_LINGUISTIC ); }
     140           0 :         const String&   GetModulePath() { return GetPath( SvtPathOptions::PATH_MODULE ); }
     141         375 :         const String&   GetPalettePath() { return GetPath( SvtPathOptions::PATH_PALETTE ); }
     142           0 :         const String&   GetPluginPath() { return GetPath( SvtPathOptions::PATH_PLUGIN ); }
     143           0 :         const String&   GetStoragePath() { return GetPath( SvtPathOptions::PATH_STORAGE ); }
     144           0 :         const String&   GetTempPath() { return GetPath( SvtPathOptions::PATH_TEMP ); }
     145           0 :         const String&   GetTemplatePath() { return GetPath( SvtPathOptions::PATH_TEMPLATE ); }
     146          19 :         const String&   GetUserConfigPath() { return GetPath( SvtPathOptions::PATH_USERCONFIG ); }
     147          35 :         const String&   GetWorkPath() { return GetPath( SvtPathOptions::PATH_WORK ); }
     148           0 :         const String&   GetUIConfigPath() { return GetPath( SvtPathOptions::PATH_UICONFIG ); }
     149           0 :         const String&   GetFingerprintPath() { return GetPath( SvtPathOptions::PATH_FINGERPRINT ); }
     150             : 
     151             :         // set the paths
     152             :         void            SetPath( SvtPathOptions::Paths, const String& rNewPath );
     153           0 :         void            SetAddinPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_ADDIN, rPath ); }
     154           0 :         void            SetAutoCorrectPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_AUTOCORRECT, rPath ); }
     155           0 :         void            SetAutoTextPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_AUTOTEXT, rPath ); }
     156           0 :         void            SetBackupPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_BACKUP, rPath ); }
     157           0 :         void            SetBasicPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_BASIC, rPath ); }
     158           0 :         void            SetBitmapPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_BITMAP, rPath ); }
     159           0 :         void            SetConfigPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_CONFIG, rPath ); }
     160           0 :         void            SetDictionaryPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_DICTIONARY, rPath ); }
     161           0 :         void            SetFavoritesPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_FAVORITES, rPath ); }
     162           0 :         void            SetFilterPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_FILTER, rPath ); }
     163           0 :         void            SetGalleryPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_GALLERY, rPath ); }
     164           0 :         void            SetGraphicPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_GRAPHIC, rPath ); }
     165           0 :         void            SetHelpPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_HELP, rPath ); }
     166           0 :         void            SetLinguisticPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_LINGUISTIC, rPath ); }
     167           0 :         void            SetModulePath( const String& rPath ) { SetPath( SvtPathOptions::PATH_MODULE, rPath ); }
     168           0 :         void            SetPalettePath( const String& rPath ) { SetPath( SvtPathOptions::PATH_PALETTE, rPath ); }
     169           0 :         void            SetPluginPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_PLUGIN, rPath ); }
     170           0 :         void            SetStoragePath( const String& rPath ) { SetPath( SvtPathOptions::PATH_STORAGE, rPath ); }
     171           0 :         void            SetTempPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_TEMP, rPath ); }
     172           0 :         void            SetTemplatePath( const String& rPath ) { SetPath( SvtPathOptions::PATH_TEMPLATE, rPath ); }
     173           0 :         void            SetUserConfigPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_USERCONFIG, rPath ); }
     174           0 :         void            SetWorkPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_WORK, rPath ); }
     175             : 
     176             :         rtl::OUString   SubstVar( const rtl::OUString& rVar ) const;
     177             :         rtl::OUString   ExpandMacros( const rtl::OUString& rPath ) const;
     178             :         rtl::OUString   UsePathVariables( const rtl::OUString& rPath ) const;
     179             : 
     180           0 :         ::com::sun::star::lang::Locale  GetLocale() const { return m_aLocale; }
     181             : };
     182             : 
     183             : // global ----------------------------------------------------------------
     184             : 
     185             : static SvtPathOptions_Impl* pOptions = NULL;
     186             : static sal_Int32 nRefCount = 0;
     187             : 
     188             : // functions -------------------------------------------------------------
     189             : struct PropertyStruct
     190             : {
     191             :     const char*             pPropName;  // The ascii name of the Office path
     192             :     SvtPathOptions::Paths   ePath;      // The enum value used by SvtPathOptions
     193             : };
     194             : 
     195             : struct VarNameAttribute
     196             : {
     197             :     const char*             pVarName;       // The name of the path variable
     198             :     VarNameProperty         eVarProperty;   // Which return value is needed by this path variable
     199             : };
     200             : 
     201             : static PropertyStruct aPropNames[] =
     202             : {
     203             :     { "Addin",          SvtPathOptions::PATH_ADDIN          },
     204             :     { "AutoCorrect",    SvtPathOptions::PATH_AUTOCORRECT    },
     205             :     { "AutoText",       SvtPathOptions::PATH_AUTOTEXT       },
     206             :     { "Backup",         SvtPathOptions::PATH_BACKUP         },
     207             :     { "Basic",          SvtPathOptions::PATH_BASIC          },
     208             :     { "Bitmap",         SvtPathOptions::PATH_BITMAP         },
     209             :     { "Config",         SvtPathOptions::PATH_CONFIG         },
     210             :     { "Dictionary",     SvtPathOptions::PATH_DICTIONARY     },
     211             :     { "Favorite",       SvtPathOptions::PATH_FAVORITES      },
     212             :     { "Filter",         SvtPathOptions::PATH_FILTER         },
     213             :     { "Gallery",        SvtPathOptions::PATH_GALLERY        },
     214             :     { "Graphic",        SvtPathOptions::PATH_GRAPHIC        },
     215             :     { "Help",           SvtPathOptions::PATH_HELP           },
     216             :     { "Linguistic",     SvtPathOptions::PATH_LINGUISTIC     },
     217             :     { "Module",         SvtPathOptions::PATH_MODULE         },
     218             :     { "Palette",        SvtPathOptions::PATH_PALETTE        },
     219             :     { "Plugin",         SvtPathOptions::PATH_PLUGIN         },
     220             :     { "Storage",        SvtPathOptions::PATH_STORAGE        },
     221             :     { "Temp",           SvtPathOptions::PATH_TEMP           },
     222             :     { "Template",       SvtPathOptions::PATH_TEMPLATE       },
     223             :     { "UserConfig",     SvtPathOptions::PATH_USERCONFIG     },
     224             :     { "Work",           SvtPathOptions::PATH_WORK           },
     225             :     { "UIConfig",       SvtPathOptions::PATH_UICONFIG       },
     226             :     { "Fingerprint",    SvtPathOptions::PATH_FINGERPRINT    }
     227             : };
     228             : 
     229             : static VarNameAttribute aVarNameAttribute[] =
     230             : {
     231             :     { SUBSTITUTE_INSTPATH,  VAR_NEEDS_SYSTEM_PATH },    // $(instpath)
     232             :     { SUBSTITUTE_PROGPATH,  VAR_NEEDS_SYSTEM_PATH },    // $(progpath)
     233             :     { SUBSTITUTE_USERPATH,  VAR_NEEDS_SYSTEM_PATH },    // $(userpath)
     234             :     { SUBSTITUTE_PATH,      VAR_NEEDS_SYSTEM_PATH },    // $(path)
     235             : };
     236             : 
     237             : // class SvtPathOptions_Impl ---------------------------------------------
     238             : 
     239        1482 : const String& SvtPathOptions_Impl::GetPath( SvtPathOptions::Paths ePath )
     240             : {
     241        1482 :     if ( ePath >= SvtPathOptions::PATH_COUNT )
     242           0 :         return m_aEmptyString;
     243             : 
     244        1482 :     ::osl::MutexGuard aGuard( m_aMutex );
     245             : 
     246             :     try
     247             :     {
     248        1482 :         OUString    aPathValue;
     249        1482 :         OUString    aResult;
     250        1482 :         sal_Int32   nHandle = m_aMapEnumToPropHandle[ (sal_Int32)ePath ];
     251             : 
     252             :         // Substitution is done by the service itself using the substition service
     253        1482 :         Any         a = m_xPathSettings->getFastPropertyValue( nHandle );
     254        1482 :         a >>= aPathValue;
     255        1482 :         if( ePath == SvtPathOptions::PATH_ADDIN     ||
     256             :             ePath == SvtPathOptions::PATH_FILTER    ||
     257             :             ePath == SvtPathOptions::PATH_HELP      ||
     258             :             ePath == SvtPathOptions::PATH_MODULE    ||
     259             :             ePath == SvtPathOptions::PATH_PLUGIN    ||
     260             :             ePath == SvtPathOptions::PATH_STORAGE
     261             :           )
     262             :         {
     263             :             // These office paths have to be converted to system pates
     264          36 :             utl::LocalFileHelper::ConvertURLToPhysicalName( aPathValue, aResult );
     265          36 :             aPathValue = aResult;
     266             :         }
     267             : 
     268        1482 :         m_aPathArray[ ePath ] = aPathValue;
     269        1482 :         return m_aPathArray[ ePath ];
     270             :     }
     271           0 :     catch (UnknownPropertyException &)
     272             :     {
     273             :     }
     274             : 
     275           0 :     return m_aEmptyString;
     276             : }
     277             : 
     278           0 : void SvtPathOptions_Impl::SetPath( SvtPathOptions::Paths ePath, const String& rNewPath )
     279             : {
     280           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     281             : 
     282           0 :     if ( ePath < SvtPathOptions::PATH_COUNT )
     283             :     {
     284           0 :         OUString    aResult;
     285           0 :         OUString    aNewValue;
     286           0 :         Any         a;
     287             : 
     288           0 :         switch ( ePath )
     289             :         {
     290             :             case SvtPathOptions::PATH_ADDIN:
     291             :             case SvtPathOptions::PATH_FILTER:
     292             :             case SvtPathOptions::PATH_HELP:
     293             :             case SvtPathOptions::PATH_MODULE:
     294             :             case SvtPathOptions::PATH_PLUGIN:
     295             :             case SvtPathOptions::PATH_STORAGE:
     296             :             {
     297             :                 // These office paths have to be convert back to UCB-URL's
     298           0 :                 utl::LocalFileHelper::ConvertPhysicalNameToURL( rNewPath, aResult );
     299           0 :                 aNewValue = aResult;
     300             :             }
     301           0 :             break;
     302             : 
     303             :             default:
     304           0 :                 aNewValue = rNewPath;
     305             :         }
     306             : 
     307             :         // Resubstitution is done by the service itself using the substition service
     308           0 :         a <<= aNewValue;
     309             :         try
     310             :         {
     311           0 :             m_xPathSettings->setFastPropertyValue( m_aMapEnumToPropHandle[ (sal_Int32)ePath], a );
     312             :         }
     313           0 :         catch (const Exception&)
     314             :         {
     315           0 :         }
     316           0 :     }
     317           0 : }
     318             : 
     319             : //-------------------------------------------------------------------------
     320             : 
     321           0 : OUString SvtPathOptions_Impl::ExpandMacros( const rtl::OUString& rPath ) const
     322             : {
     323           0 :     ::rtl::OUString sExpanded( rPath );
     324             : 
     325           0 :     const INetURLObject aParser( rPath );
     326           0 :     if ( aParser.GetProtocol() == INET_PROT_VND_SUN_STAR_EXPAND )
     327           0 :         sExpanded = m_xMacroExpander->expandMacros( aParser.GetURLPath( INetURLObject::DECODE_WITH_CHARSET ) );
     328             : 
     329           0 :     return sExpanded;
     330             : }
     331             : 
     332             : //-------------------------------------------------------------------------
     333             : 
     334           0 : OUString SvtPathOptions_Impl::UsePathVariables( const OUString& rPath ) const
     335             : {
     336           0 :     return m_xSubstVariables->reSubstituteVariables( rPath );
     337             : }
     338             : 
     339             : // -----------------------------------------------------------------------
     340             : 
     341          11 : OUString SvtPathOptions_Impl::SubstVar( const OUString& rVar ) const
     342             : {
     343             :     // Don't work at parameter-string directly. Copy it.
     344          11 :     OUString aWorkText = rVar;
     345             : 
     346             :     // Convert the returned path to system path!
     347          11 :     sal_Bool bConvertLocal = sal_False;
     348             : 
     349             :     // Search for first occure of "$(...".
     350          11 :     sal_Int32 nPosition = aWorkText.indexOf( SIGN_STARTVARIABLE );  // = first position of "$(" in string
     351          11 :     sal_Int32 nLength   = 0;                                        // = count of letters from "$(" to ")" in string
     352             : 
     353             :     // Have we found any variable like "$(...)"?
     354          11 :     if ( nPosition != STRPOS_NOTFOUND )
     355             :     {
     356             :         // Yes; Get length of found variable.
     357             :         // If no ")" was found - nLength is set to 0 by default! see before.
     358          11 :         sal_Int32 nEndPosition = aWorkText.indexOf( SIGN_ENDVARIABLE, nPosition );
     359          11 :         if ( nEndPosition != STRPOS_NOTFOUND )
     360          11 :             nLength = nEndPosition - nPosition + 1;
     361             :     }
     362             : 
     363             :     // Is there another path variable?
     364          33 :     while ( ( nPosition != STRPOS_NOTFOUND ) && ( nLength > 0 ) )
     365             :     {
     366             :         // YES; Get the next variable for replace.
     367          11 :         OUString aSubString = aWorkText.copy( nPosition, nLength );
     368          11 :         aSubString = aSubString.toAsciiLowerCase();
     369             : 
     370             :         // Look for special variable that needs a system path.
     371          11 :         VarNameToEnumMap::const_iterator pIter = m_aMapVarNamesToEnum.find( aSubString );
     372          11 :         if ( pIter != m_aMapVarNamesToEnum.end() )
     373           0 :             bConvertLocal = sal_True;
     374             : 
     375          11 :         nPosition += nLength;
     376             : 
     377             :         // We must control index in string before call something at OUString!
     378             :         // The OUString-implementation don't do it for us :-( but the result is not defined otherwise.
     379          11 :         if ( nPosition + 1 > aWorkText.getLength() )
     380             :         {
     381             :             // Position is out of range. Break loop!
     382          11 :             nPosition = STRPOS_NOTFOUND;
     383          11 :             nLength = 0;
     384             :         }
     385             :         else
     386             :         {
     387             :             // Else; Position is valid. Search for next variable.
     388           0 :             nPosition = aWorkText.indexOf( SIGN_STARTVARIABLE, nPosition );
     389             :             // Have we found any variable like "$(...)"?
     390           0 :             if ( nPosition != STRPOS_NOTFOUND )
     391             :             {
     392             :                 // Yes; Get length of found variable. If no ")" was found - nLength must set to 0!
     393           0 :                 nLength = 0;
     394           0 :                 sal_Int32 nEndPosition = aWorkText.indexOf( SIGN_ENDVARIABLE, nPosition );
     395           0 :                 if ( nEndPosition != STRPOS_NOTFOUND )
     396           0 :                     nLength = nEndPosition - nPosition + 1;
     397             :             }
     398             :         }
     399          11 :     }
     400             : 
     401          11 :     aWorkText = m_xSubstVariables->substituteVariables( rVar, sal_False );
     402             : 
     403          11 :     if ( bConvertLocal )
     404             :     {
     405             :         // Convert the URL to a system path for special path variables
     406           0 :         rtl::OUString aReturn;
     407           0 :         utl::LocalFileHelper::ConvertURLToPhysicalName( aWorkText, aReturn );
     408           0 :         return aReturn;
     409             :     }
     410             : 
     411          11 :     return aWorkText;
     412             : }
     413             : 
     414             : // -----------------------------------------------------------------------
     415             : 
     416          19 : SvtPathOptions_Impl::SvtPathOptions_Impl() :
     417          19 :     m_aPathArray( (sal_Int32)SvtPathOptions::PATH_COUNT )
     418             : {
     419          19 :     Reference< XMultiServiceFactory > xSMgr = comphelper::getProcessServiceFactory();
     420             : 
     421             :     // Create necessary services
     422          19 :     m_xPathSettings = Reference< XFastPropertySet >( xSMgr->createInstance(
     423          19 :                                                     ::rtl::OUString( "com.sun.star.util.PathSettings" )),
     424          19 :                                                 UNO_QUERY );
     425          19 :     if ( !m_xPathSettings.is() )
     426             :     {
     427             :         // #112719#: check for existance
     428             :         OSL_FAIL( "SvtPathOptions_Impl::SvtPathOptions_Impl(): #112719# happened again!" );
     429             :         throw RuntimeException(
     430             :             ::rtl::OUString( "Service com.sun.star.util.PathSettings cannot be created" ),
     431           0 :             Reference< XInterface >() );
     432             :     }
     433             : 
     434          19 :     ::comphelper::ComponentContext aContext( xSMgr );
     435          19 :     m_xSubstVariables.set( PathSubstitution::create(aContext.getUNOContext()) );
     436          19 :     m_xMacroExpander.set( aContext.getSingleton( "com.sun.star.util.theMacroExpander" ), UNO_QUERY_THROW );
     437             : 
     438             :     // Create temporary hash map to have a mapping between property names and property handles
     439          19 :     Reference< XPropertySet > xPropertySet = Reference< XPropertySet >( m_xPathSettings, UNO_QUERY );
     440          19 :     Reference< XPropertySetInfo > xPropSetInfo = xPropertySet->getPropertySetInfo();
     441          19 :     Sequence< Property > aPathPropSeq = xPropSetInfo->getProperties();
     442             : 
     443          19 :     NameToHandleMap aTempHashMap;
     444        1843 :     for ( sal_Int32 n = 0; n < aPathPropSeq.getLength(); n++ )
     445             :     {
     446        1824 :         const com::sun::star::beans::Property& aProperty = aPathPropSeq[n];
     447        1824 :         aTempHashMap.insert( NameToHandleMap::value_type( aProperty.Name, aProperty.Handle ));
     448             :     }
     449             : 
     450             :     // Create mapping between internal enum (SvtPathOptions::Paths) and property handle
     451          19 :     sal_Int32 nCount = sizeof( aPropNames ) / sizeof( PropertyStruct );
     452             :     sal_Int32 i;
     453         475 :     for ( i = 0; i < nCount; i++ )
     454             :     {
     455             :         NameToHandleMap::const_iterator pIter =
     456         456 :             aTempHashMap.find( rtl::OUString::createFromAscii( aPropNames[i].pPropName ));
     457             : 
     458         456 :         if ( pIter != aTempHashMap.end() )
     459             :         {
     460         456 :             sal_Int32 nHandle   = pIter->second;
     461         456 :             sal_Int32 nEnum     = aPropNames[i].ePath;
     462         456 :             m_aMapEnumToPropHandle.insert( EnumToHandleMap::value_type( nEnum, nHandle ));
     463             :         }
     464             :     }
     465             : 
     466             :     // Create hash map for path variables that need a system path as a return value!
     467          19 :     nCount = sizeof( aVarNameAttribute ) / sizeof( VarNameAttribute );
     468          95 :     for ( i = 0; i < nCount; i++ )
     469             :     {
     470             :         m_aMapVarNamesToEnum.insert( VarNameToEnumMap::value_type(
     471             :                 OUString::createFromAscii( aVarNameAttribute[i].pVarName ),
     472          76 :                 aVarNameAttribute[i].eVarProperty ));
     473             :     }
     474             : 
     475             :     // Set language type!
     476          19 :     OUString aLocaleStr( ConfigManager::getLocale() );
     477          19 :     sal_Int32 nIndex = 0;
     478          19 :     m_aLocale.Language = aLocaleStr.getToken(0, '-', nIndex );
     479          19 :     m_aLocale.Country = aLocaleStr.getToken(0, '-', nIndex );
     480          19 :     m_aLocale.Variant = aLocaleStr.getToken(0, '-', nIndex );
     481          19 : }
     482             : 
     483             : // -----------------------------------------------------------------------
     484             : 
     485             : // class SvtPathOptions --------------------------------------------------
     486             : 
     487             : namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex > {}; }
     488             : 
     489        1527 : SvtPathOptions::SvtPathOptions()
     490             : {
     491             :     // Global access, must be guarded (multithreading)
     492        1527 :     ::osl::MutexGuard aGuard( lclMutex::get() );
     493        1527 :     if ( !pOptions )
     494             :     {
     495          19 :         pOptions = new SvtPathOptions_Impl;
     496          19 :         ItemHolder1::holdConfigItem(E_PATHOPTIONS);
     497             :     }
     498        1527 :     ++nRefCount;
     499        1527 :     pImp = pOptions;
     500        1527 : }
     501             : 
     502             : // -----------------------------------------------------------------------
     503             : 
     504        3073 : SvtPathOptions::~SvtPathOptions()
     505             : {
     506             :     // Global access, must be guarded (multithreading)
     507        1527 :     ::osl::MutexGuard aGuard( lclMutex::get() );
     508        1527 :     if ( !--nRefCount )
     509             :     {
     510          19 :         DELETEZ( pOptions );
     511        1527 :     }
     512        1546 : }
     513             : 
     514             : // -----------------------------------------------------------------------
     515             : 
     516          36 : const String& SvtPathOptions::GetAddinPath() const
     517             : {
     518          36 :     return pImp->GetAddinPath();
     519             : }
     520             : 
     521             : // -----------------------------------------------------------------------
     522             : 
     523          10 : const String& SvtPathOptions::GetAutoCorrectPath() const
     524             : {
     525          10 :     return pImp->GetAutoCorrectPath();
     526             : }
     527             : 
     528             : // -----------------------------------------------------------------------
     529             : 
     530           0 : const String& SvtPathOptions::GetAutoTextPath() const
     531             : {
     532           0 :     return pImp->GetAutoTextPath();
     533             : }
     534             : 
     535             : // -----------------------------------------------------------------------
     536             : 
     537          59 : const String& SvtPathOptions::GetBackupPath() const
     538             : {
     539          59 :     return pImp->GetBackupPath();
     540             : }
     541             : 
     542             : // -----------------------------------------------------------------------
     543             : 
     544         929 : const String& SvtPathOptions::GetBasicPath() const
     545             : {
     546         929 :     return pImp->GetBasicPath();
     547             : }
     548             : 
     549             : // -----------------------------------------------------------------------
     550             : 
     551           0 : const String& SvtPathOptions::GetBitmapPath() const
     552             : {
     553           0 :     return pImp->GetBitmapPath();
     554             : }
     555             : 
     556             : // -----------------------------------------------------------------------
     557             : 
     558          19 : const String& SvtPathOptions::GetConfigPath() const
     559             : {
     560          19 :     return pImp->GetConfigPath();
     561             : }
     562             : 
     563             : // -----------------------------------------------------------------------
     564             : 
     565           0 : const String& SvtPathOptions::GetDictionaryPath() const
     566             : {
     567           0 :     return pImp->GetDictionaryPath();
     568             : }
     569             : 
     570             : // -----------------------------------------------------------------------
     571             : 
     572           0 : const String& SvtPathOptions::GetFavoritesPath() const
     573             : {
     574           0 :     return pImp->GetFavoritesPath();
     575             : }
     576             : 
     577             : // -----------------------------------------------------------------------
     578             : 
     579           0 : const String& SvtPathOptions::GetFilterPath() const
     580             : {
     581           0 :     return pImp->GetFilterPath();
     582             : }
     583             : 
     584             : // -----------------------------------------------------------------------
     585             : 
     586           0 : const String& SvtPathOptions::GetGalleryPath() const
     587             : {
     588           0 :     return pImp->GetGalleryPath();
     589             : }
     590             : 
     591             : // -----------------------------------------------------------------------
     592             : 
     593           0 : const String& SvtPathOptions::GetGraphicPath() const
     594             : {
     595           0 :     return pImp->GetGraphicPath();
     596             : }
     597             : 
     598             : // -----------------------------------------------------------------------
     599             : 
     600           0 : const String& SvtPathOptions::GetHelpPath() const
     601             : {
     602           0 :     return pImp->GetHelpPath();
     603             : }
     604             : 
     605             : // -----------------------------------------------------------------------
     606             : 
     607           0 : const String& SvtPathOptions::GetLinguisticPath() const
     608             : {
     609           0 :     return pImp->GetLinguisticPath();
     610             : }
     611             : 
     612             : // -----------------------------------------------------------------------
     613             : 
     614           0 : const String& SvtPathOptions::GetFingerprintPath() const
     615             : {
     616           0 :     return pImp->GetFingerprintPath();
     617             : }
     618             : 
     619             : // -----------------------------------------------------------------------
     620             : 
     621           0 : const String& SvtPathOptions::GetModulePath() const
     622             : {
     623           0 :     return pImp->GetModulePath();
     624             : }
     625             : 
     626             : // -----------------------------------------------------------------------
     627             : 
     628         375 : const String& SvtPathOptions::GetPalettePath() const
     629             : {
     630         375 :     return pImp->GetPalettePath();
     631             : }
     632             : 
     633             : // -----------------------------------------------------------------------
     634             : 
     635           0 : const String& SvtPathOptions::GetPluginPath() const
     636             : {
     637           0 :     return pImp->GetPluginPath();
     638             : }
     639             : 
     640             : // -----------------------------------------------------------------------
     641             : 
     642           0 : const String& SvtPathOptions::GetStoragePath() const
     643             : {
     644           0 :     return pImp->GetStoragePath();
     645             : }
     646             : 
     647             : // -----------------------------------------------------------------------
     648             : 
     649           0 : const String& SvtPathOptions::GetTempPath() const
     650             : {
     651           0 :     return pImp->GetTempPath();
     652             : }
     653             : 
     654             : // -----------------------------------------------------------------------
     655             : 
     656           0 : const String& SvtPathOptions::GetTemplatePath() const
     657             : {
     658           0 :     return pImp->GetTemplatePath();
     659             : }
     660             : 
     661             : // -----------------------------------------------------------------------
     662             : 
     663          19 : const String& SvtPathOptions::GetUserConfigPath() const
     664             : {
     665          19 :     return pImp->GetUserConfigPath();
     666             : }
     667             : 
     668           0 : const String& SvtPathOptions::GetUIConfigPath() const
     669             : {
     670           0 :     return pImp->GetUIConfigPath();
     671             : }
     672             : 
     673             : // -----------------------------------------------------------------------
     674             : 
     675          35 : const String& SvtPathOptions::GetWorkPath() const
     676             : {
     677          35 :     return pImp->GetWorkPath();
     678             : }
     679             : 
     680             : // -----------------------------------------------------------------------
     681             : 
     682           0 : void SvtPathOptions::SetAddinPath( const String& rPath )
     683             : {
     684           0 :     pImp->SetAddinPath( rPath );
     685           0 : }
     686             : 
     687             : // -----------------------------------------------------------------------
     688             : 
     689           0 : void SvtPathOptions::SetAutoCorrectPath( const String& rPath )
     690             : {
     691           0 :     pImp->SetAutoCorrectPath( rPath );
     692           0 : }
     693             : 
     694             : // -----------------------------------------------------------------------
     695             : 
     696           0 : void SvtPathOptions::SetAutoTextPath( const String& rPath )
     697             : {
     698           0 :     pImp->SetAutoTextPath( rPath );
     699           0 : }
     700             : 
     701             : // -----------------------------------------------------------------------
     702             : 
     703           0 : void SvtPathOptions::SetBackupPath( const String& rPath )
     704             : {
     705           0 :     pImp->SetBackupPath( rPath );
     706           0 : }
     707             : 
     708             : // -----------------------------------------------------------------------
     709             : 
     710           0 : void SvtPathOptions::SetBasicPath( const String& rPath )
     711             : {
     712           0 :     pImp->SetBasicPath( rPath );
     713           0 : }
     714             : 
     715             : // -----------------------------------------------------------------------
     716             : 
     717           0 : void SvtPathOptions::SetBitmapPath( const String& rPath )
     718             : {
     719           0 :     pImp->SetBitmapPath( rPath );
     720           0 : }
     721             : 
     722             : // -----------------------------------------------------------------------
     723             : 
     724           0 : void SvtPathOptions::SetConfigPath( const String& rPath )
     725             : {
     726           0 :     pImp->SetConfigPath( rPath );
     727           0 : }
     728             : 
     729             : // -----------------------------------------------------------------------
     730             : 
     731           0 : void SvtPathOptions::SetDictionaryPath( const String& rPath )
     732             : {
     733           0 :     pImp->SetDictionaryPath( rPath );
     734           0 : }
     735             : 
     736             : // -----------------------------------------------------------------------
     737             : 
     738           0 : void SvtPathOptions::SetFavoritesPath( const String& rPath )
     739             : {
     740           0 :     pImp->SetFavoritesPath( rPath );
     741           0 : }
     742             : 
     743             : // -----------------------------------------------------------------------
     744             : 
     745           0 : void SvtPathOptions::SetFilterPath( const String& rPath )
     746             : {
     747           0 :     pImp->SetFilterPath( rPath );
     748           0 : }
     749             : 
     750             : // -----------------------------------------------------------------------
     751             : 
     752           0 : void SvtPathOptions::SetGalleryPath( const String& rPath )
     753             : {
     754           0 :     pImp->SetGalleryPath( rPath );
     755           0 : }
     756             : 
     757             : // -----------------------------------------------------------------------
     758             : 
     759           0 : void SvtPathOptions::SetGraphicPath( const String& rPath )
     760             : {
     761           0 :     pImp->SetGraphicPath( rPath );
     762           0 : }
     763             : 
     764             : // -----------------------------------------------------------------------
     765             : 
     766           0 : void SvtPathOptions::SetHelpPath( const String& rPath )
     767             : {
     768           0 :     pImp->SetHelpPath( rPath );
     769           0 : }
     770             : 
     771             : // -----------------------------------------------------------------------
     772             : 
     773           0 : void SvtPathOptions::SetLinguisticPath( const String& rPath )
     774             : {
     775           0 :     pImp->SetLinguisticPath( rPath );
     776           0 : }
     777             : 
     778             : // -----------------------------------------------------------------------
     779             : 
     780           0 : void SvtPathOptions::SetModulePath( const String& rPath )
     781             : {
     782           0 :     pImp->SetModulePath( rPath );
     783           0 : }
     784             : 
     785             : // -----------------------------------------------------------------------
     786             : 
     787           0 : void SvtPathOptions::SetPalettePath( const String& rPath )
     788             : {
     789           0 :     pImp->SetPalettePath( rPath );
     790           0 : }
     791             : 
     792             : // -----------------------------------------------------------------------
     793             : 
     794           0 : void SvtPathOptions::SetPluginPath( const String& rPath )
     795             : {
     796           0 :     pImp->SetPluginPath( rPath );
     797           0 : }
     798             : 
     799             : // -----------------------------------------------------------------------
     800             : 
     801           0 : void SvtPathOptions::SetStoragePath( const String& rPath )
     802             : {
     803           0 :     pImp->SetStoragePath( rPath );
     804           0 : }
     805             : 
     806             : // -----------------------------------------------------------------------
     807             : 
     808           0 : void SvtPathOptions::SetTempPath( const String& rPath )
     809             : {
     810           0 :     pImp->SetTempPath( rPath );
     811           0 : }
     812             : 
     813             : // -----------------------------------------------------------------------
     814             : 
     815           0 : void SvtPathOptions::SetTemplatePath( const String& rPath )
     816             : {
     817           0 :     pImp->SetTemplatePath( rPath );
     818           0 : }
     819             : 
     820             : // -----------------------------------------------------------------------
     821             : 
     822           0 : void SvtPathOptions::SetUserConfigPath( const String& rPath )
     823             : {
     824           0 :     pImp->SetUserConfigPath( rPath );
     825           0 : }
     826             : 
     827             : // -----------------------------------------------------------------------
     828             : 
     829           0 : void SvtPathOptions::SetWorkPath( const String& rPath )
     830             : {
     831           0 :     pImp->SetWorkPath( rPath );
     832           0 : }
     833             : 
     834             : // -----------------------------------------------------------------------
     835             : 
     836          11 : String SvtPathOptions::SubstituteVariable( const String& rVar ) const
     837             : {
     838          11 :     String aRet = pImp->SubstVar( rVar );
     839          11 :     return aRet;
     840             : }
     841             : 
     842             : // -----------------------------------------------------------------------
     843             : 
     844           0 : String SvtPathOptions::ExpandMacros( const String& rPath ) const
     845             : {
     846           0 :     return pImp->ExpandMacros( rPath );
     847             : }
     848             : 
     849             : // -----------------------------------------------------------------------
     850             : 
     851           0 : String SvtPathOptions::UseVariable( const String& rPath ) const
     852             : {
     853           0 :     String aRet = pImp->UsePathVariables( rPath );
     854           0 :     return aRet;
     855             : }
     856             : 
     857             : // -----------------------------------------------------------------------
     858             : 
     859           0 : sal_Bool SvtPathOptions::SearchFile( String& rIniFile, Paths ePath )
     860             : {
     861             :     // check parameter: empty inifile name?
     862           0 :     if ( !rIniFile.Len() )
     863             :     {
     864             :         SAL_WARN( "unotools.config", "SvtPathOptions::SearchFile(): invalid parameter" );
     865           0 :         return sal_False;
     866             :     }
     867             : 
     868           0 :     rtl::OUString aIniFile = pImp->SubstVar( rIniFile );
     869           0 :     sal_Bool bRet = sal_False;
     870             : 
     871           0 :     switch ( ePath )
     872             :     {
     873             :         case PATH_USERCONFIG:
     874             :         {
     875             :             // path is a URL
     876           0 :             bRet = sal_True;
     877           0 :             INetURLObject aObj( GetUserConfigPath() );
     878             : 
     879           0 :             sal_Int32 nIniIndex = 0;
     880           0 :             do
     881             :             {
     882           0 :                 rtl::OUString aToken = aIniFile.getToken( 0, '/', nIniIndex );
     883           0 :                 aObj.insertName(aToken);
     884             :             }
     885             :             while ( nIniIndex >= 0 );
     886             : 
     887           0 :             if ( !::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::NO_DECODE ) ) )
     888             :             {
     889           0 :                 aObj.SetSmartURL( GetConfigPath() );
     890           0 :                 aObj.insertName( aIniFile );
     891           0 :                 bRet = ::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
     892             :             }
     893             : 
     894           0 :             if ( bRet )
     895           0 :                 rIniFile = aObj.GetMainURL( INetURLObject::NO_DECODE );
     896             : 
     897           0 :             break;
     898             :         }
     899             : 
     900             :         default:
     901             :         {
     902           0 :             rtl::OUString aPath;
     903           0 :             switch ( ePath )
     904             :             {
     905           0 :                 case PATH_ADDIN:        aPath = GetAddinPath();         break;
     906           0 :                 case PATH_AUTOCORRECT:  aPath = GetAutoCorrectPath();   break;
     907           0 :                 case PATH_AUTOTEXT:     aPath = GetAutoTextPath();      break;
     908           0 :                 case PATH_BACKUP:       aPath = GetBackupPath();        break;
     909           0 :                 case PATH_BASIC:        aPath = GetBasicPath();         break;
     910           0 :                 case PATH_BITMAP:       aPath = GetBitmapPath();        break;
     911           0 :                 case PATH_CONFIG:       aPath = GetConfigPath();        break;
     912           0 :                 case PATH_DICTIONARY:   aPath = GetDictionaryPath();    break;
     913           0 :                 case PATH_FAVORITES:    aPath = GetFavoritesPath();     break;
     914           0 :                 case PATH_FILTER:       aPath = GetFilterPath();        break;
     915           0 :                 case PATH_GALLERY:      aPath = GetGalleryPath();       break;
     916           0 :                 case PATH_GRAPHIC:      aPath = GetGraphicPath();       break;
     917           0 :                 case PATH_HELP:         aPath = GetHelpPath();          break;
     918           0 :                 case PATH_LINGUISTIC:   aPath = GetLinguisticPath();    break;
     919           0 :                 case PATH_MODULE:       aPath = GetModulePath();        break;
     920           0 :                 case PATH_PALETTE:      aPath = GetPalettePath();       break;
     921           0 :                 case PATH_PLUGIN:       aPath = GetPluginPath();        break;
     922           0 :                 case PATH_STORAGE:      aPath = GetStoragePath();       break;
     923           0 :                 case PATH_TEMP:         aPath = GetTempPath();          break;
     924           0 :                 case PATH_TEMPLATE:     aPath = GetTemplatePath();      break;
     925           0 :                 case PATH_WORK:         aPath = GetWorkPath();          break;
     926           0 :                 case PATH_UICONFIG:     aPath = GetUIConfigPath();      break;
     927           0 :                 case PATH_FINGERPRINT:  aPath = GetFingerprintPath();   break;
     928           0 :                 case PATH_USERCONFIG:/*-Wall???*/           break;
     929           0 :                 case PATH_COUNT: /*-Wall???*/ break;
     930             :             }
     931             : 
     932           0 :             sal_Int32 nPathIndex = 0;
     933           0 :             do
     934             :             {
     935           0 :                 sal_Bool bIsURL = sal_True;
     936           0 :                 rtl::OUString aPathToken = aPath.getToken( 0, SEARCHPATH_DELIMITER, nPathIndex );
     937           0 :                 INetURLObject aObj( aPathToken );
     938           0 :                 if ( aObj.HasError() )
     939             :                 {
     940           0 :                     bIsURL = sal_False;
     941           0 :                     rtl::OUString aURL;
     942           0 :                     if ( LocalFileHelper::ConvertPhysicalNameToURL( aPathToken, aURL ) )
     943           0 :                         aObj.SetURL( aURL );
     944             :                 }
     945           0 :                 if ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_EXPAND )
     946             :                 {
     947           0 :                     ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
     948           0 :                     Reference< XMacroExpander > xMacroExpander( aContext.getSingleton( "com.sun.star.util.theMacroExpander" ), UNO_QUERY );
     949             :                     OSL_ENSURE( xMacroExpander.is(), "SvtPathOptions::SearchFile: unable to access the MacroExpander singleton!" );
     950           0 :                     if ( xMacroExpander.is() )
     951             :                     {
     952           0 :                         const ::rtl::OUString sExpandedPath = xMacroExpander->expandMacros( aObj.GetURLPath( INetURLObject::DECODE_WITH_CHARSET ) );
     953           0 :                         aObj.SetURL( sExpandedPath );
     954           0 :                     }
     955             :                 }
     956             : 
     957           0 :                 sal_Int32 nIniIndex = 0;
     958           0 :                 do
     959             :                 {
     960           0 :                     rtl::OUString aToken = aIniFile.getToken( 0, '/', nIniIndex );
     961           0 :                     aObj.insertName(aToken);
     962             :                 }
     963             :                 while ( nIniIndex >= 0 );
     964             : 
     965           0 :                 bRet = ::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
     966             : 
     967           0 :                 if ( bRet )
     968             :                 {
     969           0 :                     if ( !bIsURL )
     970             :                     {
     971           0 :                         rtl::OUString sTmp(rIniFile);
     972             :                         ::utl::LocalFileHelper::ConvertURLToPhysicalName(
     973           0 :                                             aObj.GetMainURL( INetURLObject::NO_DECODE ), sTmp );
     974           0 :                         rIniFile = sTmp;
     975             :                     }
     976             :                     else
     977           0 :                         rIniFile = aObj.GetMainURL( INetURLObject::NO_DECODE );
     978             :                     break;
     979           0 :                 }
     980             :             }
     981           0 :             while ( nPathIndex >= 0 );
     982             :         }
     983             :     }
     984             : 
     985           0 :     return bRet;
     986             : }
     987             : 
     988             : // -----------------------------------------------------------------------
     989             : 
     990           0 : ::com::sun::star::lang::Locale SvtPathOptions::GetLocale() const
     991             : {
     992           0 :     return pImp->GetLocale();
     993             : }
     994             : 
     995             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10