summaryrefslogtreecommitdiff
path: root/writerfilter/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-03-09 12:21:36 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-03-09 14:18:28 +0100
commit8ff32dc66e3adb00209c82bddebfbeb47a275066 (patch)
tree0bf7c95f039fc1cb38460aad5e550121d599f2d2 /writerfilter/source
parentd11b43fe02a6daf2384d50de14f98fbfd55c180e (diff)
RTF import: handle \staticval
With this, user-defined document properties are imported from RTF. Change-Id: I8dfb8e802bd26906827620550d6f5d88f047d364
Diffstat (limited to 'writerfilter/source')
-rw-r--r--writerfilter/source/rtftok/rtfcontrolwords.hxx1
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx41
2 files changed, 42 insertions, 0 deletions
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;
}