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
This commit is contained in:
parent
f01f31201f
commit
2d7ff7aabc
@ -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();
|
||||
|
@ -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 &&
|
||||
|
Loading…
x
Reference in New Issue
Block a user