summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorsushil_shinde <sushil.shinde@synerzip.com>2013-11-01 19:21:01 +0530
committerMiklos Vajna <vmiklos@collabora.co.uk>2013-11-05 09:07:07 -0600
commit8ab553117e038ec1eab76ac1c3d8a0b5aa968baa (patch)
tree1945d427ef1d7789029b6a37c131d05e136854c2 /sw
parent0794e9ec93be4cfa11daefdb2e428952ea7669a5 (diff)
[docx] CustomXml saved in InteropGrabBag and exported customxml when saving.
The XDocuments representing the DOM of an OOXML's customxml document is stored as the PropertyValue "OOXCustomXml" into the "InteropGraBag". Added mxCustomXmlDomList object which holds xDocuments for each item.xml from CustomXml. Exporting all items dom tree from customxml that has been parsed when loading the file. This is necessary in order to properly reopen docx files that contain data like citation. This fix grab bags only item[n].xml's files from CustomXml folder. itemProps[n].xml's and item.xml's .rels are not preserved and exported yet. (Working on this part) Change-Id: I330f34f38a7aa4cd39094371bff15ebbc0318167 Reviewed-on: https://gerrit.libreoffice.org/6519 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
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 );