LCOV - code coverage report
Current view: top level - unotools/source/config - pathoptions.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 155 362 42.8 %
Date: 2015-06-13 12:38:46 Functions: 35 108 32.4 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11