Kaydet (Commit) f01f3120 authored tarafından Miklos Vajna's avatar Miklos Vajna

SwDBManager: extract StoreEmbeddedDataSource() from registration code

Change-Id: Ifc6471f58793cde057f354c4c6a549c073b7d34b
üst 2a0dda3d
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/lang/Locale.hpp> #include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/beans/PropertyValue.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> #include <boost/ptr_container/ptr_vector.hpp>
namespace com{namespace sun{namespace star{ namespace com{namespace sun{namespace star{
...@@ -414,6 +416,11 @@ public: ...@@ -414,6 +416,11 @@ public:
void setEmbeddedName(const OUString& rEmbeddedName, SwDocShell& rDocShell); void setEmbeddedName(const OUString& rEmbeddedName, SwDocShell& rDocShell);
OUString getEmbeddedName() const; 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 #endif
......
...@@ -2595,39 +2595,23 @@ OUString SwDBManager::LoadAndRegisterDataSource(const DBConnURITypes type, const ...@@ -2595,39 +2595,23 @@ OUString SwDBManager::LoadAndRegisterDataSource(const DBConnURITypes type, const
uno::Reference<frame::XStorable> xStore(xDS->getDatabaseDocument(), uno::UNO_QUERY_THROW); uno::Reference<frame::XStorable> xStore(xDS->getDatabaseDocument(), uno::UNO_QUERY_THROW);
OUString sOutputExt = ".odb"; OUString sOutputExt = ".odb";
OUString aOwnURL = lcl_getOwnURL(pDocShell); OUString aOwnURL = lcl_getOwnURL(pDocShell);
OUString sTmpName;
uno::Sequence<beans::PropertyValue> aSequence;
if (aOwnURL.isEmpty()) if (aOwnURL.isEmpty())
{ {
// Cannot embed, as embedded data source would need the URL of the parent document. // Cannot embed, as embedded data source would need the URL of the parent document.
OUString sHomePath(SvtPathOptions().GetWorkPath()); OUString sHomePath(SvtPathOptions().GetWorkPath());
utl::TempFile aTempFile(sNewName, true, &sOutputExt, pDestDir ? pDestDir : &sHomePath); utl::TempFile aTempFile(sNewName, true, &sOutputExt, pDestDir ? pDestDir : &sHomePath);
aTempFile.EnableKillingFile(true); aTempFile.EnableKillingFile(true);
sTmpName = aTempFile.GetURL(); OUString sTmpName = aTempFile.GetURL();
xStore->storeAsURL(sTmpName, uno::Sequence<beans::PropertyValue>());
} }
else else
{ {
// Embed: construct vnd.sun.star.pkg:// URL for later loading, and TargetStorage/StreamRelPath for storing. // Embed.
OUString aStreamRelPath = "EmbeddedDatabase"; 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(); uno::Reference<embed::XStorage> xStorage = pDocShell->GetStorage();
aSequence = comphelper::InitPropertySequence( SwDBManager::StoreEmbeddedDataSource(xStore, xStorage, aStreamRelPath, aOwnURL);
{
{"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));
} }
xStore->storeAsURL(sTmpName, aSequence);
} }
xDBContext->registerObject( sFind, xNewInstance ); xDBContext->registerObject( sFind, xNewInstance );
} }
...@@ -2638,6 +2622,25 @@ OUString SwDBManager::LoadAndRegisterDataSource(const DBConnURITypes type, const ...@@ -2638,6 +2622,25 @@ OUString SwDBManager::LoadAndRegisterDataSource(const DBConnURITypes type, const
return sFind; 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, OUString SwDBManager::LoadAndRegisterDataSource(const OUString &rURI, const OUString *pPrefix, const OUString *pDestDir,
const uno::Reference< beans::XPropertySet > *pSettings) const uno::Reference< beans::XPropertySet > *pSettings)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment