include/oox/core/filterdetect.hxx | 9 ++++++- oox/source/core/filterdetect.cxx | 32 +++++++++++++++++++++++-- oox/source/core/xmlfilterbase.cxx | 4 +++ sw/qa/uitest/writer_tests7/data/tdf131936.docx |binary sw/qa/uitest/writer_tests7/tdf131936.py | 32 +++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 3 deletions(-)
New commits: commit 4b7b19644c5a3c65ca83b105ad789bfcd07f8325 Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> AuthorDate: Wed Apr 15 14:59:15 2020 +0200 Commit: Thorsten Behrens <thorsten.behr...@cib.de> CommitDate: Mon May 4 22:51:25 2020 +0200 tdf#131936 Correctly detect OOXML variant on import Change-Id: I29a6b0454bf741ce8ad49078597b3412a83dedb9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92278 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> (cherry picked from commit ff93e4977cb1e23f355d248a77e8d0e56bb0f4b9) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92766 Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> (cherry picked from commit 66331ed8f549cd9fad331b7d2a1d7dcf3498a553) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92996 Tested-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/include/oox/core/filterdetect.hxx b/include/oox/core/filterdetect.hxx index 44f0363187c9..17c771c810d4 100644 --- a/include/oox/core/filterdetect.hxx +++ b/include/oox/core/filterdetect.hxx @@ -52,6 +52,12 @@ namespace oox { class AttributeList; } namespace oox { namespace core { +enum class OOXMLVariant { + ECMA_Transitional, + ISO_Transitional, + ISO_Strict +}; + /** Document handler specifically designed for detecting OOXML file formats. @@ -82,7 +88,7 @@ public: private: void parseRelationship( const AttributeList& rAttribs ); - static OUString getFilterNameFromContentType( const OUString& rContentType, const OUString& rFileName ); + OUString getFilterNameFromContentType( const OUString& rContentType, const OUString& rFileName ); void parseContentTypesDefault( const AttributeList& rAttribs ); void parseContentTypesOverride( const AttributeList& rAttribs ); @@ -93,6 +99,7 @@ private: OUString maFileName; ContextVector maContextStack; OUString maTargetPath; + OOXMLVariant maOOXMLVariant; css::uno::Reference< css::uno::XComponentContext > mxContext; }; diff --git a/oox/source/core/filterdetect.cxx b/oox/source/core/filterdetect.cxx index 1af982c07480..613b6077675d 100644 --- a/oox/source/core/filterdetect.cxx +++ b/oox/source/core/filterdetect.cxx @@ -55,6 +55,7 @@ using comphelper::DocPasswordVerifierResult; FilterDetectDocHandler::FilterDetectDocHandler( const Reference< XComponentContext >& rxContext, OUString& rFilterName, const OUString& rFileName ) : mrFilterName( rFilterName ), maFileName(rFileName), + maOOXMLVariant( OOXMLVariant::ECMA_Transitional ), mxContext( rxContext ) { maContextStack.reserve( 2 ); @@ -143,6 +144,15 @@ void SAL_CALL FilterDetectDocHandler::characters( const OUString& /*aChars*/ ) void FilterDetectDocHandler::parseRelationship( const AttributeList& rAttribs ) { OUString aType = rAttribs.getString( XML_Type, OUString() ); + + // tdf#131936 Remember filter when opening file as 'Office Open XML Text' + if (aType.startsWithIgnoreAsciiCase("http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties")) + maOOXMLVariant = OOXMLVariant::ISO_Transitional; + else if (aType.startsWithIgnoreAsciiCase("http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties")) + maOOXMLVariant = OOXMLVariant::ECMA_Transitional; + else if (aType.startsWithIgnoreAsciiCase("http://purl.oclc.org/ooxml/officeDocument")) + maOOXMLVariant = OOXMLVariant::ISO_Strict; + if ( aType == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" // OOXML Transitional || aType == "http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument" ) //OOXML strict { @@ -170,14 +180,32 @@ OUString FilterDetectDocHandler::getFilterNameFromContentType( const OUString& r bool bDocm = rFileName.endsWithIgnoreAsciiCase(".docm"); if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" && !bDocm ) - return OUString( "writer_MS_Word_2007" ); + { + switch (maOOXMLVariant) + { + case OOXMLVariant::ISO_Transitional: + case OOXMLVariant::ISO_Strict: // Not supported, map to ISO transitional + return "writer_OOXML"; + case OOXMLVariant::ECMA_Transitional: + return "writer_MS_Word_2007"; + } + } if( rContentType == "application/vnd.ms-word.document.macroEnabled.main+xml" || bDocm ) return OUString( "writer_MS_Word_2007_VBA" ); if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml" || rContentType == "application/vnd.ms-word.template.macroEnabledTemplate.main+xml" ) - return OUString( "writer_MS_Word_2007_Template" ); + { + switch (maOOXMLVariant) + { + case OOXMLVariant::ISO_Transitional: + case OOXMLVariant::ISO_Strict: // Not supported, map to ISO transitional + return "writer_OOXML_Text_Template"; + case OOXMLVariant::ECMA_Transitional: + return "writer_MS_Word_2007_Template"; + } + } if( rContentType == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml") return OUString( "MS Excel 2007 XML" ); diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx index 5168d81fb7fb..e73334f04521 100644 --- a/oox/source/core/xmlfilterbase.cxx +++ b/oox/source/core/xmlfilterbase.cxx @@ -612,7 +612,11 @@ writeCoreProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties { OUString sValue; if( rSelf.getVersion() == oox::core::ISOIEC_29500_2008 ) + { + // The lowercase "officedocument" is intentional and according to the spec + // (although most other places are written "officeDocument") sValue = "http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties"; + } else sValue = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"; diff --git a/sw/qa/uitest/writer_tests7/data/tdf131936.docx b/sw/qa/uitest/writer_tests7/data/tdf131936.docx new file mode 100644 index 000000000000..f993d6ee327f Binary files /dev/null and b/sw/qa/uitest/writer_tests7/data/tdf131936.docx differ diff --git a/sw/qa/uitest/writer_tests7/tdf131936.py b/sw/qa/uitest/writer_tests7/tdf131936.py new file mode 100644 index 000000000000..a6102da05b77 --- /dev/null +++ b/sw/qa/uitest/writer_tests7/tdf131936.py @@ -0,0 +1,32 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from uitest.framework import UITestCase +from uitest.uihelper.common import get_state_as_dict +from libreoffice.uno.propertyvalue import mkPropertyValues +from uitest.path import get_srcdir_url +from uitest.config import DEFAULT_SLEEP +import time + +def get_url_for_data_file(file_name): + return get_srcdir_url() + "/sw/qa/uitest/writer_tests7/data/" + file_name + +class tdf131936(UITestCase): + + def test_tdf131936_saveas_docx_version(self): + self.ui_test.load_file(get_url_for_data_file("tdf131936.docx")) + + self.ui_test.execute_dialog_through_command(".uno:SaveAs") + time.sleep(DEFAULT_SLEEP) + xDialog = self.xUITest.getTopFocusWindow() + xFileTypeCombo = xDialog.getChild("file_type") + state = get_state_as_dict(xFileTypeCombo) + self.assertEqual(state["SelectEntryText"], "Office Open XML Text (.docx)") + + xCancel = xDialog.getChild("cancel") + self.ui_test.close_dialog_through_button(xCancel) + + self.ui_test.close_doc() + +# vim: set shiftwidth=4 softtabstop=4 expandtab: _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits