From 0a5ca5768f56db481dd3b947b3dddaab7ed96450 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 15 Feb 2019 17:50:38 +0100 Subject: tdf#123293 sfx2: fix metadata loss when loading from stream The problem is that when loading from a stream, there is no BaseURL and also no storage for the document. Due to the lack of BaseURL, the sfx2::createBaseURI() throws and loading RDF metadata fails, which also pops up an annoying warning dialog. Try to handle this in a similar way than a newly created document (see GetDMA()), by using the vnd.sun.star.tdoc scheme URL for the document; this however currently requires that the document has a XStorage, which is also not the case here. So add another UNO method to tdoc UCP's tdoc_ucp::ContentProvider, to split out the creation of the tdoc schema URL from the creation of the ucb Content, to get rid of the XStorage requirement. Change-Id: Ica62743f9d21db0b1464b70db1a62ebc61989ef8 Reviewed-on: https://gerrit.libreoffice.org/67882 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt --- ucb/source/ucp/tdoc/tdoc_provider.cxx | 27 +++++++++++++++++++-------- ucb/source/ucp/tdoc/tdoc_provider.hxx | 13 ++++++++++--- 2 files changed, 29 insertions(+), 11 deletions(-) (limited to 'ucb/source') diff --git a/ucb/source/ucp/tdoc/tdoc_provider.cxx b/ucb/source/ucp/tdoc/tdoc_provider.cxx index fef2f3145f5e..fdcfd241502c 100644 --- a/ucb/source/ucp/tdoc/tdoc_provider.cxx +++ b/ucb/source/ucp/tdoc/tdoc_provider.cxx @@ -88,6 +88,7 @@ css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & r static_cast< lang::XTypeProvider* >(this), static_cast< lang::XServiceInfo* >(this), static_cast< ucb::XContentProvider* >(this), + static_cast< frame::XTransientDocumentsDocumentContentIdentifierFactory* >(this), static_cast< frame::XTransientDocumentsDocumentContentFactory* >(this) ); return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); @@ -96,10 +97,11 @@ css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & r // XTypeProvider methods. -XTYPEPROVIDER_IMPL_4( ContentProvider, +XTYPEPROVIDER_IMPL_5( ContentProvider, lang::XTypeProvider, lang::XServiceInfo, ucb::XContentProvider, + frame::XTransientDocumentsDocumentContentIdentifierFactory, frame::XTransientDocumentsDocumentContentFactory ); @@ -164,13 +166,11 @@ ContentProvider::queryContent( } -// XTransientDocumentsDocumentContentFactory methods. - +// XTransientDocumentsDocumentContentIdentifierFactory methods. -// virtual -uno::Reference< ucb::XContent > SAL_CALL -ContentProvider::createDocumentContent( - const uno::Reference< frame::XModel >& Model ) +uno::Reference SAL_CALL +ContentProvider::createDocumentContentIdentifier( + uno::Reference const& xModel) { // model -> id -> content identifier -> queryContent if ( !m_xDocsMgr.is() ) @@ -181,7 +181,7 @@ ContentProvider::createDocumentContent( 1 ); } - OUString aDocId = tdoc_ucp::OfficeDocumentsManager::queryDocumentId( Model ); + OUString aDocId = tdoc_ucp::OfficeDocumentsManager::queryDocumentId(xModel); if ( aDocId.isEmpty() ) { throw lang::IllegalArgumentException( @@ -196,6 +196,17 @@ ContentProvider::createDocumentContent( uno::Reference< ucb::XContentIdentifier > xId = new ::ucbhelper::ContentIdentifier( aBuffer.makeStringAndClear() ); + return xId; +} + +// XTransientDocumentsDocumentContentFactory methods. + +uno::Reference< ucb::XContent > SAL_CALL +ContentProvider::createDocumentContent( + uno::Reference const& xModel) +{ + uno::Reference const xId( + createDocumentContentIdentifier(xModel)); osl::MutexGuard aGuard( m_aMutex ); diff --git a/ucb/source/ucp/tdoc/tdoc_provider.hxx b/ucb/source/ucp/tdoc/tdoc_provider.hxx index 2f308bf3ff5c..f1dc515b1b84 100644 --- a/ucb/source/ucp/tdoc/tdoc_provider.hxx +++ b/ucb/source/ucp/tdoc/tdoc_provider.hxx @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -53,9 +54,10 @@ namespace tdoc_ucp { class StorageElementFactory; -class ContentProvider : - public ::ucbhelper::ContentProviderImplHelper, - public css::frame::XTransientDocumentsDocumentContentFactory +class ContentProvider + : public ::ucbhelper::ContentProviderImplHelper + , public css::frame::XTransientDocumentsDocumentContentIdentifierFactory + , public css::frame::XTransientDocumentsDocumentContentFactory { public: explicit ContentProvider( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); @@ -88,6 +90,11 @@ public: virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent( const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier ) override; + // XTransientDocumentsDocumentContentIdentifierFactory + virtual css::uno::Reference SAL_CALL + createDocumentContentIdentifier( + css::uno::Reference const& xModel) override; + // XTransientDocumentsDocumentContentFactory virtual css::uno::Reference< css::ucb::XContent > SAL_CALL createDocumentContent( const css::uno::Reference< -- cgit