[Libreoffice-commits] core.git: Branch 'distro/lhm/libreoffice-6-1+backports' - filter/source include/oox oox/source sw/CppunitTest_sw_ooxmlexport_template.mk sw/Module_sw.mk sw/qa sw/source writerfilter/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Dec 18 10:39:33 UTC 2018


 filter/source/config/fragments/filters/OOXML_Text_Template.xcu |    2 
 include/oox/core/filterbase.hxx                                |    2 
 oox/source/core/filterbase.cxx                                 |   21 +++-
 sw/CppunitTest_sw_ooxmlexport_template.mk                      |   14 +++
 sw/Module_sw.mk                                                |    1 
 sw/qa/extras/ooxmlexport/data/sample.dotx                      |binary
 sw/qa/extras/ooxmlexport/ooxmlexport_template.cxx              |   44 ++++++++++
 sw/source/filter/ww8/docxexport.cxx                            |   34 ++++++-
 sw/source/filter/ww8/docxexport.hxx                            |    7 +
 sw/source/filter/ww8/docxexportfilter.cxx                      |    2 
 writerfilter/source/filter/WriterFilter.cxx                    |   10 +-
 11 files changed, 122 insertions(+), 15 deletions(-)

New commits:
commit be5730dc4c97e813ade617227e79b9340f7f613a
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Tue Dec 11 19:47:25 2018 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Tue Dec 18 11:39:11 2018 +0100

    sw: support for saving into .dotx file
    
    Template format now supported not only for import, but for
    export too.
    
    Change-Id: Id55651a23067e882c95b1ce4be25a4fd3d08de6d
    Reviewed-on: https://gerrit.libreoffice.org/64947
    Tested-by: Jenkins
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>
    Reviewed-on: https://gerrit.libreoffice.org/65321
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/filter/source/config/fragments/filters/OOXML_Text_Template.xcu b/filter/source/config/fragments/filters/OOXML_Text_Template.xcu
index b27998c8d6af..90fd38bf6b2a 100644
--- a/filter/source/config/fragments/filters/OOXML_Text_Template.xcu
+++ b/filter/source/config/fragments/filters/OOXML_Text_Template.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="Office Open XML Text Template" oor:op="replace">
-        <prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER TEMPLATE TEMPLATEPATH</value></prop>
+        <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER TEMPLATE TEMPLATEPATH</value></prop>
         <prop oor:name="UIComponent"/>
         <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.WriterFilter</value></prop>
         <prop oor:name="UserData"><value></value></prop>
diff --git a/include/oox/core/filterbase.hxx b/include/oox/core/filterbase.hxx
index 790d8d94b436..dbab52c3cd76 100644
--- a/include/oox/core/filterbase.hxx
+++ b/include/oox/core/filterbase.hxx
@@ -240,6 +240,8 @@ public:
 
     bool exportVBA() const;
 
+    bool isExportTemplate() const;
+
 protected:
     virtual css::uno::Reference< css::io::XInputStream >
                         implGetInputStream( utl::MediaDescriptor& rMediaDesc ) const;
diff --git a/oox/source/core/filterbase.cxx b/oox/source/core/filterbase.cxx
index c24c61c2fa15..46259a8e1809 100644
--- a/oox/source/core/filterbase.cxx
+++ b/oox/source/core/filterbase.cxx
@@ -28,6 +28,7 @@
 #include <com/sun/star/task/XStatusIndicator.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <cppuhelper/supportsservice.hxx>
+#include <comphelper/documentconstants.hxx>
 #include <unotools/mediadescriptor.hxx>
 #include <osl/mutex.hxx>
 #include <osl/diagnose.h>
@@ -150,6 +151,8 @@ struct FilterBaseImpl
 
     bool mbExportVBA;
 
+    bool mbExportTemplate;
+
     /// @throws RuntimeException
     explicit            FilterBaseImpl( const Reference< XComponentContext >& rxContext );
 
