comphelper/inc/comphelper/storagehelper.hxx | 177 ++++----- comphelper/source/misc/storagehelper.cxx | 511 ++++++++++++++-------------- 2 files changed, 356 insertions(+), 332 deletions(-)
New commits: commit e3648d4ebc7378cc31b6ce73716328f48b8903e5 Author: Matúš Kukan <matus.ku...@gmail.com> Date: Thu Aug 16 21:47:01 2012 +0200 Revert "Cleanup comphelper::storagehelper" This reverts commit 72777a66bb8d9e71c4786c282c7971d7ededa729. +using namespace com::sun::star::uno; in header is not a good idea Fails to compile and is hard to parse and figure out what was the point, so just reverting. Also +using rtl::OUString; is automatic nowadays whenever possible and RTL_CONSTASCII_USTRINGPARAM is obsoleted. Change-Id: I24cb24b7f1a6007734d26cbba41d46323cb55b18 diff --git a/comphelper/inc/comphelper/storagehelper.hxx b/comphelper/inc/comphelper/storagehelper.hxx index 5e4916e..f255dc8 100644 --- a/comphelper/inc/comphelper/storagehelper.hxx +++ b/comphelper/inc/comphelper/storagehelper.hxx @@ -33,20 +33,14 @@ #include <com/sun/star/io/XStream.hpp> #include "comphelper/comphelperdllapi.h" -using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star::embed; -using namespace com::sun::star::io; -using namespace com::sun::star::beans; -using rtl::OUString; -#define PACKAGE_STORAGE_FORMAT_STRING OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageFormat" ) ) -#define ZIP_STORAGE_FORMAT_STRING OUString( RTL_CONSTASCII_USTRINGPARAM( "ZipFormat" ) ) -#define OFOPXML_STORAGE_FORMAT_STRING OUString( RTL_CONSTASCII_USTRINGPARAM( "OFOPXMLFormat" ) ) +#define PACKAGE_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageFormat" ) ) +#define ZIP_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZipFormat" ) ) +#define OFOPXML_STORAGE_FORMAT_STRING ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OFOPXMLFormat" ) ) -#define PACKAGE_ENCRYPTIONDATA_SHA256UTF8 OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA256UTF8EncryptionKey" ) ) -#define PACKAGE_ENCRYPTIONDATA_SHA1UTF8 OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1UTF8EncryptionKey" ) ) -#define PACKAGE_ENCRYPTIONDATA_SHA1MS1252 OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1MS1252EncryptionKey" ) ) +#define PACKAGE_ENCRYPTIONDATA_SHA256UTF8 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA256UTF8EncryptionKey" ) ) +#define PACKAGE_ENCRYPTIONDATA_SHA1UTF8 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1UTF8EncryptionKey" ) ) +#define PACKAGE_ENCRYPTIONDATA_SHA1MS1252 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1MS1252EncryptionKey" ) ) namespace comphelper { @@ -69,120 +63,131 @@ public: class COMPHELPER_DLLPUBLIC OStorageHelper { public: - static Reference< XSingleServiceFactory > + static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > GetStorageFactory( - const Reference< XMultiServiceFactory >& xSF = Reference< XMultiServiceFactory >() ) - throw ( Exception ); + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSF + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) + throw ( ::com::sun::star::uno::Exception ); - static Reference< XSingleServiceFactory > + static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > GetFileSystemStorageFactory( - const Reference< XMultiServiceFactory >& xSF = Reference< XMultiServiceFactory >() ) - throw ( Exception ); + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSF + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) + throw ( ::com::sun::star::uno::Exception ); - static Reference< XStorage > + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetTemporaryStorage( - const Reference< XMultiServiceFactory >& xFactory = Reference< XMultiServiceFactory >() ) - throw ( Exception ); + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) + throw ( ::com::sun::star::uno::Exception ); - // this one will only return Storage - static Reference< XStorage > + /// this one will only return Storage + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetStorageFromURL( - const OUString& aURL, sal_Int32 nStorageMode, - const Reference< XMultiServiceFactory >& xFactory = Reference< XMultiServiceFactory >() ) - throw ( Exception ); + 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 >() ) + throw ( ::com::sun::star::uno::Exception ); - // this one will return either Storage or FileSystemStorage - static Reference< XStorage > + /// this one will return either Storage or FileSystemStorage + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetStorageFromURL2( - const OUString& aURL, sal_Int32 nStorageMode, - const Reference< XMultiServiceFactory >& xFactory = Reference< XMultiServiceFactory >() ) - throw ( Exception ); + 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 >() ) + + throw ( ::com::sun::star::uno::Exception ); - static Reference< XStorage > + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetStorageFromInputStream( - const Reference < XInputStream >& xStream, - const Reference< XMultiServiceFactory >& xFactory = Reference< XMultiServiceFactory >() ) - throw ( Exception ); + 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 >() ) + throw ( ::com::sun::star::uno::Exception ); - static Reference< XStorage > + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetStorageFromStream( - const Reference < XStream >& xStream, - sal_Int32 nStorageMode = ElementModes::READWRITE, - const Reference< XMultiServiceFactory >& xFactory = Reference< XMultiServiceFactory >() ) - throw ( Exception ); + 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 >() ) + throw ( ::com::sun::star::uno::Exception ); static void CopyInputToOutput( - const Reference< XInputStream >& xInput, - const Reference< XOutputStream >& xOutput ) - throw ( Exception ); + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInput, + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutput ) + throw ( ::com::sun::star::uno::Exception ); - static Reference< XInputStream > + static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetInputStreamFromURL( - const OUString& aURL, - const Reference< XMultiServiceFactory >& xFactory = Reference< XMultiServiceFactory >() ) - throw ( Exception ); + const ::rtl::OUString& aURL, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ) + throw ( ::com::sun::star::uno::Exception ); static void SetCommonStorageEncryptionData( - const Reference< XStorage >& xStorage, - const Sequence< NamedValue >& aEncryptionData ) - throw ( Exception ); + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) + throw ( ::com::sun::star::uno::Exception ); // the following method supports only storages of OOo formats static sal_Int32 GetXStorageFormat( - const Reference< XStorage >& xStorage ) - throw ( Exception ); + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ) + throw ( ::com::sun::star::uno::Exception ); - static Reference< XStorage > + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetStorageOfFormatFromURL( - const OUString& aFormat, - const OUString& aURL, + const ::rtl::OUString& aFormat, + const ::rtl::OUString& aURL, sal_Int32 nStorageMode, - const Reference< XMultiServiceFactory >& xFactory - = Reference< XMultiServiceFactory >(), + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >(), sal_Bool bRepairStorage = sal_False ) - throw ( Exception ); + throw ( ::com::sun::star::uno::Exception ); - static Reference< XStorage > + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetStorageOfFormatFromInputStream( - const OUString& aFormat, - const Reference < XInputStream >& xStream, - const Reference< XMultiServiceFactory >& xFactory - = Reference< XMultiServiceFactory >(), + 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 >(), sal_Bool bRepairStorage = sal_False ) - throw ( Exception ); + throw ( ::com::sun::star::uno::Exception ); - static Reference< XStorage > + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetStorageOfFormatFromStream( - const OUString& aFormat, - const Reference < XStream >& xStream, - sal_Int32 nStorageMode = ElementModes::READWRITE, - const Reference< XMultiServiceFactory >& xFactory = Reference< XMultiServiceFactory >(), + 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 >(), sal_Bool bRepairStorage = sal_False ) - throw ( Exception ); + throw ( ::com::sun::star::uno::Exception ); - static Sequence< NamedValue > + static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > CreatePackageEncryptionData( - const OUString& aPassword, - const Reference< XMultiServiceFactory >& xSF = Reference< XMultiServiceFactory >() ); + const ::rtl::OUString& aPassword, + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSF + = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() ); - static sal_Bool IsValidZipEntryFileName( const OUString& aName, sal_Bool bSlashAllowed ); + static sal_Bool IsValidZipEntryFileName( const ::rtl::OUString& aName, sal_Bool bSlashAllowed ); static sal_Bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, sal_Bool bSlashAllowed ); - static sal_Bool PathHasSegment( const OUString& aPath, const OUString& aSegment ); + static sal_Bool PathHasSegment( const ::rtl::OUString& aPath, const ::rtl::OUString& aSegment ); // Methods to allow easy use of hierachical names inside storages - static Reference< XStorage > GetStorageAtPath( - const Reference< XStorage > &xStorage, - const OUString& aPath, sal_uInt32 nOpenMode, LifecycleProxy &rNastiness ); - - static Reference< XStream > GetStreamAtPath( - const Reference< XStorage > &xStorage, - const OUString& aPath, sal_uInt32 nOpenMode, LifecycleProxy &rNastiness ); - - static Reference< XStream > GetStreamAtPackageURL( - const Reference< XStorage > &xStorage, - const OUString& rURL, sal_uInt32 const nOpenMode, + static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetStorageAtPath( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > &xStorage, + const ::rtl::OUString& aPath, sal_uInt32 nOpenMode, LifecycleProxy &rNastiness ); + static ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStreamAtPath( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > &xStorage, + const ::rtl::OUString& aPath, sal_uInt32 nOpenMode, LifecycleProxy &rNastiness ); + static ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStreamAtPackageURL( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > &xStorage, + const ::rtl::OUString& rURL, sal_uInt32 const nOpenMode, LifecycleProxy & rNastiness ); }; diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx index a339589..d43e689 100644 --- a/comphelper/source/misc/storagehelper.cxx +++ b/comphelper/source/misc/storagehelper.cxx @@ -40,177 +40,177 @@ #include <comphelper/storagehelper.hxx> -using namespace com::sun::star::io; -using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star::embed; -using namespace com::sun::star::beans; -using namespace com::sun::star::ucb; -using namespace com::sun::star::xml::crypto; -using rtl::OUString; -using rtl::OString; +using namespace ::com::sun::star; namespace comphelper { -Reference< XSingleServiceFactory > - OStorageHelper::GetStorageFactory(const Reference< XMultiServiceFactory >& xSF ) - throw ( Exception ) +// ---------------------------------------------------------------------- +uno::Reference< lang::XSingleServiceFactory > OStorageHelper::GetStorageFactory( + const uno::Reference< lang::XMultiServiceFactory >& xSF ) + throw ( uno::Exception ) { - Reference< XMultiServiceFactory > xFactory = xSF.is() ? xSF : ::comphelper::getProcessServiceFactory(); + uno::Reference< lang::XMultiServiceFactory > xFactory = xSF.is() ? xSF : ::comphelper::getProcessServiceFactory(); if ( !xFactory.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); - OUString sService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.StorageFactory")); + rtl::OUString sService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.StorageFactory")); - Reference < XSingleServiceFactory > xStorageFactory( - xFactory->createInstance(sService), UNO_QUERY); + uno::Reference < lang::XSingleServiceFactory > xStorageFactory( + xFactory->createInstance(sService), uno::UNO_QUERY); if ( !xStorageFactory.is() ) { - throw RuntimeException(OUString( + throw uno::RuntimeException(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Could not load: ")) + sService, - Reference< XInterface >()); + uno::Reference< uno::XInterface >()); } return xStorageFactory; } -Reference< XSingleServiceFactory > OStorageHelper::GetFileSystemStorageFactory( - const Reference< XMultiServiceFactory >& xSF ) - throw ( Exception ) +// ---------------------------------------------------------------------- +uno::Reference< lang::XSingleServiceFactory > OStorageHelper::GetFileSystemStorageFactory( + const uno::Reference< lang::XMultiServiceFactory >& xSF ) + throw ( uno::Exception ) { - Reference< XMultiServiceFactory > xFactory = xSF.is() ? xSF : ::comphelper::getProcessServiceFactory(); + uno::Reference< lang::XMultiServiceFactory > xFactory = xSF.is() ? xSF : ::comphelper::getProcessServiceFactory(); if ( !xFactory.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); - OUString sService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.FileSystemStorageFactory")); + rtl::OUString sService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.FileSystemStorageFactory")); - Reference < XSingleServiceFactory > xStorageFactory( - xFactory->createInstance(sService), UNO_QUERY); + uno::Reference < lang::XSingleServiceFactory > xStorageFactory( + xFactory->createInstance(sService), uno::UNO_QUERY); if ( !xStorageFactory.is() ) { - throw RuntimeException(OUString( + throw uno::RuntimeException(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Could not load: ")) + sService, - Reference< XInterface >()); + uno::Reference< uno::XInterface >()); } return xStorageFactory; } -Reference< XStorage > OStorageHelper::GetTemporaryStorage( - const Reference< XMultiServiceFactory >& xFactory ) - throw ( Exception ) +// ---------------------------------------------------------------------- +uno::Reference< embed::XStorage > OStorageHelper::GetTemporaryStorage( + const uno::Reference< lang::XMultiServiceFactory >& xFactory ) + throw ( uno::Exception ) { - Reference< XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstance(), - UNO_QUERY ); + uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstance(), + uno::UNO_QUERY ); if ( !xTempStorage.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); return xTempStorage; } -Reference< XStorage > OStorageHelper::GetStorageFromURL( - const OUString& aURL, +// ---------------------------------------------------------------------- +uno::Reference< embed::XStorage > OStorageHelper::GetStorageFromURL( + const ::rtl::OUString& aURL, sal_Int32 nStorageMode, - const Reference< XMultiServiceFactory >& xFactory ) - throw ( Exception ) + const uno::Reference< lang::XMultiServiceFactory >& xFactory ) + throw ( uno::Exception ) { - Sequence< Any > aArgs( 2 ); + uno::Sequence< uno::Any > aArgs( 2 ); aArgs[0] <<= aURL; aArgs[1] <<= nStorageMode; - Reference< XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ), - UNO_QUERY ); + uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ), + uno::UNO_QUERY ); if ( !xTempStorage.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); return xTempStorage; } -Reference< XStorage > OStorageHelper::GetStorageFromURL2( - const OUString& aURL, +// ---------------------------------------------------------------------- +uno::Reference< embed::XStorage > OStorageHelper::GetStorageFromURL2( + const ::rtl::OUString& aURL, sal_Int32 nStorageMode, - const Reference< XMultiServiceFactory >& xFactory ) - throw ( Exception ) + const uno::Reference< lang::XMultiServiceFactory >& xFactory ) + throw ( uno::Exception ) { - Sequence< Any > aArgs( 2 ); + uno::Sequence< uno::Any > aArgs( 2 ); aArgs[0] <<= aURL; aArgs[1] <<= nStorageMode; - Reference< XSingleServiceFactory > xFact; + uno::Reference< lang::XSingleServiceFactory > xFact; try { - ::ucbhelper::Content aCntnt( aURL, Reference< XCommandEnvironment > () ); - if (aCntnt.isDocument()) - { + ::ucbhelper::Content aCntnt( aURL, + uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); + if (aCntnt.isDocument()) { xFact = GetStorageFactory( xFactory ); - } - else - { + } else { xFact = GetFileSystemStorageFactory( xFactory ); } - } catch (Exception &) - { } + } catch (uno::Exception &) { } - if (!xFact.is()) throw RuntimeException(); + if (!xFact.is()) throw uno::RuntimeException(); - Reference< XStorage > xTempStorage( xFact->createInstanceWithArguments( aArgs ), UNO_QUERY ); + uno::Reference< embed::XStorage > xTempStorage( + xFact->createInstanceWithArguments( aArgs ), uno::UNO_QUERY ); if ( !xTempStorage.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); return xTempStorage; } -Reference< XStorage > OStorageHelper::GetStorageFromInputStream( - const Reference < XInputStream >& xStream, - const Reference< XMultiServiceFactory >& xFactory ) - throw ( Exception ) +// ---------------------------------------------------------------------- +uno::Reference< embed::XStorage > OStorageHelper::GetStorageFromInputStream( + const uno::Reference < io::XInputStream >& xStream, + const uno::Reference< lang::XMultiServiceFactory >& xFactory ) + throw ( uno::Exception ) { - Sequence< Any > aArgs( 2 ); + uno::Sequence< uno::Any > aArgs( 2 ); aArgs[0] <<= xStream; - aArgs[1] <<= ElementModes::READ; + aArgs[1] <<= embed::ElementModes::READ; - Reference< XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ), UNO_QUERY ); + uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ), + uno::UNO_QUERY ); if ( !xTempStorage.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); return xTempStorage; } -Reference< XStorage > OStorageHelper::GetStorageFromStream( - const Reference < XStream >& xStream, +// ---------------------------------------------------------------------- +uno::Reference< embed::XStorage > OStorageHelper::GetStorageFromStream( + const uno::Reference < io::XStream >& xStream, sal_Int32 nStorageMode, - const Reference< XMultiServiceFactory >& xFactory ) - throw ( Exception ) + const uno::Reference< lang::XMultiServiceFactory >& xFactory ) + throw ( uno::Exception ) { - Sequence< Any > aArgs( 2 ); + uno::Sequence< uno::Any > aArgs( 2 ); aArgs[0] <<= xStream; aArgs[1] <<= nStorageMode; - Reference< XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ), UNO_QUERY ); + uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ), + uno::UNO_QUERY ); if ( !xTempStorage.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); return xTempStorage; } +// ---------------------------------------------------------------------- void OStorageHelper::CopyInputToOutput( - const Reference< XInputStream >& xInput, - const Reference< XOutputStream >& xOutput ) - throw ( Exception ) + const uno::Reference< io::XInputStream >& xInput, + const uno::Reference< io::XOutputStream >& xOutput ) + throw ( uno::Exception ) { static const sal_Int32 nConstBufferSize = 32000; sal_Int32 nRead; - Sequence < sal_Int8 > aSequence ( nConstBufferSize ); + uno::Sequence < sal_Int8 > aSequence ( nConstBufferSize ); do { nRead = xInput->readBytes ( aSequence, nConstBufferSize ); if ( nRead < nConstBufferSize ) { - Sequence < sal_Int8 > aTempBuf ( aSequence.getConstArray(), nRead ); + uno::Sequence < sal_Int8 > aTempBuf ( aSequence.getConstArray(), nRead ); xOutput->writeBytes ( aTempBuf ); } else @@ -219,211 +219,223 @@ void OStorageHelper::CopyInputToOutput( while ( nRead == nConstBufferSize ); } -Reference< XInputStream > OStorageHelper::GetInputStreamFromURL( - const OUString& aURL, - const Reference< XMultiServiceFactory >& xSF ) - throw ( Exception ) +// ---------------------------------------------------------------------- +uno::Reference< io::XInputStream > OStorageHelper::GetInputStreamFromURL( + const ::rtl::OUString& aURL, + const uno::Reference< lang::XMultiServiceFactory >& xSF ) + throw ( uno::Exception ) { - Reference< XMultiServiceFactory > xFactory = xSF.is() ? xSF : ::comphelper::getProcessServiceFactory(); + uno::Reference< lang::XMultiServiceFactory > xFactory = xSF.is() ? xSF : ::comphelper::getProcessServiceFactory(); if ( !xFactory.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); - Reference < XSimpleFileAccess > xTempAccess( - xFactory->createInstance ( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" )) ), - UNO_QUERY ); + uno::Reference < ::com::sun::star::ucb::XSimpleFileAccess > xTempAccess( + xFactory->createInstance ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" )) ), + uno::UNO_QUERY ); if ( !xTempAccess.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); - Reference< XInputStream > xInputStream = xTempAccess->openFileRead( aURL ); + uno::Reference< io::XInputStream > xInputStream = xTempAccess->openFileRead( aURL ); if ( !xInputStream.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); return xInputStream; } +// ---------------------------------------------------------------------- void OStorageHelper::SetCommonStorageEncryptionData( - const Reference< XStorage >& xStorage, - const Sequence< NamedValue >& aEncryptionData ) - throw ( Exception ) + const uno::Reference< embed::XStorage >& xStorage, + const uno::Sequence< beans::NamedValue >& aEncryptionData ) + throw ( uno::Exception ) { - Reference< XEncryptionProtectedSource2 > xEncrSet( xStorage, UNO_QUERY ); + uno::Reference< embed::XEncryptionProtectedSource2 > xEncrSet( xStorage, uno::UNO_QUERY ); if ( !xEncrSet.is() ) - throw IOException(); // TODO + throw io::IOException(); // TODO xEncrSet->setEncryptionData( aEncryptionData ); } +// ---------------------------------------------------------------------- sal_Int32 OStorageHelper::GetXStorageFormat( - const Reference< XStorage >& xStorage ) - throw ( Exception ) + const uno::Reference< embed::XStorage >& xStorage ) + throw ( uno::Exception ) { - Reference< XPropertySet > xStorProps( xStorage, UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xStorProps( xStorage, uno::UNO_QUERY_THROW ); - OUString aMediaType; - xStorProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" )) ) >>= aMediaType; + ::rtl::OUString aMediaType; + xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" )) ) >>= aMediaType; sal_Int32 nResult = 0; // TODO/LATER: the filter configuration could be used to detect it later, or batter a special service - if ( aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_WRITER_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_WRITER_WEB_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_WRITER_GLOBAL_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_DRAW_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_IMPRESS_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_CALC_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_CHART_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_MATH_ASCII ) ) + if ( + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_WRITER_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_WRITER_WEB_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_WRITER_GLOBAL_ASCII) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_DRAW_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_IMPRESS_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_CALC_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_CHART_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_VND_SUN_XML_MATH_ASCII ) + ) { nResult = SOFFICE_FILEFORMAT_60; } - else if ( aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_REPORT_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_REPORT_CHART_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE_ASCII ) - || aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII ) ) + else + if ( + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_REPORT_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_REPORT_CHART_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_CHART_TEMPLATE_ASCII ) || + aMediaType.equalsIgnoreAsciiCaseAscii(MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_TEMPLATE_ASCII ) + ) { nResult = SOFFICE_FILEFORMAT_8; } else { // the mediatype is not known - throw IllegalTypeException(); + throw beans::IllegalTypeException(); } return nResult; } -Reference< XStorage > OStorageHelper::GetStorageOfFormatFromURL( - const OUString& aFormat, - const OUString& aURL, +// ---------------------------------------------------------------------- +uno::Reference< embed::XStorage > OStorageHelper::GetStorageOfFormatFromURL( + const ::rtl::OUString& aFormat, + const ::rtl::OUString& aURL, sal_Int32 nStorageMode, - const Reference< XMultiServiceFactory >& xFactory, + const uno::Reference< lang::XMultiServiceFactory >& xFactory, sal_Bool bRepairStorage ) - throw ( Exception ) + throw ( uno::Exception ) { - Sequence< PropertyValue > aProps( 1 ); - aProps[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) ); + uno::Sequence< beans::PropertyValue > aProps( 1 ); + aProps[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) ); aProps[0].Value <<= aFormat; - if ( bRepairStorage ) { aProps.realloc( 2 ); - aProps[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "RepairPackage" ) ); + aProps[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RepairPackage" ) ); aProps[1].Value <<= bRepairStorage; } - Sequence< Any > aArgs( 3 ); + uno::Sequence< uno::Any > aArgs( 3 ); aArgs[0] <<= aURL; aArgs[1] <<= nStorageMode; aArgs[2] <<= aProps; - Reference< XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ), UNO_QUERY ); + uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ), + uno::UNO_QUERY ); if ( !xTempStorage.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); return xTempStorage; } -Reference< XStorage > OStorageHelper::GetStorageOfFormatFromInputStream( - const OUString& aFormat, - const Reference < XInputStream >& xStream, - const Reference< XMultiServiceFactory >& xFactory, +// ---------------------------------------------------------------------- +uno::Reference< embed::XStorage > OStorageHelper::GetStorageOfFormatFromInputStream( + const ::rtl::OUString& aFormat, + const uno::Reference < io::XInputStream >& xStream, + const uno::Reference< lang::XMultiServiceFactory >& xFactory, sal_Bool bRepairStorage ) - throw ( Exception ) + throw ( uno::Exception ) { - Sequence< PropertyValue > aProps( 1 ); - aProps[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) ); + uno::Sequence< beans::PropertyValue > aProps( 1 ); + aProps[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) ); aProps[0].Value <<= aFormat; - if ( bRepairStorage ) { aProps.realloc( 2 ); - aProps[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "RepairPackage" ) ); + aProps[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RepairPackage" ) ); aProps[1].Value <<= bRepairStorage; } - Sequence< Any > aArgs( 3 ); + uno::Sequence< uno::Any > aArgs( 3 ); aArgs[0] <<= xStream; - aArgs[1] <<= ElementModes::READ; + aArgs[1] <<= embed::ElementModes::READ; aArgs[2] <<= aProps; - Reference< XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ), UNO_QUERY ); + uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ), + uno::UNO_QUERY ); if ( !xTempStorage.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); return xTempStorage; } -Reference< XStorage > OStorageHelper::GetStorageOfFormatFromStream( - const OUString& aFormat, - const Reference < XStream >& xStream, +// ---------------------------------------------------------------------- +uno::Reference< embed::XStorage > OStorageHelper::GetStorageOfFormatFromStream( + const ::rtl::OUString& aFormat, + const uno::Reference < io::XStream >& xStream, sal_Int32 nStorageMode, - const Reference< XMultiServiceFactory >& xFactory, + const uno::Reference< lang::XMultiServiceFactory >& xFactory, sal_Bool bRepairStorage ) - throw ( Exception ) + throw ( uno::Exception ) { - Sequence< PropertyValue > aProps( 1 ); - aProps[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) ); + uno::Sequence< beans::PropertyValue > aProps( 1 ); + aProps[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) ); aProps[0].Value <<= aFormat; - if ( bRepairStorage ) { aProps.realloc( 2 ); - aProps[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "RepairPackage" ) ); + aProps[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RepairPackage" ) ); aProps[1].Value <<= bRepairStorage; } - Sequence< Any > aArgs( 3 ); + uno::Sequence< uno::Any > aArgs( 3 ); aArgs[0] <<= xStream; aArgs[1] <<= nStorageMode; aArgs[2] <<= aProps; - Reference< XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ), UNO_QUERY ); + uno::Reference< embed::XStorage > xTempStorage( GetStorageFactory( xFactory )->createInstanceWithArguments( aArgs ), + uno::UNO_QUERY ); if ( !xTempStorage.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); return xTempStorage; } -Sequence< NamedValue > OStorageHelper::CreatePackageEncryptionData( const OUString& aPassword, const Reference< XMultiServiceFactory >& xSF ) +// ---------------------------------------------------------------------- +uno::Sequence< beans::NamedValue > OStorageHelper::CreatePackageEncryptionData( const ::rtl::OUString& aPassword, const uno::Reference< lang::XMultiServiceFactory >& xSF ) { // TODO/LATER: Should not the method be part of DocPasswordHelper? - Sequence< NamedValue > aEncryptionData; + uno::Sequence< beans::NamedValue > aEncryptionData; if ( !aPassword.isEmpty() ) { sal_Int32 nSha1Ind = 0; // generate SHA256 start key try { - Reference< XMultiServiceFactory > xFactory = xSF.is() ? xSF : ::comphelper::getProcessServiceFactory(); + uno::Reference< lang::XMultiServiceFactory > xFactory = xSF.is() ? xSF : ::comphelper::getProcessServiceFactory(); if ( !xFactory.is() ) - throw RuntimeException(); + throw uno::RuntimeException(); - Reference< XDigestContextSupplier > xDigestContextSupplier( xFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ), UNO_QUERY_THROW ); - Reference< XDigestContext > xDigestContext( xDigestContextSupplier->getDigestContext( DigestID::SHA256, Sequence< NamedValue >() ), UNO_SET_THROW ); + uno::Reference< xml::crypto::XDigestContextSupplier > xDigestContextSupplier( xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.crypto.NSSInitializer" ) ) ), uno::UNO_QUERY_THROW ); + uno::Reference< xml::crypto::XDigestContext > xDigestContext( xDigestContextSupplier->getDigestContext( xml::crypto::DigestID::SHA256, uno::Sequence< beans::NamedValue >() ), uno::UNO_SET_THROW ); - OString aUTF8Password( OUStringToOString( aPassword, RTL_TEXTENCODING_UTF8 ) ); - xDigestContext->updateDigest( Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aUTF8Password.getStr() ), aUTF8Password.getLength() ) ); - Sequence< sal_Int8 > aDigest = xDigestContext->finalizeDigestAndDispose(); + ::rtl::OString aUTF8Password( ::rtl::OUStringToOString( aPassword, RTL_TEXTENCODING_UTF8 ) ); + xDigestContext->updateDigest( uno::Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aUTF8Password.getStr() ), aUTF8Password.getLength() ) ); + uno::Sequence< sal_Int8 > aDigest = xDigestContext->finalizeDigestAndDispose(); aEncryptionData.realloc( ++nSha1Ind ); aEncryptionData[0].Name = PACKAGE_ENCRYPTIONDATA_SHA256UTF8; aEncryptionData[0].Value <<= aDigest; } - catch ( Exception& ) + catch ( uno::Exception& ) { OSL_ENSURE( false, "Can not create SHA256 digest!" ); } @@ -439,7 +451,7 @@ Sequence< NamedValue > OStorageHelper::CreatePackageEncryptionData( const OUStri for ( sal_Int32 nInd = 0; nInd < 2; nInd++ ) { - OString aByteStrPass = OUStringToOString( aPassword, pEncoding[nInd] ); + ::rtl::OString aByteStrPass = ::rtl::OUStringToOString( aPassword, pEncoding[nInd] ); sal_uInt8 pBuffer[RTL_DIGEST_LENGTH_SHA1]; rtlDigestError nError = rtl_digest_SHA1( aByteStrPass.getStr(), @@ -453,18 +465,20 @@ Sequence< NamedValue > OStorageHelper::CreatePackageEncryptionData( const OUStri break; } - aEncryptionData[nSha1Ind+nInd].Value <<= Sequence< sal_Int8 >( (sal_Int8*)pBuffer, RTL_DIGEST_LENGTH_SHA1 ); + aEncryptionData[nSha1Ind+nInd].Value <<= uno::Sequence< sal_Int8 >( (sal_Int8*)pBuffer, RTL_DIGEST_LENGTH_SHA1 ); } } return aEncryptionData; } -sal_Bool OStorageHelper::IsValidZipEntryFileName( const OUString& aName, sal_Bool bSlashAllowed ) +// ---------------------------------------------------------------------- +sal_Bool OStorageHelper::IsValidZipEntryFileName( const ::rtl::OUString& aName, sal_Bool bSlashAllowed ) { return IsValidZipEntryFileName( aName.getStr(), aName.getLength(), bSlashAllowed ); } +// ---------------------------------------------------------------------- sal_Bool OStorageHelper::IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, sal_Bool bSlashAllowed ) { @@ -492,7 +506,8 @@ sal_Bool OStorageHelper::IsValidZipEntryFileName( return sal_True; } -sal_Bool OStorageHelper::PathHasSegment( const OUString& aPath, const OUString& aSegment ) +// ---------------------------------------------------------------------- +sal_Bool OStorageHelper::PathHasSegment( const ::rtl::OUString& aPath, const ::rtl::OUString& aSegment ) { sal_Bool bResult = sal_False; const sal_Int32 nPathLen = aPath.getLength(); @@ -500,11 +515,11 @@ sal_Bool OStorageHelper::PathHasSegment( const OUString& aPath, const OUString& if ( !aSegment.isEmpty() && nPathLen >= nSegLen ) { - OUString aEndSegment( RTL_CONSTASCII_USTRINGPARAM( "/" ) ); + ::rtl::OUString aEndSegment( RTL_CONSTASCII_USTRINGPARAM( "/" ) ); aEndSegment += aSegment; - OUString aInternalSegment( aEndSegment ); - aInternalSegment += OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ); + ::rtl::OUString aInternalSegment( aEndSegment ); + aInternalSegment += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ); if ( aPath.indexOf( aInternalSegment ) >= 0 ) bResult = sal_True; @@ -522,85 +537,89 @@ sal_Bool OStorageHelper::PathHasSegment( const OUString& aPath, const OUString& return bResult; } -class LifecycleProxy::Impl : public std::vector< Reference< XStorage > > {}; +class LifecycleProxy::Impl + : public std::vector< uno::Reference< embed::XStorage > > {}; +LifecycleProxy::LifecycleProxy() + : m_pBadness( new Impl() ) { } +LifecycleProxy::~LifecycleProxy() { } - LifecycleProxy::LifecycleProxy() : m_pBadness( new Impl() ) { } - LifecycleProxy::~LifecycleProxy() { } - - void LifecycleProxy::commitStorages() +void LifecycleProxy::commitStorages() +{ + for (Impl::reverse_iterator iter = m_pBadness->rbegin(); + iter != m_pBadness->rend(); ++iter) // reverse order (outwards) { - for (Impl::reverse_iterator iter = m_pBadness->rbegin(); - iter != m_pBadness->rend(); ++iter) // reverse order (outwards) + uno::Reference<embed::XTransactedObject> const xTransaction(*iter, + uno::UNO_QUERY); + if (xTransaction.is()) { - Reference<XTransactedObject> const xTransaction(*iter, UNO_QUERY); - if (xTransaction.is()) - xTransaction->commit(); + xTransaction->commit(); } } +} - static void splitPath( std::vector<OUString> &rElems, - const OUString& rPath ) - { - for (sal_Int32 i = 0; i >= 0;) - rElems.push_back( rPath.getToken( 0, '/', i ) ); - } +static void splitPath( std::vector<rtl::OUString> &rElems, + const ::rtl::OUString& rPath ) +{ + for (sal_Int32 i = 0; i >= 0;) + rElems.push_back( rPath.getToken( 0, '/', i ) ); +} - static Reference< XStorage > LookupStorageAtPath( - const Reference< XStorage > &xParentStorage, - std::vector<OUString> &rElems, sal_uInt32 nOpenMode, - LifecycleProxy &rNastiness ) +static uno::Reference< embed::XStorage > LookupStorageAtPath( + const uno::Reference< embed::XStorage > &xParentStorage, + std::vector<rtl::OUString> &rElems, sal_uInt32 nOpenMode, + LifecycleProxy &rNastiness ) +{ + uno::Reference< embed::XStorage > xStorage( xParentStorage ); + rNastiness.m_pBadness->push_back( xStorage ); + for( size_t i = 0; i < rElems.size() && xStorage.is(); i++ ) { - Reference< XStorage > xStorage( xParentStorage ); + xStorage = xStorage->openStorageElement( rElems[i], nOpenMode ); rNastiness.m_pBadness->push_back( xStorage ); - for( size_t i = 0; i < rElems.size() && xStorage.is(); i++ ) - { - xStorage = xStorage->openStorageElement( rElems[i], nOpenMode ); - rNastiness.m_pBadness->push_back( xStorage ); - } - return xStorage; } + return xStorage; +} - Reference< XStorage > OStorageHelper::GetStorageAtPath( - const Reference< XStorage > &xStorage, - const OUString& rPath, sal_uInt32 nOpenMode, - LifecycleProxy &rNastiness ) - { - std::vector<OUString> aElems; - splitPath( aElems, rPath ); - return LookupStorageAtPath( xStorage, aElems, nOpenMode, rNastiness ); - } +uno::Reference< embed::XStorage > OStorageHelper::GetStorageAtPath( + const uno::Reference< embed::XStorage > &xStorage, + const ::rtl::OUString& rPath, sal_uInt32 nOpenMode, + LifecycleProxy &rNastiness ) +{ + std::vector<rtl::OUString> aElems; + splitPath( aElems, rPath ); + return LookupStorageAtPath( xStorage, aElems, nOpenMode, rNastiness ); +} - Reference< XStream > OStorageHelper::GetStreamAtPath( - const Reference< XStorage > &xParentStorage, - const OUString& rPath, sal_uInt32 nOpenMode, - LifecycleProxy &rNastiness ) - { - std::vector<OUString> aElems; - splitPath( aElems, rPath ); - OUString aName( aElems.back() ); - aElems.pop_back(); - sal_uInt32 nStorageMode = nOpenMode & ~ElementModes::TRUNCATE; - Reference< XStorage > xStorage( - LookupStorageAtPath( xParentStorage, aElems, nStorageMode, rNastiness ), - UNO_QUERY_THROW ); - return xStorage->openStreamElement( aName, nOpenMode ); - } +uno::Reference< io::XStream > OStorageHelper::GetStreamAtPath( + const uno::Reference< embed::XStorage > &xParentStorage, + const ::rtl::OUString& rPath, sal_uInt32 nOpenMode, + LifecycleProxy &rNastiness ) +{ + std::vector<rtl::OUString> aElems; + splitPath( aElems, rPath ); + rtl::OUString aName( aElems.back() ); + aElems.pop_back(); + sal_uInt32 nStorageMode = nOpenMode & ~embed::ElementModes::TRUNCATE; + uno::Reference< embed::XStorage > xStorage( + LookupStorageAtPath( xParentStorage, aElems, nStorageMode, rNastiness ), + uno::UNO_QUERY_THROW ); + return xStorage->openStreamElement( aName, nOpenMode ); +} - Reference< XStream > OStorageHelper::GetStreamAtPackageURL( - Reference< XStorage > const& xParentStorage, - const OUString& rURL, sal_uInt32 const nOpenMode, - LifecycleProxy & rNastiness) +uno::Reference< io::XStream > OStorageHelper::GetStreamAtPackageURL( + uno::Reference< embed::XStorage > const& xParentStorage, + const ::rtl::OUString& rURL, sal_uInt32 const nOpenMode, + LifecycleProxy & rNastiness) +{ + static char const s_PkgScheme[] = "vnd.sun.star.Package:"; + if (0 == rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( + rURL.getStr(), rURL.getLength(), + s_PkgScheme, SAL_N_ELEMENTS(s_PkgScheme) - 1)) { - static char const s_PkgScheme[] = "vnd.sun.star.Package:"; - if (0 == rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( - rURL.getStr(), rURL.getLength(), - s_PkgScheme, SAL_N_ELEMENTS(s_PkgScheme) - 1)) - { - OUString const path(rURL.copy(SAL_N_ELEMENTS(s_PkgScheme)-1)); - return GetStreamAtPath(xParentStorage, path, nOpenMode, rNastiness); - } - return 0; + ::rtl::OUString const path(rURL.copy(SAL_N_ELEMENTS(s_PkgScheme)-1)); + return GetStreamAtPath(xParentStorage, path, nOpenMode, rNastiness); } + return 0; +} }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits