[Libreoffice-commits] core.git: filter/Configuration_filter.mk filter/source oox/source sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Jun 1 11:02:24 UTC 2017


 filter/Configuration_filter.mk                                       |    2 
 filter/source/config/fragments/filters/MS_Word_2007_XML_VBA.xcu      |   18 +++++
 filter/source/config/fragments/types/writer_MS_Word_2007_XML.xcu     |    2 
 filter/source/config/fragments/types/writer_MS_Word_2007_XML_VBA.xcu |   17 +++++
 oox/source/core/filterdetect.cxx                                     |    6 +
 sw/qa/extras/ooxmlexport/data/hello.docm                             |binary
 sw/qa/extras/ooxmlexport/ooxmlexport9.cxx                            |   33 ++++++++++
 sw/source/filter/ww8/docxexport.cxx                                  |   12 ++-
 sw/source/filter/ww8/docxexport.hxx                                  |    5 +
 sw/source/filter/ww8/docxexportfilter.cxx                            |    7 +-
 10 files changed, 93 insertions(+), 9 deletions(-)

New commits:
commit 697173f6fdfae581022cfdb5ec5171c5a3be58f0
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jun 1 09:46:16 2017 +0200

    sw: add separate DOCM filter
    
    This way at export time we can preserve the correct content-type, which
    isn't the same for DOCX and DOCM.
    
    Change-Id: I08fa734c72fab7400bd327a07a760839556dbf6f
    Reviewed-on: https://gerrit.libreoffice.org/38298
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/filter/Configuration_filter.mk b/filter/Configuration_filter.mk
index 7f3843cd47fe..0ed0d6170419 100644
--- a/filter/Configuration_filter.mk
+++ b/filter/Configuration_filter.mk
@@ -342,6 +342,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_writer_types.xcu
 	writer8 \
 	writer_MS_Word_2007_XML \
 	writer_MS_Word_2007_XML_Template \
+	writer_MS_Word_2007_XML_VBA \
 	writer_OOXML \
 	writer_OOXML_Template \
 	writer_layout_dump_xml \
@@ -388,6 +389,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_writer_filters
 	writer8_template \
 	MS_Word_2007_XML \
 	MS_Word_2007_XML_Template \
+	MS_Word_2007_XML_VBA \
 	OOXML_Text \
 	OOXML_Text_Template \
 	writer_layout_dump \
diff --git a/filter/source/config/fragments/filters/MS_Word_2007_XML_VBA.xcu b/filter/source/config/fragments/filters/MS_Word_2007_XML_VBA.xcu
new file mode 100644
index 000000000000..6f4774d42b83
--- /dev/null
+++ b/filter/source/config/fragments/filters/MS_Word_2007_XML_VBA.xcu
@@ -0,0 +1,18 @@
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/.
+-->
+    <node oor:name="MS Word 2007 XML VBA" oor:op="replace">
+        <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER ENCRYPTION PASSWORDTOMODIFY SUPPORTSSIGNING</value></prop>
+        <prop oor:name="UIComponent"/>
+        <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.WriterFilter</value></prop>
+        <prop oor:name="UserData"><value>OXML</value></prop>
+        <prop oor:name="UIName"><value xml:lang="en-US">Microsoft Word 2007-2013 XML VBA</value></prop>
+        <prop oor:name="FileFormatVersion"><value>0</value></prop>
+        <prop oor:name="Type"><value>writer_MS_Word_2007_VBA</value></prop>
+        <prop oor:name="TemplateName"/>
+        <prop oor:name="DocumentService"><value>com.sun.star.text.TextDocument</value></prop>
+    </node>
diff --git a/filter/source/config/fragments/types/writer_MS_Word_2007_XML.xcu b/filter/source/config/fragments/types/writer_MS_Word_2007_XML.xcu
index 9e21ef50de5a..d6c62ddf439d 100644
--- a/filter/source/config/fragments/types/writer_MS_Word_2007_XML.xcu
+++ b/filter/source/config/fragments/types/writer_MS_Word_2007_XML.xcu
@@ -18,7 +18,7 @@
     <node oor:name="writer_MS_Word_2007" oor:op="replace" >
     <prop oor:name="DetectService"><value>com.sun.star.comp.oox.FormatDetector</value></prop>
         <prop oor:name="URLPattern"/>
