summaryrefslogtreecommitdiff
path: root/comphelper/source/misc/storagehelper.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'comphelper/source/misc/storagehelper.cxx')
-rw-r--r--comphelper/source/misc/storagehelper.cxx53
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: */