diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-06-09 11:40:02 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-06-09 12:08:18 +0200 |
commit | 2d7ff7aabc1aa8cf5bb4900ae4b00feb8bc0f7f7 (patch) | |
tree | 7ec489f7fb9c203acd21adf0e649f006cbfac0ff /sw | |
parent | f01f31201f9b26b3071ab25f9a5a3a0311ff7423 (diff) |
SwDocShell: custom copy for embedded data source definition on save-as
If "EmbeddedDatabase" in test.odt refers test.ods in the same directory,
that will be "../../test.ods". Now if we save test.odt in a different
directory, we need to re-save the embedded data source definition,
otherwise the relative reference will resolve to a non-existing path.
Relative references are normally not supported for embedded objects, so
this is not a problem, but for data sources they are, that's why they
are a special case here.
Change-Id: Id138b9cdc38f2de589d9b80c66f1a61174699770
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 8 | ||||
-rw-r--r-- | sw/source/uibase/app/docsh.cxx | 21 |
2 files changed, 29 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 666f0ac2f70d..d3f08e460dd8 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -1009,6 +1009,14 @@ void SwUiWriterTest::testEmbeddedDataSource() CPPUNIT_ASSERT(mxComponent.is()); CPPUNIT_ASSERT(xDatabaseContext->hasByName("calc-data-source")); + // Data source has a table named Sheet1 after saving to a different directory. + xDataSource.set(xDatabaseContext->getByName("calc-data-source"), uno::UNO_QUERY); + CPPUNIT_ASSERT(xDataSource.is()); + xConnection.set(xDataSource->getConnection("", ""), uno::UNO_QUERY); + xTables.set(xConnection->getTables(), uno::UNO_QUERY); + CPPUNIT_ASSERT(xTables.is()); + CPPUNIT_ASSERT(xTables->hasByName("Sheet1")); + // Close: should not have a data source anymore. mxComponent->dispose(); mxComponent.clear(); diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx index b4c22ace24d1..190135579344 100644 --- a/sw/source/uibase/app/docsh.cxx +++ b/sw/source/uibase/app/docsh.cxx @@ -115,12 +115,15 @@ #include <com/sun/star/document/XDocumentProperties.hpp> #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> +#include <com/sun/star/sdb/DatabaseContext.hpp> +#include <com/sun/star/sdb/XDocumentDataSource.hpp> #include <unomid.h> #include <unotextrange.hxx> #include <sfx2/Metadatable.hxx> #include <calbck.hxx> +#include <dbmgr.hxx> #include <sal/log.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> @@ -416,6 +419,24 @@ bool SwDocShell::SaveAs( SfxMedium& rMedium ) } CalcLayoutForOLEObjects(); // format for OLE objets + + if (!m_pDoc->GetDBManager()->getEmbeddedName().isEmpty()) + { + // We have an embedded data source definition, need to re-store it, + // otherwise relative references will break when the new file is in a + // different directory. + uno::Reference<sdb::XDatabaseContext> xDatabaseContext = sdb::DatabaseContext::create(comphelper::getProcessComponentContext()); + + const INetURLObject& rOldURLObject = GetMedium()->GetURLObject(); + OUString aURL = "vnd.sun.star.pkg://"; + aURL += INetURLObject::encode(rOldURLObject.GetMainURL(INetURLObject::DECODE_WITH_CHARSET), INetURLObject::PART_AUTHORITY, INetURLObject::ENCODE_ALL); + aURL += "/" + INetURLObject::encode(m_pDoc->GetDBManager()->getEmbeddedName(), INetURLObject::PART_FPATH, INetURLObject::ENCODE_ALL); + + uno::Reference<sdb::XDocumentDataSource> xDataSource(xDatabaseContext->getByName(aURL), uno::UNO_QUERY); + uno::Reference<frame::XStorable> xStorable(xDataSource->getDatabaseDocument(), uno::UNO_QUERY); + SwDBManager::StoreEmbeddedDataSource(xStorable, rMedium.GetOutputStorage(), m_pDoc->GetDBManager()->getEmbeddedName(), rMedium.GetName()); + } + // #i62875# // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible if (m_pWrtShell && |