diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-03-09 14:41:10 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-03-09 15:58:35 +0100 |
commit | 2e1a6ba26fd0cb251f831dd2a0f60103ca1342e2 (patch) | |
tree | c46ff15e539f9f4af53f321f2211395aa098ff12 | |
parent | b8ad8bf2ca0c875f182b1776579fdcd95a8759a5 (diff) |
RTF export: write user-defined document properties
Change-Id: I07dfd626f7d248e264fd1724f6f2bd1241be39d0
-rw-r--r-- | sw/qa/extras/rtfexport/data/custom-doc-props.rtf (renamed from sw/qa/extras/rtfimport/data/custom-doc-props.rtf) | 0 | ||||
-rw-r--r-- | sw/qa/extras/rtfexport/rtfexport.cxx | 10 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 10 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfexport.cxx | 53 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfexport.hxx | 2 |
5 files changed, 65 insertions, 10 deletions
diff --git a/sw/qa/extras/rtfimport/data/custom-doc-props.rtf b/sw/qa/extras/rtfexport/data/custom-doc-props.rtf index b36d864f2969..b36d864f2969 100644 --- a/sw/qa/extras/rtfimport/data/custom-doc-props.rtf +++ b/sw/qa/extras/rtfexport/data/custom-doc-props.rtf diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index 60a2293c99fb..24faee23a2f2 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -989,6 +989,16 @@ DECLARE_RTFEXPORT_TEST(testRedline, "redline.rtf") CPPUNIT_ASSERT_EQUAL(OUString("Dorothy Jones"), getProperty<OUString>(getRun(getParagraph(2), 2), "RedlineAuthor")); } +DECLARE_RTFEXPORT_TEST(testCustomDocProps, "custom-doc-props.rtf") +{ + // Custom document properties were not improved, this resulted in a beans::UnknownPropertyException. + uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<document::XDocumentProperties> xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties(); + uno::Reference<beans::XPropertyContainer> xUserDefinedProperties = xDocumentProperties->getUserDefinedProperties(); + CPPUNIT_ASSERT_EQUAL(OUString("2016-03-08T10:55:18,531376147"), getProperty<OUString>(xUserDefinedProperties, "urn:bails:IntellectualProperty:Authorization:StartValidity")); + CPPUNIT_ASSERT_EQUAL(OUString("None"), getProperty<OUString>(xUserDefinedProperties, "urn:bails:IntellectualProperty:Authorization:StopValidity")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 6ee872955725..d98b9b9ccd62 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -2525,16 +2525,6 @@ DECLARE_RTFIMPORT_TEST(testTdf87034, "tdf87034.rtf") CPPUNIT_ASSERT_EQUAL(OUString("A1B3C4D"), getParagraph(1)->getString()); } -DECLARE_RTFIMPORT_TEST(testCustomDocProps, "custom-doc-props.rtf") -{ - // Custom document properties were not improved, this resulted in a beans::UnknownPropertyException. - uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<document::XDocumentProperties> xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties(); - uno::Reference<beans::XPropertyContainer> xUserDefinedProperties = xDocumentProperties->getUserDefinedProperties(); - CPPUNIT_ASSERT_EQUAL(OUString("2016-03-08T10:55:18,531376147"), getProperty<OUString>(xUserDefinedProperties, "urn:bails:IntellectualProperty:Authorization:StartValidity")); - CPPUNIT_ASSERT_EQUAL(OUString("None"), getProperty<OUString>(xUserDefinedProperties, "urn:bails:IntellectualProperty:Authorization:StopValidity")); -} - CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index 8292557304fa..2c3c88be8087 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -474,6 +474,58 @@ void RtfExport::WriteInfo() Strm().WriteChar('}'); } +void RtfExport::WriteUserProps() +{ + Strm().WriteChar('{').WriteCharPtr(OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_USERPROPS); + + SwDocShell* pDocShell(m_pDoc->GetDocShell()); + uno::Reference<document::XDocumentProperties> xDocProps; + if (pDocShell) + { + uno::Reference<document::XDocumentPropertiesSupplier> xDPS(pDocShell->GetModel(), uno::UNO_QUERY); + xDocProps.set(xDPS->getDocumentProperties()); + } + + if (xDocProps.is()) + { + // Handle user-defined properties. + uno::Reference<beans::XPropertyContainer> xUserDefinedProperties = xDocProps->getUserDefinedProperties(); + if (xUserDefinedProperties.is()) + { + uno::Reference<beans::XPropertySet> xPropertySet(xUserDefinedProperties, uno::UNO_QUERY); + uno::Sequence<beans::Property> aProperties = xPropertySet->getPropertySetInfo()->getProperties(); + + for (const beans::Property& rProperty : aProperties) + { + if (rProperty.Name.startsWith("Company")) + // We have explicit markup in RTF for this property. + continue; + + // Property name. + Strm().WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_PROPNAME " "); + Strm().WriteCharPtr(msfilter::rtfutil::OutString(rProperty.Name, m_eDefaultEncoding).getStr()); + Strm().WriteChar('}'); + + // Property value type. + OUString aValue; + if (xPropertySet->getPropertyValue(rProperty.Name) >>= aValue) + { + Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PROPTYPE); + OutULong(30); + } + + // Property value. + Strm().WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_STATICVAL " "); + Strm().WriteCharPtr(msfilter::rtfutil::OutString(aValue, m_eDefaultEncoding).getStr()); + Strm().WriteChar('}'); + } + } + + } + + Strm().WriteChar('}'); +} + void RtfExport::WritePageDescTable() { // Write page descriptions (page styles) @@ -535,6 +587,7 @@ void RtfExport::ExportDocument_Impl() WriteRevTab(); WriteInfo(); + WriteUserProps(); // Default TabSize Strm().WriteCharPtr(m_pAttrOutput->m_aTabStop.makeStringAndClear().getStr()).WriteCharPtr(SAL_NEWLINE_STRING); diff --git a/sw/source/filter/ww8/rtfexport.hxx b/sw/source/filter/ww8/rtfexport.hxx index 845dfc7c0e7e..ecef9ee60217 100644 --- a/sw/source/filter/ww8/rtfexport.hxx +++ b/sw/source/filter/ww8/rtfexport.hxx @@ -204,6 +204,8 @@ private: void WriteFootnoteSettings(); void WriteMainText(); void WriteInfo(); + /// Writes the userprops group: user defined document properties. + void WriteUserProps(); /// Writes the writer-specific \pgdsctbl group. void WritePageDescTable(); /// This is necessary to have the numbering table ready before the main text is being processed. |