From 8b75883b87c9f7989f98fb413f5e51200c52891c Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 14 Nov 2011 22:07:23 +0100 Subject: Simplified some uses of css.configuration.theDefaultProvider. * Retro-added new-style UNOIDL singleton specification for it, for easy instantiation. * Plus new comphelper::getComponentContext to map from XMultiServiceFactory to XComponentContext. --- filter/source/config/cache/constant.hxx | 1 - filter/source/config/cache/filtercache.cxx | 10 ++-- filter/source/msfilter/msoleexp.cxx | 49 ++++++++--------- filter/source/pdf/pdfexport.cxx | 87 +++++++++++++++--------------- 4 files changed, 68 insertions(+), 79 deletions(-) (limited to 'filter') diff --git a/filter/source/config/cache/constant.hxx b/filter/source/config/cache/constant.hxx index 097f8aa1117e..32b91139fd39 100644 --- a/filter/source/config/cache/constant.hxx +++ b/filter/source/config/cache/constant.hxx @@ -182,7 +182,6 @@ extern rtl::OUString pFilterStrings[]; /** @short some uno service names. */ -#define SERVICE_CONFIGURATIONPROVIDER _FILTER_CONFIG_FROM_ASCII_("com.sun.star.configuration.ConfigurationProvider" ) #define SERVICE_CONFIGURATIONUPDATEACCESS _FILTER_CONFIG_FROM_ASCII_("com.sun.star.configuration.ConfigurationUpdateAccess" ) #define SERVICE_CONFIGURATIONACCESS _FILTER_CONFIG_FROM_ASCII_("com.sun.star.configuration.ConfigurationAccess" ) #define SERVICE_URLTRANSFORMER _FILTER_CONFIG_FROM_ASCII_("com.sun.star.util.URLTransformer" ) diff --git a/filter/source/config/cache/filtercache.cxx b/filter/source/config/cache/filtercache.cxx index 282ca5aa481c..eedd168a5771 100644 --- a/filter/source/config/cache/filtercache.cxx +++ b/filter/source/config/cache/filtercache.cxx @@ -41,9 +41,11 @@ //_______________________________________________ // includes +#include #include #include #include +#include #include #include #include @@ -962,13 +964,11 @@ css::uno::Reference< css::uno::XInterface > FilterCache::impl_createConfigAccess try { css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider( - m_xSMGR->createInstance(SERVICE_CONFIGURATIONPROVIDER), css::uno::UNO_QUERY); - - if (!xConfigProvider.is()) - return css::uno::Reference< css::uno::XInterface >(); + css::configuration::theDefaultProvider::get( + comphelper::getComponentContext(m_xSMGR))); ::comphelper::SequenceAsVector< css::uno::Any > lParams; - css::beans::PropertyValue aParam ; + css::beans::NamedValue aParam; // set root path aParam.Name = _FILTER_CONFIG_FROM_ASCII_("nodepath"); diff --git a/filter/source/msfilter/msoleexp.cxx b/filter/source/msfilter/msoleexp.cxx index c9c13ed4881a..0a682c83ddb4 100644 --- a/filter/source/msfilter/msoleexp.cxx +++ b/filter/source/msfilter/msoleexp.cxx @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -97,38 +98,30 @@ String GetStorageType( const SvGlobalName& aEmbName ) sal_Bool UseOldMSExport() { - uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); - - if ( xFactory.is() ) - { - uno::Reference< lang::XMultiServiceFactory > xProvider( xFactory->createInstance( - rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider"))), - uno::UNO_QUERY); - if ( xProvider.is() ) + uno::Reference< lang::XMultiServiceFactory > xProvider( + configuration::theDefaultProvider::get( + comphelper::getProcessComponentContext())); + try { + uno::Sequence< uno::Any > aArg( 1 ); + aArg[0] <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common/InternalMSExport") ); + uno::Reference< container::XNameAccess > xNameAccess( + xProvider->createInstanceWithArguments( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationUpdateAccess" ) ), + aArg ), + uno::UNO_QUERY ); + if ( xNameAccess.is() ) { - try { - uno::Sequence< uno::Any > aArg( 1 ); - aArg[0] <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common/InternalMSExport") ); - uno::Reference< container::XNameAccess > xNameAccess( - xProvider->createInstanceWithArguments( - rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationUpdateAccess" ) ), - aArg ), - uno::UNO_QUERY ); - if ( xNameAccess.is() ) - { - uno::Any aResult = xNameAccess->getByName( - rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseOldExport" ) ) ); + uno::Any aResult = xNameAccess->getByName( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseOldExport" ) ) ); - sal_Bool bResult = sal_Bool(); - if ( aResult >>= bResult ) - return bResult; - } - } - catch( uno::Exception& ) - { - } + sal_Bool bResult = sal_Bool(); + if ( aResult >>= bResult ) + return bResult; } } + catch( uno::Exception& ) + { + } OSL_FAIL( "Could not get access to configuration entry!\n" ); return sal_False; diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx index d5fd5864f74b..466132e2c612 100644 --- a/filter/source/pdf/pdfexport.cxx +++ b/filter/source/pdf/pdfexport.cxx @@ -62,6 +62,7 @@ #include "vcl/graphictools.hxx" #include "com/sun/star/beans/XPropertySet.hpp" +#include "com/sun/star/configuration/theDefaultProvider.hpp" #include "com/sun/star/awt/Rectangle.hpp" #include "com/sun/star/awt/XDevice.hpp" #include "com/sun/star/util/MeasureUnit.hpp" @@ -325,55 +326,51 @@ static OUString getMimetypeForDocument( const Reference< XMultiServiceFactory >& // get the actual filter name OUString aFilterName; Reference< lang::XMultiServiceFactory > xConfigProvider( - xFactory->createInstance( - OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) ) ), - uno::UNO_QUERY ); - if( xConfigProvider.is() ) + configuration::theDefaultProvider::get( + comphelper::getComponentContext( xFactory ) ) ); + uno::Sequence< uno::Any > aArgs( 1 ); + beans::NamedValue aPathProp; + aPathProp.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); + aPathProp.Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Setup/Office/Factories/" ) ); + aArgs[0] <<= aPathProp; + + Reference< container::XNameAccess > xSOFConfig( + xConfigProvider->createInstanceWithArguments( + OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" ) ), + aArgs ), + uno::UNO_QUERY ); + + Reference< container::XNameAccess > xApplConfig; + xSOFConfig->getByName( aDocServiceName ) >>= xApplConfig; + if ( xApplConfig.is() ) { - uno::Sequence< uno::Any > aArgs( 1 ); - beans::PropertyValue aPathProp; - aPathProp.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); - aPathProp.Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Setup/Office/Factories/" ) ); - aArgs[0] <<= aPathProp; - - Reference< container::XNameAccess > xSOFConfig( - xConfigProvider->createInstanceWithArguments( - OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" ) ), - aArgs ), + xApplConfig->getByName( OUString( RTL_CONSTASCII_USTRINGPARAM( "ooSetupFactoryActualFilter" ) ) ) >>= aFilterName; + if( aFilterName.getLength() ) + { + // find the related type name + OUString aTypeName; + Reference< container::XNameAccess > xFilterFactory( + xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" )) ), uno::UNO_QUERY ); - Reference< container::XNameAccess > xApplConfig; - xSOFConfig->getByName( aDocServiceName ) >>= xApplConfig; - if ( xApplConfig.is() ) - { - xApplConfig->getByName( OUString( RTL_CONSTASCII_USTRINGPARAM( "ooSetupFactoryActualFilter" ) ) ) >>= aFilterName; - if( aFilterName.getLength() ) + Sequence< beans::PropertyValue > aFilterData; + xFilterFactory->getByName( aFilterName ) >>= aFilterData; + for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ ) + if ( aFilterData[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) + aFilterData[nInd].Value >>= aTypeName; + + if ( aTypeName.getLength() ) { - // find the related type name - OUString aTypeName; - Reference< container::XNameAccess > xFilterFactory( - xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" )) ), - uno::UNO_QUERY ); - - Sequence< beans::PropertyValue > aFilterData; - xFilterFactory->getByName( aFilterName ) >>= aFilterData; - for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ ) - if ( aFilterData[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) - aFilterData[nInd].Value >>= aTypeName; - - if ( aTypeName.getLength() ) - { - // find the mediatype - Reference< container::XNameAccess > xTypeDetection( - xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.TypeDetection" )) ), - UNO_QUERY ); - - Sequence< beans::PropertyValue > aTypeData; - xTypeDetection->getByName( aTypeName ) >>= aTypeData; - for ( sal_Int32 nInd = 0; nInd < aTypeData.getLength(); nInd++ ) - if ( aTypeData[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) - aTypeData[nInd].Value >>= aDocMimetype; - } + // find the mediatype + Reference< container::XNameAccess > xTypeDetection( + xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.TypeDetection" )) ), + UNO_QUERY ); + + Sequence< beans::PropertyValue > aTypeData; + xTypeDetection->getByName( aTypeName ) >>= aTypeData; + for ( sal_Int32 nInd = 0; nInd < aTypeData.getLength(); nInd++ ) + if ( aTypeData[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) + aTypeData[nInd].Value >>= aDocMimetype; } } } -- cgit