diff options
author | Vasily Melenchuk <vasily.melenchuk@cib.de> | 2018-12-11 19:47:25 +0300 |
---|---|---|
committer | Katarina Behrens <Katarina.Behrens@cib.de> | 2018-12-14 11:42:44 +0100 |
commit | 0932e4bb9a4e4a25be092dcf87a0119d1894ac30 (patch) | |
tree | 5cbec163bad58a354b39b9816bf55757b6998c29 | |
parent | 44416a16f40167cf9a60ff6fc7990a07df4e7d7b (diff) |
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 <Katarina.Behrens@cib.de>
-rw-r--r-- | filter/source/config/fragments/filters/OOXML_Text_Template.xcu | 2 | ||||
-rw-r--r-- | include/oox/core/filterbase.hxx | 2 | ||||
-rw-r--r-- | oox/source/core/filterbase.cxx | 21 | ||||
-rw-r--r-- | sw/CppunitTest_sw_ooxmlexport_template.mk | 14 | ||||
-rw-r--r-- | sw/Module_sw.mk | 1 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/sample.dotx | bin | 0 -> 11338 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport_template.cxx | 44 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 34 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.hxx | 7 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexportfilter.cxx | 2 | ||||
-rw-r--r-- | writerfilter/source/filter/WriterFilter.cxx | 10 |
11 files changed, 122 insertions, 15 deletions
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 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 <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) { } @@ -421,10 +425,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; @@ -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<SfxFilterFlags>(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 Binary files differnew file mode 100644 index 000000000000..c0f4062c1e25 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/sample.dotx 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 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<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) @@ -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<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); 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() |