@@ -163,7 +166,8 @@ FilterBaseImpl::FilterBaseImpl( const Reference< XComponentContext >& rxContext
     meDirection( FILTERDIRECTION_UNKNOWN ),
     meVersion( ECMA_DIALECT ),
     mxComponentContext( rxContext, UNO_SET_THROW ),
-    mbExportVBA(false)
+    mbExportVBA(false),
+    mbExportTemplate(false)
 {
 }
 
@@ -426,10 +430,8 @@ void SAL_CALL FilterBase::initialize( const Sequence< Any >& rArgs )
     {
         Sequence<css::beans::PropertyValue> aSeq;
         rArgs[0] >>= aSeq;
-        sal_Int32 nLen = aSeq.getLength();
-        for (sal_Int32 i = 0; i < nLen; ++i)
+        for (const auto& rVal : aSeq)
         {
-            css::beans::PropertyValue& rVal = aSeq[i];
             if (rVal.Name == "UserData")
             {
                 css::uno::Sequence<OUString> aUserDataSeq;
@@ -443,6 +445,12 @@ void SAL_CALL FilterBase::initialize( const Sequence< Any >& rArgs )
                     }
                 }
             }
+            else if (rVal.Name == "Flags")
+            {
+                sal_Int32 nFlags;
+                rVal.Value >>= nFlags;
+                mxImpl->mbExportTemplate = bool(static_cast<SfxFilterFlags>(nFlags) & SfxFilterFlags::TEMPLATE);
+            }
         }
     }
 }
@@ -586,6 +594,11 @@ bool FilterBase::exportVBA() const
     return mxImpl->mbExportVBA;
 }
 
+bool FilterBase::isExportTemplate() const
+{
+    return mxImpl->mbExportTemplate;
+}
+
 } // namespace core
 } // namespace oox
 
diff --git a/sw/CppunitTest_sw_ooxmlexport_template.mk b/sw/CppunitTest_sw_ooxmlexport_template.mk
new file mode 100644
index 000000000000..79bb3b70a59b
--- /dev/null
+++ b/sw/CppunitTest_sw_ooxmlexport_template.mk
@@ -0,0 +1,14 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# 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/.
+#
+#*************************************************************************
+
+$(eval $(call sw_ooxmlexport_test,_template))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index d36b96a94cfe..def5b6623763 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -72,6 +72,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_ooxmlexport10 \
     CppunitTest_sw_ooxmlexport11 \
     CppunitTest_sw_ooxmlexport12 \
+    CppunitTest_sw_ooxmlexport_template \
     CppunitTest_sw_ooxmlfieldexport \
     CppunitTest_sw_ooxmllinks \
     CppunitTest_sw_ooxmlw14export \
diff --git a/sw/qa/extras/ooxmlexport/data/sample.dotx b/sw/qa/extras/ooxmlexport/data/sample.dotx
new file mode 100644
index 000000000000..c0f4062c1e25
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/sample.dotx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport_template.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport_template.cxx
new file mode 100644
index 000000000000..bb1c813a733f
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport_template.cxx
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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/.
+ */
+
+#include <swmodeltestbase.hxx>
+#include <string>
+
+class Test : public SwModelTestBase
+{
+public:
+    Test()
+        : SwModelTestBase("/sw/qa/extras/ooxmlexport/data/", "Office Open XML Text Template")
+    {
+    }
+
+protected:
+    bool mustTestImportOf(const char* filename) const override
+    {
+        return OString(filename).endsWith(".dotx");
+    }
+};
+
+DECLARE_OOXMLEXPORT_TEST(testSaveAsDotX, "sample.dotx")
+{
+    xmlDocPtr pXmlDocCT = parseExport("[Content_Types].xml");
+
+    if (!pXmlDocCT)
+        return;
+
+    // Ensure that document has correct content type
+    assertXPath(pXmlDocCT,
+                "/ContentType:Types/ContentType:Override[@PartName='/word/document.xml']",
+                "ContentType",
+                "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml");
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index 1e3f8b86b2b2..431d837c777c 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -1553,7 +1553,8 @@ void DocxExport::SetFS( ::sax_fastparser::FSHelperPtr const & pFS )
     mpFS = pFS;
 }
 
-DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM *pOriginalPam, bool bDocm )
+DocxExport::DocxExport(DocxExportFilter* pFilter, SwDoc* pDocument, SwPaM* pCurrentPam,
+                       SwPaM* pOriginalPam, bool bDocm, bool bTemplate)
     : MSWordExportBase( pDocument, pCurrentPam, pOriginalPam ),
       m_pFilter( pFilter ),
       m_pAttrOutput( nullptr ),
@@ -1565,7 +1566,8 @@ DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCur
       m_nHeadersFootersInSection(0),
       m_pVMLExport( nullptr ),
       m_pSdrExport( nullptr ),
-      m_bDocm(bDocm)
+      m_bDocm(bDocm),
+      m_bTemplate(bTemplate)
 {
     // Write the document properties
     WriteProperties( );
@@ -1574,10 +1576,32 @@ 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";
+    // Set media type depending of document type
+    OUString aMediaType;
     if (m_bDocm)
-        aMediaType = "application/vnd.ms-word.document.macroEnabled.main+xml";
+    {
+        if (m_bTemplate)
+        {
+            aMediaType = "application/vnd.ms-word.template.macroEnabledTemplate.main+xml";
+        }
+        else
+        {
+            aMediaType = "application/vnd.ms-word.document.macroEnabled.main+xml";
+        }
+    }
+    else
+    {
+        if (m_bTemplate)
+        {
+            aMediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml";
+        }
+        else
+        {
+            aMediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";
+        }
+    }
+
+
     // the actual document
     m_pDocumentFS = m_pFilter->openFragmentStreamWithSerializer( "word/document.xml", aMediaType );
 
diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx
index 1f9f188e6225..f4f9b0a1d8b9 100644
--- a/sw/source/filter/ww8/docxexport.hxx
+++ b/sw/source/filter/ww8/docxexport.hxx
@@ -108,6 +108,9 @@ class DocxExport : public MSWordExportBase
     /// If the result will be a .docm file or not.
     bool m_bDocm;
 
+    /// Export is done into template (.dotx)
+    bool const m_bTemplate;
+
     DocxSettingsData m_aSettings;
 
 public:
@@ -265,8 +268,8 @@ public:
     void WriteMainText();
 
     /// Pass the pDocument, pCurrentPam and pOriginalPam to the base class.
-    DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument,
-            SwPaM *pCurrentPam, SwPaM *pOriginalPam, bool bDocm );
+    DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM* pCurrentPam, SwPaM* pOriginalPam,
+               bool bDocm, bool bTemplate);
 
     /// Destructor.
     virtual ~DocxExport() override;
diff --git a/sw/source/filter/ww8/docxexportfilter.cxx b/sw/source/filter/ww8/docxexportfilter.cxx
index 4069289670e0..2e18a6da2969 100644
--- a/sw/source/filter/ww8/docxexportfilter.cxx
+++ b/sw/source/filter/ww8/docxexportfilter.cxx
@@ -82,7 +82,7 @@ bool DocxExportFilter::exportDocument()
     // export the document
     // (in a separate block so that it's destructed before the commit)
     {
-        DocxExport aExport( this, pDoc, pCurPam.get(), &aPam, bDocm );
+        DocxExport aExport(this, pDoc, pCurPam.get(), &aPam, bDocm, isExportTemplate());
         aExport.ExportDocument( true ); // FIXME support exporting selection only
     }
 
diff --git a/writerfilter/source/filter/WriterFilter.cxx b/writerfilter/source/filter/WriterFilter.cxx
index 2953c6cc3f17..3e5b197c90fc 100644
--- a/writerfilter/source/filter/WriterFilter.cxx
+++ b/writerfilter/source/filter/WriterFilter.cxx
@@ -93,6 +93,7 @@ class WriterFilter : public cppu::WeakImplHelper
 {
     uno::Reference<uno::XComponentContext> m_xContext;
     uno::Reference<lang::XComponent> m_xSrcDoc, m_xDstDoc;
+    uno::Sequence<uno::Any> m_xInitializationArguments;
 
 public:
     explicit WriterFilter(uno::Reference<uno::XComponentContext> xContext)
@@ -137,7 +138,11 @@ sal_Bool WriterFilter::filter(const uno::Sequence< beans::PropertyValue >& rDesc
             uno::Any a(cppu::getCaughtException());
             throw lang::WrappedTargetRuntimeException("wrapped " + a.getValueTypeName() + ": " + e.Message, uno::Reference<uno::XInterface>(), a);
         }
-        uno::Reference< document::XExporter > xExprtr(xIfc, uno::UNO_QUERY_THROW);
+
+        uno::Reference<lang::XInitialization> xInit(xIfc, uno::UNO_QUERY_THROW);
+        xInit->initialize(m_xInitializationArguments);
+
+        uno::Reference<document::XExporter> xExprtr(xIfc, uno::UNO_QUERY_THROW);
         uno::Reference< document::XFilter > xFltr(xIfc, uno::UNO_QUERY_THROW);
         if (!xExprtr.is() || !xFltr.is())
             return false;
@@ -307,8 +312,9 @@ void WriterFilter::setSourceDocument(const uno::Reference< lang::XComponent >& x
     m_xSrcDoc = xDoc;
 }
 
-void WriterFilter::initialize(const uno::Sequence< uno::Any >& /*rArguments*/)
+void WriterFilter::initialize(const uno::Sequence< uno::Any >& rArguments)
 {
+    m_xInitializationArguments = rArguments;
 }
 
 OUString WriterFilter::getImplementationName()


More information about the Libreoffice-commits mailing list