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

Generated by: LCOV version 1.10