[Libreoffice-commits] core.git: 3 commits - sfx2/source sw/inc sw/qa sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Tue Jun 9 03:09:28 PDT 2015
sfx2/source/doc/objstor.cxx | 1
sw/inc/dbmgr.hxx | 7 ++++++
sw/qa/extras/uiwriter/uiwriter.cxx | 8 ++++++
sw/source/uibase/app/docsh.cxx | 21 ++++++++++++++++++
sw/source/uibase/dbui/dbmgr.cxx | 43 +++++++++++++++++++------------------
5 files changed, 60 insertions(+), 20 deletions(-)
New commits:
commit 9805ae85eb776fa8f718c1415942c31f2cfc6d9e
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Jun 9 12:07:37 2015 +0200
sfx2: silence warning in SfxObjectShell::CopyStoragesOfUnknownMediaType()
I guess the intention is to catch all "own" formats, and Base is just
missing from that list.
Change-Id: I064068c2ab17db9109a9a4681775ba8d18292292
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index d431a1e..826d024 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -3484,6 +3484,7 @@ bool SfxObjectShell::CopyStoragesOfUnknownMediaType( const uno::Reference< embed
case SotClipboardFormatId::STARCALC_8:
case SotClipboardFormatId::STARCHART_8:
case SotClipboardFormatId::STARMATH_8:
+ case SotClipboardFormatId::STARBASE_8:
break;
default:
commit 2d7ff7aabc1aa8cf5bb4900ae4b00feb8bc0f7f7
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Jun 9 11:40:02 2015 +0200
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
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 666f0ac..d3f08e4 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 b4c22ac..1901355 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 &&
commit f01f31201f9b26b3071ab25f9a5a3a0311ff7423
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Jun 9 09:42:40 2015 +0200
SwDBManager: extract StoreEmbeddedDataSource() from registration code
Change-Id: Ifc6471f58793cde057f354c4c6a549c073b7d34b
diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index 007755d..5bf1542 100644
--- a/sw/inc/dbmgr.hxx
+++ b/sw/inc/dbmgr.hxx
@@ -28,6 +28,8 @@
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
namespace com{namespace sun{namespace star{
@@ -414,6 +416,11 @@ public:
void setEmbeddedName(const OUString& rEmbeddedName, SwDocShell& rDocShell);
OUString getEmbeddedName() const;
+
+ static void StoreEmbeddedDataSource(const css::uno::Reference<css::frame::XStorable>& xStorable,
+ const css::uno::Reference<css::embed::XStorage>& xStorage,
+ const OUString& rStreamRelPath,
+ const OUString& rOwnURL);
};
#endif
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index db52e41..ccd1372 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -2595,39 +2595,23 @@ OUString SwDBManager::LoadAndRegisterDataSource(const DBConnURITypes type, const
uno::Reference<frame::XStorable> xStore(xDS->getDatabaseDocument(), uno::UNO_QUERY_THROW);
OUString sOutputExt = ".odb";
OUString aOwnURL = lcl_getOwnURL(pDocShell);
- OUString sTmpName;
- uno::Sequence<beans::PropertyValue> aSequence;
if (aOwnURL.isEmpty())
{
// Cannot embed, as embedded data source would need the URL of the parent document.
OUString sHomePath(SvtPathOptions().GetWorkPath());
utl::TempFile aTempFile(sNewName, true, &sOutputExt, pDestDir ? pDestDir : &sHomePath);
aTempFile.EnableKillingFile(true);
- sTmpName = aTempFile.GetURL();
+ OUString sTmpName = aTempFile.GetURL();
+ xStore->storeAsURL(sTmpName, uno::Sequence<beans::PropertyValue>());
}
else
{
- // Embed: construct vnd.sun.star.pkg:// URL for later loading, and TargetStorage/StreamRelPath for storing.
+ // Embed.
OUString aStreamRelPath = "EmbeddedDatabase";
- sTmpName = "vnd.sun.star.pkg://";
- sTmpName += INetURLObject::encode(aOwnURL, INetURLObject::PART_AUTHORITY, INetURLObject::ENCODE_ALL);
- sTmpName += "/" + aStreamRelPath;
uno::Reference<embed::XStorage> xStorage = pDocShell->GetStorage();
- aSequence = comphelper::InitPropertySequence(
- {
- {"TargetStorage", uno::makeAny(xStorage)},
- {"StreamRelPath", uno::makeAny(aStreamRelPath)},
- {"BaseURI", uno::makeAny(aOwnURL)}
- });
-
- // Refer to the sub-storage name in the document settings, so
- // we can load it again next time the file is imported.
- uno::Reference<lang::XMultiServiceFactory> xFactory(pDocShell->GetModel(), uno::UNO_QUERY);
- uno::Reference<beans::XPropertySet> xPropertySet(xFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
- xPropertySet->setPropertyValue("EmbeddedDatabaseName", uno::makeAny(aStreamRelPath));
+ SwDBManager::StoreEmbeddedDataSource(xStore, xStorage, aStreamRelPath, aOwnURL);
}
- xStore->storeAsURL(sTmpName, aSequence);
}
xDBContext->registerObject( sFind, xNewInstance );
}
@@ -2638,6 +2622,25 @@ OUString SwDBManager::LoadAndRegisterDataSource(const DBConnURITypes type, const
return sFind;
}
+void SwDBManager::StoreEmbeddedDataSource(const uno::Reference<frame::XStorable>& xStorable,
+ const uno::Reference<embed::XStorage>& xStorage,
+ const OUString& rStreamRelPath,
+ const OUString& rOwnURL)
+{
+ // Construct vnd.sun.star.pkg:// URL for later loading, and TargetStorage/StreamRelPath for storing.
+ OUString sTmpName = "vnd.sun.star.pkg://";
+ sTmpName += INetURLObject::encode(rOwnURL, INetURLObject::PART_AUTHORITY, INetURLObject::ENCODE_ALL);
+ sTmpName += "/" + rStreamRelPath;
+
+ uno::Sequence<beans::PropertyValue> aSequence = comphelper::InitPropertySequence(
+ {
+ {"TargetStorage", uno::makeAny(xStorage)},
+ {"StreamRelPath", uno::makeAny(rStreamRelPath)},
+ {"BaseURI", uno::makeAny(rOwnURL)}
+ });
+ xStorable->storeAsURL(sTmpName, aSequence);
+}
+
OUString SwDBManager::LoadAndRegisterDataSource(const OUString &rURI, const OUString *pPrefix, const OUString *pDestDir,
const uno::Reference< beans::XPropertySet > *pSettings)
{
More information about the Libreoffice-commits
mailing list