From c9bae5c5f0b9219391e604a1d61126ea3d2c943c Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Tue, 10 Mar 2015 00:34:07 +0100 Subject: detect MSO 2007 OOXML documents (cherry picked from commit 15174177091367332b57cd79575e2f7dd27388b2) Conflicts: oox/source/core/xmlfilterbase.cxx Conflicts: oox/source/core/xmlfilterbase.cxx Change-Id: I4052c6f1e5dde71ce4cede1ec9a313f461861d71 --- include/oox/core/xmlfilterbase.hxx | 3 +++ oox/source/core/xmlfilterbase.cxx | 42 +++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/include/oox/core/xmlfilterbase.hxx b/include/oox/core/xmlfilterbase.hxx index a26bad854665..3d12fc4d5fc5 100644 --- a/include/oox/core/xmlfilterbase.hxx +++ b/include/oox/core/xmlfilterbase.hxx @@ -233,6 +233,8 @@ public: FastParser* createParser() const; + bool isMSO2007Document() const; + protected: virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > implGetInputStream( utl::MediaDescriptor& rMediaDesc ) const SAL_OVERRIDE; @@ -252,6 +254,7 @@ private: ::std::auto_ptr< XmlFilterBaseImpl > mxImpl; sal_Int32 mnRelId; sal_Int32 mnMaxDocId; + bool mbMSO2007; }; typedef ::rtl::Reference< XmlFilterBase > XmlFilterRef; diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx index 3b807df64d8a..ddc4507c5dfc 100644 --- a/oox/source/core/xmlfilterbase.cxx +++ b/oox/source/core/xmlfilterbase.cxx @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -200,7 +201,8 @@ XmlFilterBase::XmlFilterBase( const Reference< XComponentContext >& rxContext ) FilterBase( rxContext ), mxImpl( new XmlFilterBaseImpl( rxContext ) ), mnRelId( 1 ), - mnMaxDocId( 0 ) + mnMaxDocId( 0 ), + mbMSO2007(false) { } @@ -216,6 +218,35 @@ XmlFilterBase::~XmlFilterBase() mxImpl->maFastParser.setDocumentHandler( 0 ); } +namespace { + +bool is2007MSODocument(Reference xDocProps) +{ + if (!xDocProps->getGenerator().startsWithIgnoreAsciiCase("Microsoft")) + return false; + + uno::Reference xUserDefProps(xDocProps->getUserDefinedProperties(), uno::UNO_QUERY); + if (!xUserDefProps.is()) + return false; + + comphelper::SequenceAsHashMap aUserDefinedProperties(xUserDefProps->getPropertyValues()); + comphelper::SequenceAsHashMap::iterator it = aUserDefinedProperties.find("AppVersion"); + if (it == aUserDefinedProperties.end()) + return false; + + OUString aValue; + if (!(it->second >>= aValue)) + return false; + + if (!aValue.startsWithIgnoreAsciiCase("12.")) + return false; + + SAL_WARN("oox", "a MSO 2007 document"); + return true; +} + +} + void XmlFilterBase::importDocumentProperties() @@ -234,7 +265,9 @@ void XmlFilterBase::importDocumentProperties() xContext); Reference< XOOXMLDocumentPropertiesImporter > xImporter( xTemp, UNO_QUERY ); Reference< XDocumentPropertiesSupplier > xPropSupplier( xModel, UNO_QUERY); - xImporter->importProperties( xDocumentStorage, xPropSupplier->getDocumentProperties() ); + Reference< XDocumentProperties > xDocProps = xPropSupplier->getDocumentProperties(); + xImporter->importProperties( xDocumentStorage, xDocProps ); + mbMSO2007 = is2007MSODocument(xDocProps); } FastParser* XmlFilterBase::createParser() const @@ -785,7 +818,10 @@ StorageRef XmlFilterBase::implCreateStorage( const Reference< XStream >& rxOutSt return StorageRef( new ZipStorage( getComponentContext(), rxOutStream ) ); } - +bool XmlFilterBase::isMSO2007Document() const +{ + return mbMSO2007; +} } // namespace core } // namespace oox -- cgit v1.2.3