diff options
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/source/misc/storagehelper.cxx | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx index bd1e1ac48d17..177d974f8cb4 100644 --- a/comphelper/source/misc/storagehelper.cxx +++ b/comphelper/source/misc/storagehelper.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: storagehelper.cxx,v $ - * $Revision: 1.12 $ + * $Revision: 1.13 $ * * This file is part of OpenOffice.org. * @@ -37,12 +37,15 @@ #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/IllegalTypeException.hpp> +#include <ucbhelper/content.hxx> + #include <comphelper/fileformat.h> #include <comphelper/processfactory.hxx> #include <comphelper/documentconstants.hxx> #include <comphelper/storagehelper.hxx> + using namespace ::com::sun::star; namespace comphelper { @@ -67,6 +70,25 @@ uno::Reference< lang::XSingleServiceFactory > OStorageHelper::GetStorageFactory( } // ---------------------------------------------------------------------- +uno::Reference< lang::XSingleServiceFactory > OStorageHelper::GetFileSystemStorageFactory( + const uno::Reference< lang::XMultiServiceFactory >& xSF ) + throw ( uno::Exception ) +{ + uno::Reference< lang::XMultiServiceFactory > xFactory = xSF.is() ? xSF : ::comphelper::getProcessServiceFactory(); + if ( !xFactory.is() ) + throw uno::RuntimeException(); + + uno::Reference < lang::XSingleServiceFactory > xStorageFactory( + xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.embed.FileSystemStorageFactory" ) ), + uno::UNO_QUERY ); + + if ( !xStorageFactory.is() ) + throw uno::RuntimeException(); + + return xStorageFactory; +} + +// ---------------------------------------------------------------------- uno::Reference< embed::XStorage > OStorageHelper::GetTemporaryStorage( const uno::Reference< lang::XMultiServiceFactory >& xFactory ) throw ( uno::Exception ) @@ -99,6 +121,38 @@ uno::Reference< embed::XStorage > OStorageHelper::GetStorageFromURL( } // ---------------------------------------------------------------------- +uno::Reference< embed::XStorage > OStorageHelper::GetStorageFromURL2( + const ::rtl::OUString& aURL, + sal_Int32 nStorageMode, + const uno::Reference< lang::XMultiServiceFactory >& xFactory ) + throw ( uno::Exception ) +{ + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[0] <<= aURL; + aArgs[1] <<= nStorageMode; + + uno::Reference< lang::XSingleServiceFactory > xFact; + try { + ::ucbhelper::Content aCntnt( aURL, + uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); + if (aCntnt.isDocument()) { + xFact = GetStorageFactory( xFactory ); + } else { + xFact = GetFileSystemStorageFactory( xFactory ); + } + } catch (uno::Exception &) { } + + if (!xFact.is()) throw uno::RuntimeException(); + + uno::Reference< embed::XStorage > xTempStorage( + xFact->createInstanceWithArguments( aArgs ), uno::UNO_QUERY ); + if ( !xTempStorage.is() ) + throw uno::RuntimeException(); + + return xTempStorage; +} + +// ---------------------------------------------------------------------- uno::Reference< embed::XStorage > OStorageHelper::GetStorageFromInputStream( const uno::Reference < io::XInputStream >& xStream, const uno::Reference< lang::XMultiServiceFactory >& xFactory ) |