summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2012-12-03 16:33:30 +0200
committerNoel Grandin <noel@peralex.com>2012-12-10 08:05:53 +0200
commit24f0aa76c005d1506a6d13945c39dafc6e9b8d91 (patch)
treede84b05444d3436ed107bc4fb7d3522284e69529 /comphelper
parentb9a4a0b9658015a0d55c42de1f5e56941e20d268 (diff)
fdo#46808, use service constructor for embed::StorageFactory
Change-Id: I26cd1cf86118122f392f16801a646df753a7df26
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/inc/comphelper/storagehelper.hxx32
-rw-r--r--comphelper/source/misc/storagehelper.cxx51
2 files changed, 35 insertions, 48 deletions
diff --git a/comphelper/inc/comphelper/storagehelper.hxx b/comphelper/inc/comphelper/storagehelper.hxx
index f26f997cc2f3..e98a40727688 100644
--- a/comphelper/inc/comphelper/storagehelper.hxx
+++ b/comphelper/inc/comphelper/storagehelper.hxx
@@ -71,8 +71,8 @@ class COMPHELPER_DLLPUBLIC OStorageHelper
public:
static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >
GetStorageFactory(
- const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSF
- = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
+ const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext
+ = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >() )
throw ( ::com::sun::star::uno::Exception );
static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >
@@ -83,8 +83,8 @@ public:
static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
GetTemporaryStorage(
- const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
- = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
+ const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext
+ = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >() )
throw ( ::com::sun::star::uno::Exception );
/// this one will only return Storage
@@ -92,8 +92,8 @@ public:
GetStorageFromURL(
const ::rtl::OUString& aURL,
sal_Int32 nStorageMode,
- const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
- = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
+ const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xrxContext
+ = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >() )
throw ( ::com::sun::star::uno::Exception );
/// this one will return either Storage or FileSystemStorage
@@ -109,16 +109,16 @@ public:
static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
GetStorageFromInputStream(
const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xStream,
- const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
- = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
+ const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext
+ = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >() )
throw ( ::com::sun::star::uno::Exception );
static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
GetStorageFromStream(
const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream >& xStream,
sal_Int32 nStorageMode = ::com::sun::star::embed::ElementModes::READWRITE,
- const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
- = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
+ const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext
+ = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >() )
throw ( ::com::sun::star::uno::Exception );
static void CopyInputToOutput(
@@ -147,8 +147,8 @@ public:
const ::rtl::OUString& aFormat,
const ::rtl::OUString& aURL,
sal_Int32 nStorageMode,
- const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
- = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >(),
+ const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext
+ = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >(),
sal_Bool bRepairStorage = sal_False )
throw ( ::com::sun::star::uno::Exception );
@@ -156,8 +156,8 @@ public:
GetStorageOfFormatFromInputStream(
const ::rtl::OUString& aFormat,
const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xStream,
- const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
- = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >(),
+ const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext
+ = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >(),
sal_Bool bRepairStorage = sal_False )
throw ( ::com::sun::star::uno::Exception );
@@ -166,8 +166,8 @@ public:
const ::rtl::OUString& aFormat,
const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream >& xStream,
sal_Int32 nStorageMode = ::com::sun::star::embed::ElementModes::READWRITE,
- const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
- = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >(),
+ const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext
+ = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >(),
sal_Bool bRepairStorage = sal_False )
throw ( ::com::sun::star::uno::Exception );
diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx
index e4a1048622c7..888a8b3596f0 100644
--- a/comphelper/source/misc/storagehelper.cxx
+++ b/comphelper/source/misc/storagehelper.cxx
@@ -21,6 +21,7 @@
#include <com/sun/star/embed/XEncryptionProtectedSource2.hpp>
#include <com/sun/star/embed/XStorage.hpp>
#include <com/sun/star/embed/XTransactedObject.hpp>
+#include <com/sun/star/embed/StorageFactory.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/ucb/SimpleFileAccess.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
@@ -49,26 +50,12 @@ namespace comphelper {
// ----------------------------------------------------------------------
uno::Reference< lang::XSingleServiceFactory > OStorageHelper::GetStorageFactory(
- const uno::Reference< lang::XMultiServiceFactory >& xSF )
+ const uno::Reference< uno::XComponentContext >& rxContext )
throw ( uno::Exception )
{
- uno::Reference< lang::XMultiServiceFactory > xFactory = xSF.is() ? xSF : ::comphelper::getProcessServiceFactory();
- if ( !xFactory.is() )
- throw uno::RuntimeException();
-
- rtl::OUString sService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.StorageFactory"));
-
- uno::Reference < lang::XSingleServiceFactory > xStorageFactory(
- xFactory->createInstance(sService), uno::UNO_QUERY);
-
- if ( !xStorageFactory.is() )
- {
- throw uno::RuntimeException(rtl::OUString(
- RTL_CONSTASCII_USTRINGPARAM("Could not load: ")) + sService,
- uno::Reference< uno::XInterface >());
- }
+ uno::Reference< uno::XComponentContext> xContext = rxContext.is() ? rxContext : ::comphelper::getProcessComponentContext();
- return xStorageFactory;
+ return embed::StorageFactory::create( xContext );
}
// ----------------------------------------------------------------------
@@ -97,10 +84,10 @@ uno::Reference< lang::XSingleServiceFactory > OStorageHelper::GetFileSystemStora
// ----------------------------------------------------------------------
uno::Reference< embed::XStorage > OStorageHelper::GetTemporaryStorage(
- const uno::Reference< lang::XMultiServiceFactory >& xFactory )
+ const uno::Reference< uno::XComponentContext >& rxContext )
throw ( uno::Exception )
{
- uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstance(),
+ uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( rxContext )->createInstance(),
uno::UNO_QUERY );
if ( !xTempStorage.is() )
throw uno::RuntimeException();
@@ -112,14 +99,14 @@ uno::Reference< embed::XStorage > OStorageHelper::GetTemporaryStorage(
uno::Reference< embed::XStorage > OStorageHelper::GetStorageFromURL(
const ::rtl::OUString& aURL,
sal_Int32 nStorageMode,
- const uno::Reference< lang::XMultiServiceFactory >& xFactory )
+ const uno::Reference< uno::XComponentContext >& rxContext )
throw ( uno::Exception )
{
uno::Sequence< uno::Any > aArgs( 2 );
aArgs[0] <<= aURL;
aArgs[1] <<= nStorageMode;
- uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ),
+ uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( rxContext )->createInstanceWithArguments( aArgs ),
uno::UNO_QUERY );
if ( !xTempStorage.is() )
throw uno::RuntimeException();
@@ -144,7 +131,7 @@ uno::Reference< embed::XStorage > OStorageHelper::GetStorageFromURL2(
uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > (),
getProcessComponentContext() );
if (aCntnt.isDocument()) {
- xFact = GetStorageFactory( xFactory );
+ xFact = GetStorageFactory( comphelper::getComponentContext(xFactory) );
} else {
xFact = GetFileSystemStorageFactory( xFactory );
}
@@ -163,14 +150,14 @@ uno::Reference< embed::XStorage > OStorageHelper::GetStorageFromURL2(
// ----------------------------------------------------------------------
uno::Reference< embed::XStorage > OStorageHelper::GetStorageFromInputStream(
const uno::Reference < io::XInputStream >& xStream,
- const uno::Reference< lang::XMultiServiceFactory >& xFactory )
+ const uno::Reference< uno::XComponentContext >& rxContext )
throw ( uno::Exception )
{
uno::Sequence< uno::Any > aArgs( 2 );
aArgs[0] <<= xStream;
aArgs[1] <<= embed::ElementModes::READ;
- uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ),
+ uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( rxContext )->createInstanceWithArguments( aArgs ),
uno::UNO_QUERY );
if ( !xTempStorage.is() )
throw uno::RuntimeException();
@@ -182,14 +169,14 @@ uno::Reference< embed::XStorage > OStorageHelper::GetStorageFromInputStream(
uno::Reference< embed::XStorage > OStorageHelper::GetStorageFromStream(
const uno::Reference < io::XStream >& xStream,
sal_Int32 nStorageMode,
- const uno::Reference< lang::XMultiServiceFactory >& xFactory )
+ const uno::Reference< uno::XComponentContext >& rxContext )
throw ( uno::Exception )
{
uno::Sequence< uno::Any > aArgs( 2 );
aArgs[0] <<= xStream;
aArgs[1] <<= nStorageMode;
- uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ),
+ uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( rxContext )->createInstanceWithArguments( aArgs ),
uno::UNO_QUERY );
if ( !xTempStorage.is() )
throw uno::RuntimeException();
@@ -311,7 +298,7 @@ uno::Reference< embed::XStorage > OStorageHelper::GetStorageOfFormatFromURL(
const ::rtl::OUString& aFormat,
const ::rtl::OUString& aURL,
sal_Int32 nStorageMode,
- const uno::Reference< lang::XMultiServiceFactory >& xFactory,
+ const uno::Reference< uno::XComponentContext >& rxContext,
sal_Bool bRepairStorage )
throw ( uno::Exception )
{
@@ -330,7 +317,7 @@ uno::Reference< embed::XStorage > OStorageHelper::GetStorageOfFormatFromURL(
aArgs[1] <<= nStorageMode;
aArgs[2] <<= aProps;
- uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ),
+ uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( rxContext )->createInstanceWithArguments( aArgs ),
uno::UNO_QUERY );
if ( !xTempStorage.is() )
throw uno::RuntimeException();
@@ -342,7 +329,7 @@ uno::Reference< embed::XStorage > OStorageHelper::GetStorageOfFormatFromURL(
uno::Reference< embed::XStorage > OStorageHelper::GetStorageOfFormatFromInputStream(
const ::rtl::OUString& aFormat,
const uno::Reference < io::XInputStream >& xStream,
- const uno::Reference< lang::XMultiServiceFactory >& xFactory,
+ const uno::Reference< uno::XComponentContext >& rxContext,
sal_Bool bRepairStorage )
throw ( uno::Exception )
{
@@ -361,7 +348,7 @@ uno::Reference< embed::XStorage > OStorageHelper::GetStorageOfFormatFromInputStr
aArgs[1] <<= embed::ElementModes::READ;
aArgs[2] <<= aProps;
- uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ),
+ uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( rxContext )->createInstanceWithArguments( aArgs ),
uno::UNO_QUERY );
if ( !xTempStorage.is() )
throw uno::RuntimeException();
@@ -374,7 +361,7 @@ uno::Reference< embed::XStorage > OStorageHelper::GetStorageOfFormatFromStream(
const ::rtl::OUString& aFormat,
const uno::Reference < io::XStream >& xStream,
sal_Int32 nStorageMode,
- const uno::Reference< lang::XMultiServiceFactory >& xFactory,
+ const uno::Reference< uno::XComponentContext >& rxContext,
sal_Bool bRepairStorage )
throw ( uno::Exception )
{
@@ -393,7 +380,7 @@ uno::Reference< embed::XStorage > OStorageHelper::GetStorageOfFormatFromStream(
aArgs[1] <<= nStorageMode;
aArgs[2] <<= aProps;
- uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ),
+ uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( rxContext )->createInstanceWithArguments( aArgs ),
uno::UNO_QUERY );
if ( !xTempStorage.is() )
throw uno::RuntimeException();