[Libreoffice-commits] core.git: 2 commits - dbaccess/source
Miklos Vajna
vmiklos at collabora.co.uk
Tue May 5 01:28:48 PDT 2015
dbaccess/source/core/dataaccess/databasedocument.cxx | 43 +++++++++++++++---
dbaccess/source/core/inc/core_resource.hrc | 1
dbaccess/source/core/resource/strings.src | 5 --
dbaccess/source/filter/xml/xmlfilter.cxx | 45 +++++++++++--------
4 files changed, 64 insertions(+), 30 deletions(-)
New commits:
commit 2b1bd0fac8007adeefb91f6d505186221143fb4f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue May 5 09:57:03 2015 +0200
dbaccess: implement ODatabaseDocument::loadFromStorage()
With this, it's finally possible to load a .odb file embedded inside a
.odt.
Change-Id: Ib5eec603ce958abd848e456871aacfad4ab0a8b7
diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx
index 1721287..7028a9d 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 151d000..4ab8b27 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 1784a3d..fdad3c6 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$\".";
commit ff3e41a5be2f104e2ea1497660938e5744ad6fba
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue May 5 09:42:03 2015 +0200
dbaccess: use already existing source storage in ODBFilter, if possible
Change-Id: I4378e229c771cf79a694086b7a4ba4ac2e36b8f7
diff --git a/dbaccess/source/filter/xml/xmlfilter.cxx b/dbaccess/source/filter/xml/xmlfilter.cxx
index 03e94ba..4d2e8cc 100644
--- a/dbaccess/source/filter/xml/xmlfilter.cxx
+++ b/dbaccess/source/filter/xml/xmlfilter.cxx
@@ -431,31 +431,40 @@ bool ODBFilter::implImport( const Sequence< PropertyValue >& rDescriptor )
{
OUString sFileName;
::comphelper::NamedValueCollection aMediaDescriptor( rDescriptor );
- if ( aMediaDescriptor.has( "URL" ) )
- sFileName = aMediaDescriptor.getOrDefault( "URL", OUString() );
- if ( sFileName.isEmpty() && aMediaDescriptor.has( "FileName" ) )
- sFileName = aMediaDescriptor.getOrDefault( "FileName", sFileName );
- OSL_ENSURE( !sFileName.isEmpty(), "ODBFilter::implImport: no URL given!" );
- bool bRet = !sFileName.isEmpty();
+ uno::Reference<embed::XStorage> xStorage = GetSourceStorage();
+
+ bool bRet = true;
+ if (!xStorage.is())
+ {
+ if (aMediaDescriptor.has("URL"))
+ sFileName = aMediaDescriptor.getOrDefault("URL", OUString());
+ if (sFileName.isEmpty() && aMediaDescriptor.has("FileName"))
+ sFileName = aMediaDescriptor.getOrDefault("FileName", sFileName);
+
+ OSL_ENSURE(!sFileName.isEmpty(), "ODBFilter::implImport: no URL given!");
+ bRet = !sFileName.isEmpty();
+ }
if ( bRet )
{
uno::Reference<XComponent> xCom(GetModel(),UNO_QUERY);
- SfxMediumRef pMedium = new SfxMedium(
- sFileName, ( StreamMode::READ | StreamMode::NOCREATE ) );
- uno::Reference< embed::XStorage > xStorage;
- try
- {
- xStorage.set( pMedium->GetStorage( false ), UNO_QUERY_THROW );
- }
- catch (const Exception&)
+ SfxMediumRef pMedium(0);
+ if (!xStorage.is())
{
- Any aError = ::cppu::getCaughtException();
- if ( aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() ) )
- throw;
- throw lang::WrappedTargetRuntimeException( OUString(), *this, aError );
+ pMedium = new SfxMedium(sFileName, (StreamMode::READ | StreamMode::NOCREATE));
+ try
+ {
+ xStorage.set(pMedium->GetStorage(false), UNO_QUERY_THROW);
+ }
+ catch (const Exception&)
+ {
+ Any aError = ::cppu::getCaughtException();
+ if (aError.isExtractableTo(::cppu::UnoType<RuntimeException>::get()))
+ throw;
+ throw lang::WrappedTargetRuntimeException(OUString(), *this, aError);
+ }
}
uno::Reference<sdb::XOfficeDatabaseDocument> xOfficeDoc(GetModel(),UNO_QUERY_THROW);
More information about the Libreoffice-commits
mailing list