diff options
author | Michael Meeks <michael.meeks@novell.com> | 2011-08-26 16:58:07 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@novell.com> | 2011-08-26 17:11:24 +0100 |
commit | d7e0e737c103ebc145cdf4c6afc182dafe0fcd47 (patch) | |
tree | f917a7c21101271d7c86a5131f38d930875f2562 /comphelper/source | |
parent | Header/Footer: Change the edition mode entering (diff) | |
download | core-d7e0e737c103ebc145cdf4c6afc182dafe0fcd47.tar.gz core-d7e0e737c103ebc145cdf4c6afc182dafe0fcd47.zip |
add a helper class to do path resolution
includes horrible lifecycle stack workaround for free.
Diffstat (limited to 'comphelper/source')
-rw-r--r-- | comphelper/source/misc/storagehelper.cxx | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx index 70b7852b579a..52b8e677f5ab 100644 --- a/comphelper/source/misc/storagehelper.cxx +++ b/comphelper/source/misc/storagehelper.cxx @@ -39,6 +39,7 @@ #include <com/sun/star/xml/crypto/XDigestContextSupplier.hpp> #include <com/sun/star/xml/crypto/DigestID.hpp> +#include <vector> #include <rtl/digest.h> #include <ucbhelper/content.hxx> @@ -536,6 +537,58 @@ sal_Bool OStorageHelper::PathHasSegment( const ::rtl::OUString& aPath, const ::r return bResult; } +class OStorageHelper::LifecycleProxyImpl : public std::vector< uno::Reference< embed::XStorage > > {}; +OStorageHelper::LifecycleProxy::LifecycleProxy() : + pBadness( new OStorageHelper::LifecycleProxyImpl() ) { } +OStorageHelper::LifecycleProxy::~LifecycleProxy() { delete pBadness; } + +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 uno::Reference< embed::XStorage > LookupStorageAtPath( + const uno::Reference< embed::XStorage > &xParentStorage, + std::vector<rtl::OUString> &rElems, sal_uInt32 nOpenMode, + OStorageHelper::LifecycleProxy &rNastiness ) +{ + uno::Reference< embed::XStorage > xStorage( xParentStorage ); + rNastiness.pBadness->push_back( xStorage ); + for( size_t i = 0; i < rElems.size() && xStorage.is(); i++ ) + { + xStorage = xStorage->openStorageElement( rElems[i], nOpenMode ); + rNastiness.pBadness->push_back( xStorage ); + } + return xStorage; +} + +uno::Reference< embed::XStorage > OStorageHelper::GetStorageAtPath( + const uno::Reference< embed::XStorage > &xStorage, + const ::rtl::OUString& rPath, sal_uInt32 nOpenMode, + OStorageHelper::LifecycleProxy &rNastiness ) +{ + std::vector<rtl::OUString> aElems; + splitPath( aElems, rPath ); + return LookupStorageAtPath( xStorage, aElems, nOpenMode, rNastiness ); +} + +uno::Reference< io::XStream > OStorageHelper::GetStreamAtPath( + const uno::Reference< embed::XStorage > &xParentStorage, + const ::rtl::OUString& rPath, sal_uInt32 nOpenMode, + OStorageHelper::LifecycleProxy &rNastiness ) +{ + std::vector<rtl::OUString> aElems; + splitPath( aElems, rPath ); + rtl::OUString aName( aElems.back() ); + aElems.pop_back(); + uno::Reference< embed::XStorage > xStorage( + LookupStorageAtPath( xParentStorage, aElems, nOpenMode, rNastiness ), + uno::UNO_QUERY_THROW ); + return xStorage->openStreamElement( aName, nOpenMode ); +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |