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

Generated by: LCOV version 1.10