[Libreoffice-commits] core.git: Branch 'libreoffice-6-4' - include/oox oox/source sw/qa

Samuel Mehrbrodt (via logerrit) logerrit at kemper.freedesktop.org
Mon Apr 27 08:15:13 UTC 2020


 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 66331ed8f549cd9fad331b7d2a1d7dcf3498a553
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Wed Apr 15 14:59:15 2020 +0200
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Mon Apr 27 10:14:41 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.Mehrbrodt at cib.de>
    (cherry picked from commit ff93e4977cb1e23f355d248a77e8d0e56bb0f4b9)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92766
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/include/oox/core/filterdetect.hxx b/include/oox/core/filterdetect.hxx
index ac3194e81acd..f3f5f24d40b0 100644
--- a/include/oox/core/filterdetect.hxx
+++ b/include/oox/core/filterdetect.hxx
@@ -49,6 +49,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.
 
@@ -79,7 +85,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 );
 
@@ -90,6 +96,7 @@ private:
     OUString const      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 c83dab9d6f74..f51dae3d07e4 100644
--- a/oox/source/core/filterdetect.cxx
+++ b/oox/source/core/filterdetect.cxx
@@ -56,6 +56,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 );
@@ -144,6 +145,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
     {
@@ -171,14 +181,32 @@ OUString FilterDetectDocHandler::getFilterNameFromContentType( const OUString& r
     bool bDocm = rFileName.endsWithIgnoreAsciiCase(".docm");
 
     if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" && !bDocm )
-        return "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 "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 "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 "MS Excel 2007 XML";
diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx
index 48e1ad66f079..5808fdc6f234 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -625,7 +625,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:


More information about the Libreoffice-commits mailing list