diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-06-01 11:36:10 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-06-01 12:30:26 +0200 |
commit | b499739c438d58c29125cb2777f019c84394786d (patch) | |
tree | 5ec47605d3229190330f6c3bde953e787a8d0e08 /dbaccess | |
parent | aa25be596516d4acd831d89006fed78c4b974dac (diff) |
dbaccess: add support for storing ODatabaseDocument to a sub-storage
When Writer creates an embedded data source definition, it should be
stored on the storage of the Writer document, so Writer sets the
TargetStorage and StreamRelPath parameters of the storeAsURL() call.
Let ODatabaseDocument::impl_storeAs_throw() and
ODatabaseDocument::impl_writeStorage_throw() respect these, so the save
actually succeeds.
Change-Id: I4568ef96204a219b813142d7b5eebe9f1ec5e22e
Diffstat (limited to 'dbaccess')
-rw-r--r-- | dbaccess/source/core/dataaccess/databasedocument.cxx | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 1f801b7d51aa..84a592e0c6de 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -91,6 +91,7 @@ #include <list> #include <svtools/grfmgr.hxx> +#include <tools/urlobj.hxx> using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; @@ -487,6 +488,8 @@ namespace { OUString("BaseURI"), 0, ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 }, { OUString("StreamName"), 0, ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 }, { OUString("UsePrettyPrinting"), 0, ::cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::MAYBEVOID, 0}, + {OUString("TargetStorage"), 0, cppu::UnoType<embed::XStorage>::get(), beans::PropertyAttribute::MAYBEVOID, 0}, + {OUString("StreamRelPath"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0}, { OUString(), 0, css::uno::Type(), 0, 0 } }; } @@ -1074,7 +1077,15 @@ void ODatabaseDocument::impl_storeAs_throw( const OUString& _rURL, const ::comph if ( bLocationChanged ) { // create storage for target URL - Reference< XStorage > xTargetStorage( impl_createStorageFor_throw( _rURL ) ); + uno::Reference<embed::XStorage> xTargetStorage; + _rArguments.get("TargetStorage") >>= xTargetStorage; + if (!xTargetStorage.is()) + xTargetStorage = impl_createStorageFor_throw(_rURL); + + // In case we got a StreamRelPath, then xTargetStorage should reference that sub-storage. + OUString sStreamRelPath = _rArguments.getOrDefault("StreamRelPath", OUString()); + if (!sStreamRelPath.isEmpty()) + xTargetStorage = xTargetStorage->openStorageElement(sStreamRelPath, embed::ElementModes::READWRITE); if ( m_pImpl->isEmbeddedDatabase() ) m_pImpl->clearConnections(); @@ -1649,6 +1660,23 @@ void ODatabaseDocument::impl_writeStorage_throw( const Reference< XStorage >& _r if ( aSaveOpt.IsSaveRelFSys() ) xInfoSet->setPropertyValue("BaseURI", uno::makeAny(_rMediaDescriptor.getOrDefault("URL",OUString()))); + // Set TargetStorage, so it doesn't have to be re-constructed based on possibly empty URL. + xInfoSet->setPropertyValue("TargetStorage", uno::makeAny(m_pImpl->getRootStorage())); + + // Set StreamRelPath, in case this document is an embedded one. + OUString sStreamRelPath; + OUString sURL = _rMediaDescriptor.getOrDefault("URL", OUString()); + if (sURL.startsWithIgnoreAsciiCase("vnd.sun.star.pkg:")) + { + // In this case the host contains the real path, and the the path is the embedded stream name. + INetURLObject aURL(sURL); + sStreamRelPath = aURL.GetURLPath(INetURLObject::DECODE_WITH_CHARSET); + if (sStreamRelPath.startsWith("/")) + sStreamRelPath = sStreamRelPath.copy(1); + } + if (!sStreamRelPath.isEmpty()) + xInfoSet->setPropertyValue("StreamRelPath", uno::makeAny(sStreamRelPath)); + sal_Int32 nArgsLen = aDelegatorArguments.getLength(); aDelegatorArguments.realloc(nArgsLen+1); aDelegatorArguments[nArgsLen++] <<= xInfoSet; |