diff options
Diffstat (limited to 'unotools/source/config/pathoptions.cxx')
-rw-r--r-- | unotools/source/config/pathoptions.cxx | 84 |
1 files changed, 52 insertions, 32 deletions
diff --git a/unotools/source/config/pathoptions.cxx b/unotools/source/config/pathoptions.cxx index 3d7eddf9c89f..8356064172c1 100644 --- a/unotools/source/config/pathoptions.cxx +++ b/unotools/source/config/pathoptions.cxx @@ -44,12 +44,14 @@ #include <unotools/ucbhelper.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/componentcontext.hxx> #include <com/sun/star/beans/XFastPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/beans/XPropertySetInfo.hpp> #include <com/sun/star/util/XStringSubstitution.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/util/XMacroExpander.hpp> #include <rtl/instance.hxx> #include <itemholder1.hxx> @@ -136,6 +138,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; @@ -198,13 +201,13 @@ 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; } - BOOL IsPathReadonly(SvtPathOptions::Pathes ePath)const; + sal_Bool IsPathReadonly(SvtPathOptions::Pathes ePath)const; }; // global ---------------------------------------------------------------- @@ -302,10 +305,10 @@ const String& SvtPathOptions_Impl::GetPath( SvtPathOptions::Pathes ePath ) return m_aEmptyString; } // ----------------------------------------------------------------------- -BOOL SvtPathOptions_Impl::IsPathReadonly(SvtPathOptions::Pathes ePath)const +sal_Bool SvtPathOptions_Impl::IsPathReadonly(SvtPathOptions::Pathes ePath)const { ::osl::MutexGuard aGuard( m_aMutex ); - BOOL bReadonly = FALSE; + sal_Bool bReadonly = sal_False; if ( ePath < SvtPathOptions::PATH_COUNT ) { Reference<XPropertySet> xPrSet(m_xPathSettings, UNO_QUERY); @@ -363,29 +366,35 @@ 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; // Convert the returned path to system path! - BOOL bConvertLocal = FALSE; + sal_Bool bConvertLocal = sal_False; // Search for first occure of "$(...". sal_Int32 nPosition = aWorkText.indexOf( SIGN_STARTVARIABLE ); // = first position of "$(" in string @@ -412,7 +421,7 @@ OUString SvtPathOptions_Impl::SubstVar( const OUString& rVar ) // Look for special variable that needs a system path. VarNameToEnumMap::const_iterator pIter = m_aMapVarNamesToEnum.find( aSubString ); if ( pIter != m_aMapVarNamesToEnum.end() ) - bConvertLocal = TRUE; + bConvertLocal = sal_True; nPosition += nLength; @@ -474,18 +483,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 - OSL_FAIL( "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 ); @@ -896,13 +896,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; @@ -973,7 +982,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; } @@ -981,16 +990,27 @@ sal_Bool SvtPathOptions::SearchFile( String& rIniFile, Pathes ePath ) sal_uInt16 j, nIdx = 0, nTokenCount = aPath.GetTokenCount( SEARCHPATH_DELIMITER ); for ( j = 0; j < nTokenCount; ++j ) { - BOOL bIsURL = TRUE; + sal_Bool bIsURL = sal_True; String aPathToken = aPath.GetToken( 0, SEARCHPATH_DELIMITER, nIdx ); INetURLObject aObj( aPathToken ); if ( aObj.HasError() ) { - bIsURL = FALSE; + bIsURL = sal_False; String aURL; if ( LocalFileHelper::ConvertPhysicalNameToURL( aPathToken, aURL ) ) aObj.SetURL( aURL ); } + if ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_EXPAND ) + { + ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); + Reference< XMacroExpander > xMacroExpander( aContext.getSingleton( "com.sun.star.util.theMacroExpander" ), UNO_QUERY ); + OSL_ENSURE( xMacroExpander.is(), "SvtPathOptions::SearchFile: unable to access the MacroExpander singleton!" ); + if ( xMacroExpander.is() ) + { + const ::rtl::OUString sExpandedPath = xMacroExpander->expandMacros( aObj.GetURLPath( INetURLObject::DECODE_WITH_CHARSET ) ); + aObj.SetURL( sExpandedPath ); + } + } xub_StrLen i, nCount = aIniFile.GetTokenCount( '/' ); for ( i = 0; i < nCount; ++i ) @@ -1020,7 +1040,7 @@ sal_Bool SvtPathOptions::SearchFile( String& rIniFile, Pathes ePath ) return pImp->GetLocale(); } // ----------------------------------------------------------------------- -BOOL SvtPathOptions::IsPathReadonly(Pathes ePath)const +sal_Bool SvtPathOptions::IsPathReadonly(Pathes ePath)const { return pImp->IsPathReadonly(ePath); } |