-        <prop oor:name="Extensions"><value>docx docm</value></prop>
+        <prop oor:name="Extensions"><value>docx</value></prop>
         <prop oor:name="MediaType"><value>application/msword</value></prop>
         <prop oor:name="Preferred"><value>true</value></prop>
         <prop oor:name="PreferredFilter"><value>MS Word 2007 XML</value></prop>
diff --git a/filter/source/config/fragments/types/writer_MS_Word_2007_XML_VBA.xcu b/filter/source/config/fragments/types/writer_MS_Word_2007_XML_VBA.xcu
new file mode 100644
index 000000000000..5ee986fc8d83
--- /dev/null
+++ b/filter/source/config/fragments/types/writer_MS_Word_2007_XML_VBA.xcu
@@ -0,0 +1,17 @@
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/.
+-->
+    <node oor:name="writer_MS_Word_2007_VBA" oor:op="replace" >
+    <prop oor:name="DetectService"><value>com.sun.star.comp.oox.FormatDetector</value></prop>
+        <prop oor:name="URLPattern"/>
+        <prop oor:name="Extensions"><value>docm</value></prop>
+        <prop oor:name="MediaType"><value>application/msword</value></prop>
+        <prop oor:name="Preferred"><value>true</value></prop>
+        <prop oor:name="PreferredFilter"><value>MS Word 2007 XML VBA</value></prop>
+        <prop oor:name="UIName"><value xml:lang="en-US">Microsoft Word 2007-2013 XML VBA</value></prop>
+        <prop oor:name="ClipboardFormat"><value>MSWordDoc</value></prop>
+    </node>
diff --git a/oox/source/core/filterdetect.cxx b/oox/source/core/filterdetect.cxx
index d397ae3a4b9b..1882572f12d5 100644
--- a/oox/source/core/filterdetect.cxx
+++ b/oox/source/core/filterdetect.cxx
@@ -162,10 +162,12 @@ void FilterDetectDocHandler::parseRelationship( const AttributeList& rAttribs )
 
 OUString FilterDetectDocHandler::getFilterNameFromContentType( const OUString& rContentType )
 {
-    if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" ||
-        rContentType == "application/vnd.ms-word.document.macroEnabled.main+xml" )
+    if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" )
         return OUString( "writer_MS_Word_2007" );
 
+    if( rContentType == "application/vnd.ms-word.document.macroEnabled.main+xml" )
+        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" );
diff --git a/sw/qa/extras/ooxmlexport/data/hello.docm b/sw/qa/extras/ooxmlexport/data/hello.docm
new file mode 100644
index 000000000000..a00aa58e7ba5
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/hello.docm differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
index 8e263e2c9f3d..9d1a5e161fcc 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
@@ -39,6 +39,15 @@ protected:
     }
 };
 
+class DocmTest : public SwModelTestBase
+{
+public:
+    DocmTest()
+        : SwModelTestBase("/sw/qa/extras/ooxmlexport/data/", "MS Word 2007 XML VBA")
+    {
+    }
+};
+
 DECLARE_OOXMLEXPORT_TEST(testFdo55381, "fdo55381.docx")
 {
     uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
@@ -49,6 +58,30 @@ DECLARE_OOXMLEXPORT_TEST(testFdo55381, "fdo55381.docx")
     //TODO: frames not located on the correct pages
 }
 
+DECLARE_OOXMLEXPORT_TEST(testDocm, "hello.docm")
+{
+    // Make sure that we check the name of the export filter.
+    // This was application/vnd.ms-word.document.macroEnabled.main+xml when the
+    // name of the import filter was checked.
+    if (xmlDocPtr pXmlDoc = parseExport("[Content_Types].xml"))
+        assertXPath(pXmlDoc,
+                    "/ContentType:Types/ContentType:Override[@PartName='/word/document.xml']",
+                    "ContentType",
+                    "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");
+}
+
+DECLARE_SW_ROUNDTRIP_TEST(testDocmSave, "hello.docm", nullptr, DocmTest)
+{
+    // This was
+    // application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml,
+    // we used the wrong content type for .docm files.
+    if (xmlDocPtr pXmlDoc = parseExport("[Content_Types].xml"))
+        assertXPath(pXmlDoc,
+                    "/ContentType:Types/ContentType:Override[@PartName='/word/document.xml']",
+                    "ContentType",
+                    "application/vnd.ms-word.document.macroEnabled.main+xml");
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf92045, "tdf92045.docx")
 {
     // This was true, <w:effect w:val="none"/> resulted in setting the blinking font effect.
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index e06585d4ee5a..57432c9add87 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -1447,7 +1447,7 @@ void DocxExport::SetFS( ::sax_fastparser::FSHelperPtr const & pFS )
     mpFS = pFS;
 }
 
-DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM *pOriginalPam )
+DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM *pOriginalPam, bool bDocm )
     : MSWordExportBase( pDocument, pCurrentPam, pOriginalPam ),
       m_pFilter( pFilter ),
       m_pAttrOutput( nullptr ),
@@ -1457,7 +1457,8 @@ DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCur
       m_nOLEObjects( 0 ),
       m_nHeadersFootersInSection(0),
       m_pVMLExport( nullptr ),
-      m_pSdrExport( nullptr )
+      m_pSdrExport( nullptr ),
+      m_bDocm(bDocm)
 {
     // Write the document properies
     WriteProperties( );
@@ -1466,9 +1467,12 @@ DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCur
     m_pFilter->addRelation( oox::getRelationship(Relationship::OFFICEDOCUMENT),
             "word/document.xml" );
 
+    // DOCM needs a different media type for the document.xml stream.
+    OUString aMediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";
+    if (m_bDocm)
+        aMediaType = "application/vnd.ms-word.document.macroEnabled.main+xml";
     // the actual document
-    m_pDocumentFS = m_pFilter->openFragmentStreamWithSerializer( "word/document.xml",
-            "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" );
+    m_pDocumentFS = m_pFilter->openFragmentStreamWithSerializer( "word/document.xml", aMediaType );
 
     SetFS(m_pDocumentFS);
 
diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx
index 99d1368c553f..454e0742cee1 100644
--- a/sw/source/filter/ww8/docxexport.hxx
+++ b/sw/source/filter/ww8/docxexport.hxx
@@ -100,6 +100,9 @@ class DocxExport : public MSWordExportBase
     /// Exporter of drawings.
     DocxSdrExport* m_pSdrExport;
 
+    /// If the result will be a .docm file or not.
+    bool m_bDocm;
+
     DocxSettingsData m_aSettings;
 
 public:
@@ -254,7 +257,7 @@ public:
 
     /// Pass the pDocument, pCurrentPam and pOriginalPam to the base class.
     DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument,
-            SwPaM *pCurrentPam, SwPaM *pOriginalPam );
+            SwPaM *pCurrentPam, SwPaM *pOriginalPam, bool bDocm );
 
     /// Destructor.
     virtual ~DocxExport() override;
diff --git a/sw/source/filter/ww8/docxexportfilter.cxx b/sw/source/filter/ww8/docxexportfilter.cxx
index 31b58968b591..e0c2522e29e3 100644
--- a/sw/source/filter/ww8/docxexportfilter.cxx
+++ b/sw/source/filter/ww8/docxexportfilter.cxx
@@ -30,6 +30,7 @@
 #include <IDocumentLayoutAccess.hxx>
 
 #include <cppuhelper/implementationentry.hxx>
+#include <unotools/mediadescriptor.hxx>
 
 using namespace ::comphelper;
 using namespace ::com::sun::star;
@@ -74,10 +75,14 @@ bool DocxExportFilter::exportDocument()
 
     std::unique_ptr<SwPaM> pCurPam( new SwPaM( *aPam.End(), *aPam.Start() ) );
 
+    OUString aFilterName;
+    getMediaDescriptor()[utl::MediaDescriptor::PROP_FILTERNAME()] >>= aFilterName;
+    bool bDocm = aFilterName.endsWith("VBA");
+
     // export the document
     // (in a separate block so that it's destructed before the commit)
     {
-        DocxExport aExport( this, pDoc, pCurPam.get(), &aPam );
+        DocxExport aExport( this, pDoc, pCurPam.get(), &aPam, bDocm );
         aExport.ExportDocument( true ); // FIXME support exporting selection only
     }
 


More information about the Libreoffice-commits mailing list