summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-03-10 08:23:37 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-03-10 14:31:54 +0100
commitb84f5a0efa4a24a3e8074bc27fb21529b9c4d3a6 (patch)
treea73c21550394e1ded2bb97114e7a2551d5733889 /writerfilter
parent6a114b8ffaac52322c318d2dba543a2ad52cc892 (diff)
RTF import: set user-defined metadata only after parsing all of them
This helps setting all or no metadata in case an error would happen in the middle of parsing metadata entries. Change-Id: I349f53148627dd07f1304ebe00f0664bd23e26ea
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx54
1 files changed, 43 insertions, 11 deletions
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 6dd561b47d11..6bea01fff696 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -8,6 +8,7 @@
*/
#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/document/DocumentProperties.hpp>
#include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp>
#include <com/sun/star/graphic/GraphicProvider.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
@@ -2056,6 +2057,9 @@ RTFError RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
case RTF_USERPROPS:
// Container of all user-defined properties.
m_aStates.top().eDestination = Destination::USERPROPS;
+ if (m_xDocumentProperties.is())
+ // Create a custom document properties to be able to process them later all at once.
+ m_xDocumentProperties = document::DocumentProperties::create(m_xContext);
break;
case RTF_PROPNAME:
m_aStates.top().eDestination = Destination::PROPNAME;
@@ -5924,20 +5928,48 @@ RTFError RTFDocumentImpl::popState()
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)
+ xPropertyContainer->addProperty(rKey, beans::PropertyAttribute::REMOVABLE, aAny);
+ }
+ break;
+ case Destination::USERPROPS:
+ {
+ // These are the imported properties.
+ uno::Reference<document::XDocumentProperties> xDocumentProperties = m_xDocumentProperties;
+
+ // These are the real document properties.
+ uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(m_xDstDoc, uno::UNO_QUERY);
+ if (xDocumentPropertiesSupplier.is())
+ m_xDocumentProperties.set(xDocumentPropertiesSupplier->getDocumentProperties(), uno::UNO_QUERY);
+
+ if (m_xDocumentProperties.is())
+ {
+ uno::Reference<beans::XPropertyContainer> xClipboardPropertyContainer = xDocumentProperties->getUserDefinedProperties();
+ uno::Reference<beans::XPropertyContainer> xDocumentPropertyContainer = m_xDocumentProperties->getUserDefinedProperties();
+ uno::Reference<beans::XPropertySet> xClipboardPropertySet(xClipboardPropertyContainer, uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xDocumentPropertySet(xDocumentPropertyContainer, uno::UNO_QUERY);
+ uno::Sequence<beans::Property> aClipboardProperties = xClipboardPropertySet->getPropertySetInfo()->getProperties();
+ uno::Sequence<beans::Property> aDocumentProperties = xDocumentPropertySet->getPropertySetInfo()->getProperties();
+
+ for (const beans::Property& rProperty : aClipboardProperties)
{
- SAL_WARN("writerfilter", "failed to set property " << rKey << ": " << rException.Message);
+ const OUString& rKey = rProperty.Name;
+ uno::Any aValue = xClipboardPropertySet->getPropertyValue(rKey);
+
+ try
+ {
+ if (lcl_containsProperty(aDocumentProperties, rKey))
+ xDocumentPropertySet->setPropertyValue(rKey, aValue);
+ else
+ xDocumentPropertyContainer->addProperty(rKey, beans::PropertyAttribute::REMOVABLE, aValue);
+ }
+ catch (const uno::Exception& rException)
+ {
+ SAL_WARN("writerfilter", "failed to set property " << rKey << ": " << rException.Message);
+ }
}
}
- break;
+ }
+ break;
default:
break;
}