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>
This commit is contained in:
parent
44416a16f4
commit
0932e4bb9a
11 changed files with 122 additions and 15 deletions
|
@ -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>
|
||||
|
|
|
@ -236,6 +236,8 @@ public:
|
|||
|
||||
bool exportVBA() const;
|
||||
|
||||
bool isExportTemplate() const;
|
||||
|
||||
protected:
|
||||
virtual css::uno::Reference< css::io::XInputStream >
|
||||
implGetInputStream( utl::MediaDescriptor& rMediaDesc ) const;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
14
sw/CppunitTest_sw_ooxmlexport_template.mk
Normal file
14
sw/CppunitTest_sw_ooxmlexport_template.mk
Normal file
|
@ -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:
|
|
@ -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 \
|
||||
|
|
BIN
sw/qa/extras/ooxmlexport/data/sample.dotx
Normal file
BIN
sw/qa/extras/ooxmlexport/data/sample.dotx
Normal file
Binary file not shown.
44
sw/qa/extras/ooxmlexport/ooxmlexport_template.cxx
Normal file
44
sw/qa/extras/ooxmlexport/ooxmlexport_template.cxx
Normal file
|
@ -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: */
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue