summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-05-08 14:58:55 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-05-08 15:24:30 +0200
commit358a7ca728dced8ca41ad79a7c54a6c2408807b1 (patch)
tree7a85259c5fb4da95b407da51490af37a26aaa8b3
parentbc4f6677a0d307fb19ad4fdfb627c80e59fd6835 (diff)
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
-rw-r--r--sw/inc/dbmgr.hxx4
-rw-r--r--sw/source/core/doc/doc.cxx4
-rw-r--r--sw/source/uibase/dbui/dbmgr.cxx14
3 files changed, 22 insertions, 0 deletions
diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index d420a8a4d4bf..e5f719c5fa13 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 80de11eebe8d..4886e296a3e5 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 0574eb408472..042a0bd925a7 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)