From afc5c31646cc2108d788edee5d1ba1939430f773 Mon Sep 17 00:00:00 2001 From: Katarina Machalkova Date: Wed, 13 Oct 2010 18:13:56 +0200 Subject: [PATCH] Merged ooxml-sc-docpropsimp.dff from ooo-build --- oox/inc/oox/core/xmlfilterbase.hxx | 2 ++ oox/source/core/xmlfilterbase.cxx | 51 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/oox/inc/oox/core/xmlfilterbase.hxx b/oox/inc/oox/core/xmlfilterbase.hxx index 30efeb0e9440..4cfccca02d70 100644 --- a/oox/inc/oox/core/xmlfilterbase.hxx +++ b/oox/inc/oox/core/xmlfilterbase.hxx @@ -198,6 +198,8 @@ public: */ XmlFilterBase& exportDocumentProperties( ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties > xProperties ); + void importDocumentProperties() throw(); + protected: virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > implGetInputStream( ::comphelper::MediaDescriptor& rMediaDesc ) const; diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx index efcea42a53c8..37e26f415ca4 100644 --- a/oox/source/core/xmlfilterbase.cxx +++ b/oox/source/core/xmlfilterbase.cxx @@ -81,6 +81,22 @@ using ::comphelper::MediaDescriptor; using ::sax_fastparser::FastSerializerHelper; using ::sax_fastparser::FSHelperPtr; + +#include +#include +#include +#include +#include +#include +#include + +using ::com::sun::star::uno::XComponentContext; +using ::com::sun::star::document::XOOXMLDocumentPropertiesImporter; +using ::com::sun::star::document::XDocumentPropertiesSupplier; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::lang::XComponent; + + namespace oox { namespace core { @@ -118,6 +134,22 @@ XmlFilterBaseImpl::XmlFilterBaseImpl() : { } +// ============================================================================ +static Reference< XComponentContext > lcl_getComponentContext(Reference< XMultiServiceFactory > aFactory) +{ + Reference< XComponentContext > xContext; + try + { + Reference< XPropertySet > xFactProp( aFactory, UNO_QUERY ); + if( xFactProp.is() ) + xFactProp->getPropertyValue( OUString::createFromAscii("DefaultContext") ) >>= xContext; + } + catch( Exception& ) + {} + + return xContext; +} + // ============================================================================ XmlFilterBase::XmlFilterBase( const Reference< XMultiServiceFactory >& rxGlobalFactory ) : @@ -166,6 +198,25 @@ XmlFilterBase::~XmlFilterBase() // ---------------------------------------------------------------------------- +void XmlFilterBase::importDocumentProperties() throw() +{ + Reference< XMultiServiceFactory > xFactory( getGlobalFactory(), UNO_QUERY ); + MediaDescriptor aMediaDesc( getMediaDescriptor() ); + Reference< XInputStream > xInputStream; + ::oox::core::FilterDetect aDetector( xFactory ); + xInputStream = aDetector.extractUnencryptedPackage( aMediaDesc ); + Reference< XComponent > xModel( getModel(), UNO_QUERY ); + Reference< XComponentContext > xContext = lcl_getComponentContext(getGlobalFactory()); + Reference< XStorage > xDocumentStorage ( + ::comphelper::OStorageHelper::GetStorageOfFormatFromInputStream( OFOPXML_STORAGE_FORMAT_STRING, xInputStream ) ); + Reference< XInterface > xTemp = xContext->getServiceManager()->createInstanceWithContext( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.OOXMLDocumentPropertiesImporter")), + xContext); + Reference< XOOXMLDocumentPropertiesImporter > xImporter( xTemp, UNO_QUERY ); + Reference< XDocumentPropertiesSupplier > xPropSupplier( xModel, UNO_QUERY); + xImporter->importProperties( xDocumentStorage, xPropSupplier->getDocumentProperties() ); +} + OUString XmlFilterBase::getFragmentPathFromFirstType( const OUString& rType ) { // importRelations() caches the relations map for subsequence calls