diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-06-02 10:57:23 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-06-02 14:53:29 +0200 |
commit | 97fa7024ce608b7908aca369e8c643a5de9ebf78 (patch) | |
tree | 72e7cff11d04d90b3b4a6a4f756d1e18e22018e7 /oox | |
parent | f883a6b420efa7ed099448f7e6e5cadaa3bb275b (diff) |
Related: tdf#108269 oox: allow recovering broken DOCM files
The content type inside an OOXML file differs for DOCX and DOCM. These
must be in sync with the file extension, otherwise MSO refuses to open
the file. We used to always write the DOCX content-type even for files
which had the DOCM extension.
Allow users to recover those broken files by detecting a "has docm
extension but docx content-type" file as docm, so re-saving it will
produce output that's accepted by MSO as well.
Change-Id: I7d60c6f6c1d0421e95b3dc9e8fff617f101919f5
Reviewed-on: https://gerrit.libreoffice.org/38342
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/core/filterdetect.cxx | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/oox/source/core/filterdetect.cxx b/oox/source/core/filterdetect.cxx index 1882572f12d5..226668dfc767 100644 --- a/oox/source/core/filterdetect.cxx +++ b/oox/source/core/filterdetect.cxx @@ -52,8 +52,9 @@ using utl::MediaDescriptor; using comphelper::IDocPasswordVerifier; using comphelper::DocPasswordVerifierResult; -FilterDetectDocHandler::FilterDetectDocHandler( const Reference< XComponentContext >& rxContext, OUString& rFilterName ) : +FilterDetectDocHandler::FilterDetectDocHandler( const Reference< XComponentContext >& rxContext, OUString& rFilterName, const OUString& rFileName ) : mrFilterName( rFilterName ), + maFileName(rFileName), mxContext( rxContext ) { maContextStack.reserve( 2 ); @@ -160,12 +161,12 @@ void FilterDetectDocHandler::parseRelationship( const AttributeList& rAttribs ) } } -OUString FilterDetectDocHandler::getFilterNameFromContentType( const OUString& rContentType ) +OUString FilterDetectDocHandler::getFilterNameFromContentType( const OUString& rContentType, const OUString& rFileName ) { - if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" ) + if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" && !rFileName.endsWith("docm") ) return OUString( "writer_MS_Word_2007" ); - if( rContentType == "application/vnd.ms-word.document.macroEnabled.main+xml" ) + if( rContentType == "application/vnd.ms-word.document.macroEnabled.main+xml" || rFileName.endsWith("docm") ) return OUString( "writer_MS_Word_2007_VBA" ); if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml" || @@ -209,14 +210,14 @@ void FilterDetectDocHandler::parseContentTypesDefault( const AttributeList& rAtt OUString aExtension = rAttribs.getString( XML_Extension, OUString() ); sal_Int32 nExtPos = maTargetPath.getLength() - aExtension.getLength(); if( (nExtPos > 0) && (maTargetPath[ nExtPos - 1 ] == '.') && maTargetPath.match( aExtension, nExtPos ) ) - mrFilterName = getFilterNameFromContentType( rAttribs.getString( XML_ContentType, OUString() ) ); + mrFilterName = getFilterNameFromContentType( rAttribs.getString( XML_ContentType, OUString() ), maFileName ); } } void FilterDetectDocHandler::parseContentTypesOverride( const AttributeList& rAttribs ) { if( rAttribs.getString( XML_PartName, OUString() ).equals( maTargetPath ) ) - mrFilterName = getFilterNameFromContentType( rAttribs.getString( XML_ContentType, OUString() ) ); + mrFilterName = getFilterNameFromContentType( rAttribs.getString( XML_ContentType, OUString() ), maFileName ); } /* Helper for XServiceInfo */ @@ -400,7 +401,11 @@ OUString SAL_CALL FilterDetect::detect( Sequence< PropertyValue >& rMediaDescSeq aParser.registerNamespace( NMSP_packageRel ); aParser.registerNamespace( NMSP_officeRel ); aParser.registerNamespace( NMSP_packageContentTypes ); - aParser.setDocumentHandler( new FilterDetectDocHandler( mxContext, aFilterName ) ); + + OUString aFileName; + aMediaDescriptor[utl::MediaDescriptor::PROP_URL()] >>= aFileName; + + aParser.setDocumentHandler( new FilterDetectDocHandler( mxContext, aFilterName, aFileName ) ); /* Parse '_rels/.rels' to get the target path and '[Content_Types].xml' to determine the content type of the part at the target path. */ |