summaryrefslogtreecommitdiff
path: root/dbaccess
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-05-05 09:57:03 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-05-05 10:22:47 +0200
commit2b1bd0fac8007adeefb91f6d505186221143fb4f (patch)
tree43acbd052755a396b2fae473675f342a0d54cdc5 /dbaccess
parentff3e41a5be2f104e2ea1497660938e5744ad6fba (diff)
dbaccess: implement ODatabaseDocument::loadFromStorage()
With this, it's finally possible to load a .odb file embedded inside a .odt. Change-Id: Ib5eec603ce958abd848e456871aacfad4ab0a8b7
Diffstat (limited to 'dbaccess')
-rw-r--r--dbaccess/source/core/dataaccess/databasedocument.cxx43
-rw-r--r--dbaccess/source/core/inc/core_resource.hrc1
-rw-r--r--dbaccess/source/core/resource/strings.src5
3 files changed, 37 insertions, 12 deletions
diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx
index 172128732ba8..7028a9d06dee 100644
--- a/dbaccess/source/core/dataaccess/databasedocument.cxx
+++ b/dbaccess/source/core/dataaccess/databasedocument.cxx
@@ -1914,14 +1914,45 @@ Reference< XDataSource > SAL_CALL ODatabaseDocument::getDataSource() throw (Runt
return m_pImpl->getOrCreateDataSource();
}
-void SAL_CALL ODatabaseDocument::loadFromStorage( const Reference< XStorage >& /*xStorage*/, const Sequence< PropertyValue >& /*aMediaDescriptor*/ ) throw (IllegalArgumentException, DoubleInitializationException, IOException, Exception, RuntimeException, std::exception)
+namespace
{
- DocumentGuard aGuard(*this, DocumentGuard::DefaultMethod);
+/// Property map for embedded import info set.
+comphelper::PropertyMapEntry const aEmbeddedImportInfoMap[] =
+{
+ {OUString("StreamRelPath"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0},
+ {OUString("StreamName"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0},
+ {OUString("SourceStorage"), 0, cppu::UnoType<embed::XStorage>::get(), beans::PropertyAttribute::MAYBEVOID, 0},
+ {OUString(), 0, css::uno::Type(), 0, 0}
+};
+}
- throw Exception(
- DBACORE_RESSTRING( RID_STR_NO_EMBEDDING ),
- *this
- );
+void SAL_CALL ODatabaseDocument::loadFromStorage(const Reference<XStorage>& xStorage, const Sequence<PropertyValue>& rMediaDescriptor) throw (IllegalArgumentException, DoubleInitializationException, IOException, Exception, RuntimeException, std::exception)
+{
+ DocumentGuard aGuard(*this, DocumentGuard::InitMethod);
+
+ uno::Reference<beans::XPropertySet> xInfoSet(comphelper::GenericPropertySet_CreateInstance(new comphelper::PropertySetInfo(aEmbeddedImportInfoMap)));
+ comphelper::NamedValueCollection aDescriptor(rMediaDescriptor);
+ xInfoSet->setPropertyValue("StreamRelPath", uno::makeAny(aDescriptor.getOrDefault("HierarchicalDocumentName", OUString())));
+ xInfoSet->setPropertyValue("StreamName", uno::makeAny(OUString("content.xml")));
+ xInfoSet->setPropertyValue("SourceStorage", uno::makeAny(xStorage));
+
+ uno::Sequence<uno::Any> aFilterCreationArgs(1);
+ aFilterCreationArgs[0] <<= xInfoSet;
+
+ uno::Reference<document::XImporter> xImporter(m_pImpl->m_aContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.comp.sdb.DBFilter", aFilterCreationArgs, m_pImpl->m_aContext), uno::UNO_QUERY_THROW);
+
+ uno::Reference<lang::XComponent> xComponent(*this, uno::UNO_QUERY_THROW);
+ xImporter->setTargetDocument(xComponent);
+
+ uno::Reference<document::XFilter> xFilter(xImporter, uno::UNO_QUERY_THROW);
+ uno::Sequence<beans::PropertyValue> aFilterArgs;
+ xFilter->filter(aFilterArgs);
+
+ // In case of embedding, XModel::attachResource is already called.
+ if (m_bEmbedded)
+ impl_setInitialized();
+
+ impl_setModified_nothrow(false, aGuard);
}
void SAL_CALL ODatabaseDocument::storeToStorage( const Reference< XStorage >& _rxStorage, const Sequence< PropertyValue >& _rMediaDescriptor ) throw (IllegalArgumentException, IOException, Exception, RuntimeException, std::exception)
diff --git a/dbaccess/source/core/inc/core_resource.hrc b/dbaccess/source/core/inc/core_resource.hrc
index 151d00017d62..4ab8b27d230b 100644
--- a/dbaccess/source/core/inc/core_resource.hrc
+++ b/dbaccess/source/core/inc/core_resource.hrc
@@ -91,7 +91,6 @@
#define RID_STR_CURSOR_BEFORE_OR_AFTER ( RID_CORE_STRINGS_START + 61 )
#define RID_STR_NO_BOOKMARK_BEFORE_OR_AFTER ( RID_CORE_STRINGS_START + 62 )
#define RID_STR_NO_BOOKMARK_DELETED ( RID_CORE_STRINGS_START + 63 )
-#define RID_STR_NO_EMBEDDING ( RID_CORE_STRINGS_START + 64 )
#define RID_STR_CONNECTION_REQUEST ( RID_CORE_STRINGS_START + 65 )
#define RID_STR_MISSING_EXTENSION ( RID_CORE_STRINGS_START + 66 )
diff --git a/dbaccess/source/core/resource/strings.src b/dbaccess/source/core/resource/strings.src
index 1784a3d39182..fdad3c68f117 100644
--- a/dbaccess/source/core/resource/strings.src
+++ b/dbaccess/source/core/resource/strings.src
@@ -345,11 +345,6 @@ String RID_STR_NO_BOOKMARK_DELETED
Text [ en-US ] = "The current row is deleted, and thus doesn't have a bookmark.";
};
-String RID_STR_NO_EMBEDDING
-{
- Text [ en-US ] = "Embedding of database documents is not supported.";
-};
-
String RID_STR_CONNECTION_REQUEST
{
Text [ en-US ] = "A connection for the following URL was requested \"$name$\".";