summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/ooxmlexport/data/customxml.docxbin0 -> 23402 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport.cxx28
-rw-r--r--sw/source/filter/ww8/docxexport.cxx43
-rw-r--r--sw/source/filter/ww8/docxexport.hxx1
4 files changed, 72 insertions, 0 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/customxml.docx b/sw/qa/extras/ooxmlexport/data/customxml.docx
new file mode 100644
index 000000000000..bfdf8ece682d
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/customxml.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index f8b79041645d..028189b18881 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -1506,6 +1506,34 @@ DECLARE_OOXML_TEST(testCharHighlight, "char_highlight.docx")
}
}
+DECLARE_OOXML_TEST(testCustomXmlGrabBag, "customxml.docx")
+{
+ // The problem was that CustomXml/item[n].xml files were missing from docx file after saving file.
+ // This test case tests whether customxml files grabbagged properly in correct object.
+
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xTextDocumentPropertySet(xTextDocument, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aGrabBag(0);
+ xTextDocumentPropertySet->getPropertyValue(OUString("InteropGrabBag")) >>= aGrabBag;
+ CPPUNIT_ASSERT(aGrabBag.hasElements()); // Grab Bag not empty
+ sal_Bool CustomXml = sal_False;
+ for(int i = 0; i < aGrabBag.getLength(); ++i)
+ {
+ if (aGrabBag[i].Name == OUString("OOXCustomXml"))
+ {
+ CustomXml = sal_True;
+ uno::Reference<xml::dom::XDocument> aCustomXmlDom;
+ uno::Sequence<uno::Reference<xml::dom::XDocument> > aCustomXmlDomList;
+ CPPUNIT_ASSERT(aGrabBag[i].Value >>= aCustomXmlDomList); // PropertyValue of proper type
+ sal_Int32 length = aCustomXmlDomList.getLength();
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(3), length);
+ aCustomXmlDom = aCustomXmlDomList[1];
+ CPPUNIT_ASSERT(aCustomXmlDom.get()); // Reference not empty
+ }
+ }
+ CPPUNIT_ASSERT(CustomXml); // Grab Bag has all the expected elements
+}
+
#endif
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index 69fc7e94937d..40112cf31455 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -351,6 +351,8 @@ void DocxExport::ExportDocument_Impl()
WriteTheme();
+ WriteCustomXml();
+
delete pStyles, pStyles = NULL;
delete m_pSections, m_pSections = NULL;
}
@@ -782,6 +784,47 @@ void DocxExport::WriteTheme()
uno::Sequence< beans::StringPair >() );
}
+void DocxExport::WriteCustomXml()
+{
+ uno::Reference< beans::XPropertySet > xPropSet( pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
+
+ uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
+ OUString pName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
+ if ( !xPropSetInfo->hasPropertyByName( pName ) )
+ return;
+
+ uno::Sequence<uno::Reference<xml::dom::XDocument> > customXmlDomlist;
+ uno::Sequence< beans::PropertyValue > propList;
+ xPropSet->getPropertyValue( pName ) >>= propList;
+ for ( sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp )
+ {
+ OUString propName = propList[nProp].Name;
+ if ( propName == "OOXCustomXml" )
+ {
+ propList[nProp].Value >>= customXmlDomlist;
+ break;
+ }
+ }
+
+ for (sal_Int32 j = 1; j < customXmlDomlist.getLength(); j++) {
+
+ uno::Reference<xml::dom::XDocument> customXmlDom = customXmlDomlist[j];
+ if ( customXmlDom.is() )
+ {
+ m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml",
+ "../customXml/item"+OUString::number(j)+".xml" );
+
+ uno::Reference< xml::sax::XSAXSerializable > serializer( customXmlDom, uno::UNO_QUERY );
+ uno::Reference< xml::sax::XWriter > writer = xml::sax::Writer::create( comphelper::getProcessComponentContext() );
+ writer->setOutputStream( GetFilter().openFragmentStream( "customXml/item"+OUString::number(j)+".xml",
+ "application/xml" ) );
+ serializer->serialize( uno::Reference< xml::sax::XDocumentHandler >( writer, uno::UNO_QUERY_THROW ),
+ uno::Sequence< beans::StringPair >() );
+ }
+ }
+}
+
VMLExport& DocxExport::VMLExporter()
{
return *m_pVMLExport;
diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx
index 18017d1fbe5e..531dcc511e5c 100644
--- a/sw/source/filter/ww8/docxexport.hxx
+++ b/sw/source/filter/ww8/docxexport.hxx
@@ -207,6 +207,7 @@ private:
/// Write word/theme/theme1.xml
void WriteTheme();
+ void WriteCustomXml();
/// All xml namespaces to be used at the top of any text .xml file (main doc, headers, footers,...)
sax_fastparser::XFastAttributeListRef MainXmlNamespaces( sax_fastparser::FSHelperPtr serializer );