From 0932e4bb9a4e4a25be092dcf87a0119d1894ac30 Mon Sep 17 00:00:00 2001 From: Vasily Melenchuk Date: Tue, 11 Dec 2018 19:47:25 +0300 Subject: [PATCH] sw: support for saving into .dotx file Template format now supported not only for import, but for export too. Change-Id: I9fb9da14c4d6466b6979fa37fb2c0359ce5 Reviewed-on: https://gerrit.libreoffice.org/64947 Tested-by: Jenkins Reviewed-by: Katarina Behrens --- .../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 | Bin 0 -> 11338 bytes .../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(-) create mode 100644 sw/CppunitTest_sw_ooxmlexport_template.mk create mode 100644 sw/qa/extras/ooxmlexport/data/sample.dotx create mode 100644 sw/qa/extras/ooxmlexport/ooxmlexport_template.cxx 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 . --> - IMPORT ALIEN 3RDPARTYFILTER TEMPLATE TEMPLATEPATH + IMPORT EXPORT ALIEN 3RDPARTYFILTER TEMPLATE TEMPLATEPATH com.sun.star.comp.Writer.WriterFilter diff --git a/include/oox/core/filterbase.hxx b/include/oox/core/filterbase.hxx index 8bb995b2f7f0..f00885cf3adc 100644 --- a/include/oox/core/filterbase.hxx +++ b/include/oox/core/filterbase.hxx @@ -236,6 +236,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 c19905417114..9b52bff85f84 100644 --- a/oox/source/core/filterbase.cxx +++ b/oox/source/core/filterbase.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -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) { } @@ -421,10 +425,8 @@ void SAL_CALL FilterBase::initialize( const Sequence< Any >& rArgs ) { Sequence 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 aUserDataSeq; @@ -438,6 +440,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(nFlags) & SfxFilterFlags::TEMPLATE); + } } } } @@ -581,6 +589,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 ee052eceb24a..843553c43ca2 100644 --- a/sw/Module_sw.mk +++ b/sw/Module_sw.mk @@ -73,6 +73,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 0000000000000000000000000000000000000000..c0f4062c1e25fcf35e41fd3b9238ae5dc018e232 GIT binary patch literal 11338 zcmeHt1y^0k()PiE6Wrb1-Ge(p1Hs+h50(UXcemgKCqQs_cS4Zh?hfxsX3d>UX1?za z+`HF0d#{$KcAwr=U0qMtYgq_LbifM$3;+Ni0ZcIyG3tT=0K`xL02%-WTuao>*4f0? zSx?o&-o#0V(cQ+HI2RI}IvW5E>i@s%zjy{}6YgHdG^iQw@yx-g%f@ZTd}GPhdWD<##W$7+UIvqYe$hVKh-LsaHCC$hzOzlSc z@daa)L*{dkd zBC-W9&o)F~kVZW}LjYd?%`6FHa2t+6Eeas3g9n+Vo}-Di6BFZ)`~S@Gzt{$U`Riq| z9hP0p2*SsHkA4#^N{b!Xc?wKM<4f2J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MJXc2}}Z zb&)WkD7?Gdvl?)jHx73XdhbR_0cUYn#2%G?L9d#uZn49Ra^du6%VHHv?Yi$txNjKh zq$5fb7xR&_(jWba|DVkutc~(Zeqv9SwI3oCKpkWCKq96oIV#>-#{DVh%b$%uUoyb- zx5mZ%-$tNV$L_Ou2S(XdFC_I*NV}E3@fOK;`+Z9O6Vl`sY4+o)eDzZfIhr*Pl|x8+ z=8FyAvNm&>R_*)BV)vY-&@?;6GxixT_`N$8!h3?EPk2{eY9)vLrZDPRwt>!0G__C5 zvnFGsK1rtie0SCqyZCu;IrN}~I4wSx1~mz>X+E1LJ#ACUvac53c9b*~4zQIf0q-f2 z&Jt&`)McL~DYB9-X9qI9&7WqjG#?-BR&JIR&~@A0o7pahwt~9&H*|c-yqutx(qelN z8M;{|l}S3Ne1df1Z*5 za#H@gh~E!F{t{6QO78e6;@4x5-{HR#vwy)2K!^1|;eVrPf5-n$|NVvM1BLlN@xPIQ zzf1T#3-%Wt0C2?y0DkAhenhU8L5gyP1Vkw+xew6+XXDR&M literal 0 HcmV?d00001 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 +#include + +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 e311e7855ae3..96d41d44bafa 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -1545,7 +1545,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_nHeaders( 0 ), @@ -1553,7 +1554,8 @@ DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCur m_nOLEObjects( 0 ), m_nActiveXControls( 0 ), m_nHeadersFootersInSection(0), - m_bDocm(bDocm) + m_bDocm(bDocm), + m_bTemplate(bTemplate) { // Write the document properties WriteProperties( ); @@ -1562,10 +1564,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 f237460026a9..3852f85f426a 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 const 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 67167e6c7039..cf3163c9f362 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 08bc0c420ec7..5ffad7b17527 100644 --- a/writerfilter/source/filter/WriterFilter.cxx +++ b/writerfilter/source/filter/WriterFilter.cxx @@ -94,6 +94,7 @@ class WriterFilter : public cppu::WeakImplHelper { uno::Reference m_xContext; uno::Reference m_xSrcDoc, m_xDstDoc; + uno::Sequence m_xInitializationArguments; public: explicit WriterFilter(uno::Reference xContext) @@ -138,7 +139,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(), a); } - uno::Reference< document::XExporter > xExprtr(xIfc, uno::UNO_QUERY_THROW); + + uno::Reference xInit(xIfc, uno::UNO_QUERY_THROW); + xInit->initialize(m_xInitializationArguments); + + uno::Reference xExprtr(xIfc, uno::UNO_QUERY_THROW); uno::Reference< document::XFilter > xFltr(xIfc, uno::UNO_QUERY_THROW); xExprtr->setSourceDocument(m_xSrcDoc); return xFltr->filter(rDescriptor); @@ -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()