[Libreoffice-commits] core.git: sw/inc sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Fri May 8 06:28:09 PDT 2015
sw/inc/dbmgr.hxx | 4 ++++
sw/source/core/doc/doc.cxx | 4 ++++
sw/source/uibase/dbui/dbmgr.cxx | 14 ++++++++++++++
3 files changed, 22 insertions(+)
New commits:
commit 358a7ca728dced8ca41ad79a7c54a6c2408807b1
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Fri May 8 14:58:55 2015 +0200
Add SwDBManager::LoadAndRegisterEmbeddedDataSource
With this, if a .odt document has an embedded data source definition,
referred as EmbeddedDatabaseName in settings.xml, then that data source
gets registered when opening the document.
Change-Id: Ibd836fe11c0e74e8ea10e357886e6266e9ba0db0
diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index d420a8a..e5f719c 100644
--- a/sw/inc/dbmgr.hxx
+++ b/sw/inc/dbmgr.hxx
@@ -77,6 +77,7 @@ class SwXMailMerge;
class SwMailMergeConfigItem;
class SwCalc;
class INetURLObject;
+class SwDocShell;
enum DBManagerOptions
{
@@ -369,6 +370,9 @@ public:
static OUString LoadAndRegisterDataSource(const OUString& rURI, const OUString *pPrefix = 0, const OUString *pDestDir = 0,
const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet > *pSettings = 0);
+ /// Load the embedded data source of the document and also register it.
+ void LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const SwDocShell& rDocShell);
+
/** try to get the data source from the given connection through the XChild interface.
If this is not possible, the data source will be created through its name.
@param _xConnection
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 80de11e..4886e29 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -38,6 +38,7 @@
#include <DocumentLayoutManager.hxx>
#include <DocumentExternalDataManager.hxx>
#include <UndoManager.hxx>
+#include <dbmgr.hxx>
#include <hintids.hxx>
#include <tools/globname.hxx>
#include <svx/svxids.hrc>
@@ -493,6 +494,9 @@ void SwDoc::ChgDBData(const SwDBData& rNewData)
{
if( rNewData != maDBData )
{
+ if (maDBData.sEmbeddedName != rNewData.sEmbeddedName && GetDocShell())
+ mpDBManager->LoadAndRegisterEmbeddedDataSource(rNewData, *GetDocShell());
+
maDBData = rNewData;
getIDocumentState().SetModified();
}
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 0574eb4..042a0bd 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -2624,6 +2624,20 @@ OUString SwDBManager::LoadAndRegisterDataSource(const OUString &rURI, const OUSt
return LoadAndRegisterDataSource( type, aURLAny, pSettings, rURI, pPrefix, pDestDir );
}
+void SwDBManager::LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const SwDocShell& rDocShell)
+{
+ uno::Reference<sdb::XDatabaseContext> xDatabaseContext = sdb::DatabaseContext::create(comphelper::getProcessComponentContext());
+
+ if (xDatabaseContext->hasByName(rData.sDataSource))
+ xDatabaseContext->revokeObject(rData.sDataSource);
+
+ INetURLObject aURLObject(rDocShell.GetMedium()->GetURLObject());
+ aURLObject.SetMark(rData.sEmbeddedName);
+ OUString aURL = aURLObject.GetMainURL(INetURLObject::DECODE_WITH_CHARSET);
+ uno::Reference<uno::XInterface> xDataSource(xDatabaseContext->getByName(aURL), uno::UNO_QUERY);
+ xDatabaseContext->registerObject(rData.sDataSource, xDataSource);
+}
+
void SwDBManager::ExecuteFormLetter( SwWrtShell& rSh,
const Sequence<PropertyValue>& rProperties,
bool bWithDataSourceBrowser)
More information about the Libreoffice-commits
mailing list