Kaydet (Commit) 697173f6 authored tarafından Miklos Vajna's avatar Miklos Vajna

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/38298Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 88ff39ae
...@@ -342,6 +342,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_writer_types.xcu ...@@ -342,6 +342,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_writer_types.xcu
writer8 \ writer8 \
writer_MS_Word_2007_XML \ writer_MS_Word_2007_XML \
writer_MS_Word_2007_XML_Template \ writer_MS_Word_2007_XML_Template \
writer_MS_Word_2007_XML_VBA \
writer_OOXML \ writer_OOXML \
writer_OOXML_Template \ writer_OOXML_Template \
writer_layout_dump_xml \ writer_layout_dump_xml \
...@@ -388,6 +389,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_writer_filters ...@@ -388,6 +389,7 @@ $(eval $(call filter_Configuration_add_filters,fcfg_langpack,fcfg_writer_filters
writer8_template \ writer8_template \
MS_Word_2007_XML \ MS_Word_2007_XML \
MS_Word_2007_XML_Template \ MS_Word_2007_XML_Template \
MS_Word_2007_XML_VBA \
OOXML_Text \ OOXML_Text \
OOXML_Text_Template \ OOXML_Text_Template \
writer_layout_dump \ writer_layout_dump \
......
<!--
* 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>
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<node oor:name="writer_MS_Word_2007" oor:op="replace" > <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="DetectService"><value>com.sun.star.comp.oox.FormatDetector</value></prop>
<prop oor:name="URLPattern"/> <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="MediaType"><value>application/msword</value></prop>
<prop oor:name="Preferred"><value>true</value></prop> <prop oor:name="Preferred"><value>true</value></prop>
<prop oor:name="PreferredFilter"><value>MS Word 2007 XML</value></prop> <prop oor:name="PreferredFilter"><value>MS Word 2007 XML</value></prop>
......
<!--
* 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>
...@@ -162,10 +162,12 @@ void FilterDetectDocHandler::parseRelationship( const AttributeList& rAttribs ) ...@@ -162,10 +162,12 @@ void FilterDetectDocHandler::parseRelationship( const AttributeList& rAttribs )
OUString FilterDetectDocHandler::getFilterNameFromContentType( const OUString& rContentType ) OUString FilterDetectDocHandler::getFilterNameFromContentType( const OUString& rContentType )
{ {
if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" || if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" )
rContentType == "application/vnd.ms-word.document.macroEnabled.main+xml" )
return OUString( "writer_MS_Word_2007" ); 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" || if( rContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml" ||
rContentType == "application/vnd.ms-word.template.macroEnabledTemplate.main+xml" ) rContentType == "application/vnd.ms-word.template.macroEnabledTemplate.main+xml" )
return OUString( "writer_MS_Word_2007_Template" ); return OUString( "writer_MS_Word_2007_Template" );
......
...@@ -39,6 +39,15 @@ protected: ...@@ -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") DECLARE_OOXMLEXPORT_TEST(testFdo55381, "fdo55381.docx")
{ {
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
...@@ -49,6 +58,30 @@ DECLARE_OOXMLEXPORT_TEST(testFdo55381, "fdo55381.docx") ...@@ -49,6 +58,30 @@ DECLARE_OOXMLEXPORT_TEST(testFdo55381, "fdo55381.docx")
//TODO: frames not located on the correct pages //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") DECLARE_OOXMLEXPORT_TEST(testTdf92045, "tdf92045.docx")
{ {
// This was true, <w:effect w:val="none"/> resulted in setting the blinking font effect. // This was true, <w:effect w:val="none"/> resulted in setting the blinking font effect.
......
...@@ -1447,7 +1447,7 @@ void DocxExport::SetFS( ::sax_fastparser::FSHelperPtr const & pFS ) ...@@ -1447,7 +1447,7 @@ void DocxExport::SetFS( ::sax_fastparser::FSHelperPtr const & pFS )
mpFS = 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 ), : MSWordExportBase( pDocument, pCurrentPam, pOriginalPam ),
m_pFilter( pFilter ), m_pFilter( pFilter ),
m_pAttrOutput( nullptr ), m_pAttrOutput( nullptr ),
...@@ -1457,7 +1457,8 @@ DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCur ...@@ -1457,7 +1457,8 @@ DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCur
m_nOLEObjects( 0 ), m_nOLEObjects( 0 ),
m_nHeadersFootersInSection(0), m_nHeadersFootersInSection(0),
m_pVMLExport( nullptr ), m_pVMLExport( nullptr ),
m_pSdrExport( nullptr ) m_pSdrExport( nullptr ),
m_bDocm(bDocm)
{ {
// Write the document properies // Write the document properies
WriteProperties( ); WriteProperties( );
...@@ -1466,9 +1467,12 @@ DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCur ...@@ -1466,9 +1467,12 @@ DocxExport::DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, SwPaM *pCur
m_pFilter->addRelation( oox::getRelationship(Relationship::OFFICEDOCUMENT), m_pFilter->addRelation( oox::getRelationship(Relationship::OFFICEDOCUMENT),
"word/document.xml" ); "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 // the actual document
m_pDocumentFS = m_pFilter->openFragmentStreamWithSerializer( "word/document.xml", m_pDocumentFS = m_pFilter->openFragmentStreamWithSerializer( "word/document.xml", aMediaType );
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" );
SetFS(m_pDocumentFS); SetFS(m_pDocumentFS);
......
...@@ -100,6 +100,9 @@ class DocxExport : public MSWordExportBase ...@@ -100,6 +100,9 @@ class DocxExport : public MSWordExportBase
/// Exporter of drawings. /// Exporter of drawings.
DocxSdrExport* m_pSdrExport; DocxSdrExport* m_pSdrExport;
/// If the result will be a .docm file or not.
bool m_bDocm;
DocxSettingsData m_aSettings; DocxSettingsData m_aSettings;
public: public:
...@@ -254,7 +257,7 @@ public: ...@@ -254,7 +257,7 @@ public:
/// Pass the pDocument, pCurrentPam and pOriginalPam to the base class. /// Pass the pDocument, pCurrentPam and pOriginalPam to the base class.
DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument, DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument,
SwPaM *pCurrentPam, SwPaM *pOriginalPam ); SwPaM *pCurrentPam, SwPaM *pOriginalPam, bool bDocm );
/// Destructor. /// Destructor.
virtual ~DocxExport() override; virtual ~DocxExport() override;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <IDocumentLayoutAccess.hxx> #include <IDocumentLayoutAccess.hxx>
#include <cppuhelper/implementationentry.hxx> #include <cppuhelper/implementationentry.hxx>
#include <unotools/mediadescriptor.hxx>
using namespace ::comphelper; using namespace ::comphelper;
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -74,10 +75,14 @@ bool DocxExportFilter::exportDocument() ...@@ -74,10 +75,14 @@ bool DocxExportFilter::exportDocument()
std::unique_ptr<SwPaM> pCurPam( new SwPaM( *aPam.End(), *aPam.Start() ) ); 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 // export the document
// (in a separate block so that it's destructed before the commit) // (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 aExport.ExportDocument( true ); // FIXME support exporting selection only
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment