diff options
author | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2010-11-24 10:47:15 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2010-11-24 10:47:15 +0100 |
commit | 2b4caa130c2c1f027f5b197c5c7344fcbcb11740 (patch) | |
tree | 53463e4cf6a70338745cb6a3e2ccf0abddf37b01 /unotools | |
parent | 22ea168b2014bbefe00a52de59f52b669abd8909 (diff) |
dba34b: #i115760#: added ExpandMacros
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/inc/unotools/pathoptions.hxx | 5 | ||||
-rw-r--r-- | unotools/source/config/pathoptions.cxx | 101 |
2 files changed, 56 insertions, 50 deletions
diff --git a/unotools/inc/unotools/pathoptions.hxx b/unotools/inc/unotools/pathoptions.hxx index 4d94c93cca4a..bff3a3120ee4 100644 --- a/unotools/inc/unotools/pathoptions.hxx +++ b/unotools/inc/unotools/pathoptions.hxx @@ -129,8 +129,9 @@ public: void SetWorkPath( const String& rPath ); void SetPath( SvtPathOptions::Pathes ePath, const String& rNewPath ); - String SubstituteVariable( const String& rVar ); - String UseVariable( const String& rVar ); + String SubstituteVariable( const String& rVar ) const; + String ExpandMacros( const String& rPath ) const; + String UseVariable( const String& rVar ) const; sal_Bool SearchFile( String& rIniFile, Pathes ePath = PATH_USERCONFIG ); ::com::sun::star::lang::Locale GetLocale() const; sal_Bool IsReadonly() const; diff --git a/unotools/source/config/pathoptions.cxx b/unotools/source/config/pathoptions.cxx index 3cf43a1f3bc9..d2f001d1c481 100644 --- a/unotools/source/config/pathoptions.cxx +++ b/unotools/source/config/pathoptions.cxx @@ -137,6 +137,7 @@ class SvtPathOptions_Impl std::vector< String > m_aPathArray; Reference< XFastPropertySet > m_xPathSettings; Reference< XStringSubstitution > m_xSubstVariables; + Reference< XMacroExpander > m_xMacroExpander; mutable EnumToHandleMap m_aMapEnumToPropHandle; VarNameToEnumMap m_aMapVarNamesToEnum; @@ -199,9 +200,9 @@ class SvtPathOptions_Impl void SetUserConfigPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_USERCONFIG, rPath ); } void SetWorkPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_WORK, rPath ); } - rtl::OUString SubstVar( const rtl::OUString& rVar ); - rtl::OUString SubstituteAndConvert( const rtl::OUString& rPath ); - rtl::OUString UsePathVariables( const rtl::OUString& rPath ); + rtl::OUString SubstVar( const rtl::OUString& rVar ) const; + rtl::OUString ExpandMacros( const rtl::OUString& rPath ) const; + rtl::OUString UsePathVariables( const rtl::OUString& rPath ) const; ::com::sun::star::lang::Locale GetLocale() const { return m_aLocale; } @@ -282,33 +283,31 @@ const String& SvtPathOptions_Impl::GetPath( SvtPathOptions::Pathes ePath ) { ::osl::MutexGuard aGuard( m_aMutex ); - if ( ePath < SvtPathOptions::PATH_COUNT ) + if ( ePath >= SvtPathOptions::PATH_COUNT ) + return m_aEmptyString; + + OUString aPathValue; + String aResult; + sal_Int32 nHandle = m_aMapEnumToPropHandle[ (sal_Int32)ePath ]; + + // Substitution is done by the service itself using the substition service + Any a = m_xPathSettings->getFastPropertyValue( nHandle ); + a >>= aPathValue; + if( ePath == SvtPathOptions::PATH_ADDIN || + ePath == SvtPathOptions::PATH_FILTER || + ePath == SvtPathOptions::PATH_HELP || + ePath == SvtPathOptions::PATH_MODULE || + ePath == SvtPathOptions::PATH_PLUGIN || + ePath == SvtPathOptions::PATH_STORAGE + ) { - OUString aPathValue; - String aResult; - sal_Int32 nHandle = m_aMapEnumToPropHandle[ (sal_Int32)ePath ]; - - // Substitution is done by the service itself using the substition service - Any a = m_xPathSettings->getFastPropertyValue( nHandle ); - a >>= aPathValue; - if( ePath == SvtPathOptions::PATH_ADDIN || - ePath == SvtPathOptions::PATH_FILTER || - ePath == SvtPathOptions::PATH_HELP || - ePath == SvtPathOptions::PATH_MODULE || - ePath == SvtPathOptions::PATH_PLUGIN || - ePath == SvtPathOptions::PATH_STORAGE - ) - { - // These office paths have to be converted to system pathes - utl::LocalFileHelper::ConvertURLToPhysicalName( aPathValue, aResult ); - aPathValue = aResult; - } - - m_aPathArray[ ePath ] = aPathValue; - return m_aPathArray[ ePath ]; + // These office paths have to be converted to system pathes + utl::LocalFileHelper::ConvertURLToPhysicalName( aPathValue, aResult ); + aPathValue = aResult; } - return m_aEmptyString; + m_aPathArray[ ePath ] = aPathValue; + return m_aPathArray[ ePath ]; } // ----------------------------------------------------------------------- BOOL SvtPathOptions_Impl::IsPathReadonly(SvtPathOptions::Pathes ePath)const @@ -372,23 +371,29 @@ void SvtPathOptions_Impl::SetPath( SvtPathOptions::Pathes ePath, const String& r } } -// ----------------------------------------------------------------------- +//------------------------------------------------------------------------- -OUString SvtPathOptions_Impl::SubstituteAndConvert( const rtl::OUString& rPath ) +OUString SvtPathOptions_Impl::ExpandMacros( const rtl::OUString& rPath ) const { - return SubstVar( rPath ); + ::rtl::OUString sExpanded( rPath ); + + const INetURLObject aParser( rPath ); + if ( aParser.GetProtocol() == INET_PROT_VND_SUN_STAR_EXPAND ) + sExpanded = m_xMacroExpander->expandMacros( aParser.GetURLPath( INetURLObject::DECODE_WITH_CHARSET ) ); + + return sExpanded; } //------------------------------------------------------------------------- -OUString SvtPathOptions_Impl::UsePathVariables( const OUString& rPath ) +OUString SvtPathOptions_Impl::UsePathVariables( const OUString& rPath ) const { return m_xSubstVariables->reSubstituteVariables( rPath ); } // ----------------------------------------------------------------------- -OUString SvtPathOptions_Impl::SubstVar( const OUString& rVar ) +OUString SvtPathOptions_Impl::SubstVar( const OUString& rVar ) const { // Don't work at parameter-string directly. Copy it. OUString aWorkText = rVar; @@ -483,18 +488,9 @@ SvtPathOptions_Impl::SvtPathOptions_Impl() : Reference< XInterface >() ); } - m_xSubstVariables = Reference< XStringSubstitution >( xSMgr->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.util.PathSubstitution" ))), - UNO_QUERY ); - if ( !m_xSubstVariables.is() ) - { - // #112719#: check for existance - DBG_ERROR( "SvtPathOptions_Impl::SvtPathOptions_Impl(): #112719# happened again!" ); - throw RuntimeException( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Service com.sun.star.util.PathSubstitution cannot be created" )), - Reference< XInterface >() ); - } + ::comphelper::ComponentContext aContext( xSMgr ); + m_xSubstVariables.set( aContext.createComponent( "com.sun.star.util.PathSubstitution" ), UNO_QUERY_THROW ); + m_xMacroExpander.set( aContext.getSingleton( "com.sun.star.util.theMacroExpander" ), UNO_QUERY_THROW ); // Create temporary hash map to have a mapping between property names and property handles Reference< XPropertySet > xPropertySet = Reference< XPropertySet >( m_xPathSettings, UNO_QUERY ); @@ -905,13 +901,22 @@ void SvtPathOptions::SetWorkPath( const String& rPath ) // ----------------------------------------------------------------------- -String SvtPathOptions::SubstituteVariable( const String& rVar ) +String SvtPathOptions::SubstituteVariable( const String& rVar ) const { - String aRet = pImp->SubstituteAndConvert( rVar ); + String aRet = pImp->SubstVar( rVar ); return aRet; } -String SvtPathOptions::UseVariable( const String& rPath ) +// ----------------------------------------------------------------------- + +String SvtPathOptions::ExpandMacros( const String& rPath ) const +{ + return pImp->ExpandMacros( rPath ); +} + +// ----------------------------------------------------------------------- + +String SvtPathOptions::UseVariable( const String& rPath ) const { String aRet = pImp->UsePathVariables( rPath ); return aRet; @@ -982,7 +987,7 @@ sal_Bool SvtPathOptions::SearchFile( String& rIniFile, Pathes ePath ) case PATH_TEMPLATE: aPath = GetTemplatePath(); break; case PATH_WORK: aPath = GetWorkPath(); break; case PATH_UICONFIG: aPath = GetUIConfigPath(); break; - case PATH_FINGERPRINT: aPath = GetFingerprintPath(); break; + case PATH_FINGERPRINT: aPath = GetFingerprintPath(); break; case PATH_USERCONFIG:/*-Wall???*/ break; case PATH_COUNT: /*-Wall???*/ break; } |