diff options
-rw-r--r-- | sw/qa/extras/rtfimport/data/custom-doc-props.rtf | 10 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 10 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfcontrolwords.hxx | 1 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 41 |
4 files changed, 62 insertions, 0 deletions
diff --git a/sw/qa/extras/rtfimport/data/custom-doc-props.rtf b/sw/qa/extras/rtfimport/data/custom-doc-props.rtf new file mode 100644 index 000000000000..b36d864f2969 --- /dev/null +++ b/sw/qa/extras/rtfimport/data/custom-doc-props.rtf @@ -0,0 +1,10 @@ +{\rtf1 +{\*\userprops +{\propname urn:bails:IntellectualProperty:Authorization:StartValidity} +\proptype30 +{\staticval 2016-03-08T10:55:18,531376147} +{\propname urn:bails:IntellectualProperty:Authorization:StopValidity} +\proptype30 +{\staticval None} +} +} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index d98b9b9ccd62..6ee872955725 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -2525,6 +2525,16 @@ 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/writerfilter/source/rtftok/rtfcontrolwords.hxx b/writerfilter/source/rtftok/rtfcontrolwords.hxx index dab8196fbc2a..80a2d1e465ed 100644 --- a/writerfilter/source/rtftok/rtfcontrolwords.hxx +++ b/writerfilter/source/rtftok/rtfcontrolwords.hxx @@ -158,6 +158,7 @@ enum class Destination TOCENTRY, USERPROPS, PROPNAME, + STATICVAL, }; enum RTFKeyword diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 1fa5cbc879be..6dd561b47d11 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -1291,6 +1291,7 @@ void RTFDocumentImpl::text(OUString& rString) case Destination::INDEXENTRY: case Destination::TOCENTRY: case Destination::PROPNAME: + case Destination::STATICVAL: m_aStates.top().pDestinationText->append(rString); break; default: @@ -2059,6 +2060,9 @@ RTFError RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword) case RTF_PROPNAME: m_aStates.top().eDestination = Destination::PROPNAME; break; + case RTF_STATICVAL: + m_aStates.top().eDestination = Destination::STATICVAL; + break; default: { // Check if it's a math token. @@ -5108,6 +5112,14 @@ void RTFDocumentImpl::resetAttributes() m_aStates.top().aParagraphAttributes.clear(); } +bool lcl_containsProperty(const uno::Sequence<beans::Property>& rProperties, const OUString& rName) +{ + return std::find_if(rProperties.begin(), rProperties.end(), [&](const beans::Property& rProperty) + { + return rProperty.Name == rName; + }) != rProperties.end(); +} + RTFError RTFDocumentImpl::popState() { //SAL_INFO("writerfilter", OSL_THIS_FUNC << " before pop: m_pTokenizer->getGroup() " << m_pTokenizer->getGroup() << @@ -5897,6 +5909,35 @@ RTFError RTFDocumentImpl::popState() break; // not for nested group aState.aPropName = m_aStates.top().pDestinationText->makeStringAndClear(); break; + case Destination::STATICVAL: + if (&m_aStates.top().aDestinationText != m_aStates.top().pDestinationText) + break; // not for nested group + if (m_xDocumentProperties.is()) + { + // Find out what is the key, value type and value we want to set. + uno::Reference<beans::XPropertyContainer> xPropertyContainer = m_xDocumentProperties->getUserDefinedProperties(); + uno::Reference<beans::XPropertySet> xPropertySet(xPropertyContainer, uno::UNO_QUERY); + uno::Sequence<beans::Property> aProperties = xPropertySet->getPropertySetInfo()->getProperties(); + const OUString& rKey = m_aStates.top().aPropName; + OUString aStaticVal = m_aStates.top().pDestinationText->makeStringAndClear(); + uno::Any aAny; + if (m_aStates.top().aPropType == cppu::UnoType<OUString>::get()) + aAny = uno::makeAny(aStaticVal); + + // Set it. + try + { + if (lcl_containsProperty(aProperties, rKey)) + xPropertySet->setPropertyValue(rKey, aAny); + else + xPropertyContainer->addProperty(rKey, beans::PropertyAttribute::REMOVABLE, aAny); + } + catch (const uno::Exception& rException) + { + SAL_WARN("writerfilter", "failed to set property " << rKey << ": " << rException.Message); + } + } + break; default: break; } |