diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-03-10 11:23:51 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-03-10 14:31:54 +0100 |
commit | b1f9369b8181b4f135bfc8a0f1fdf1be7609fd0f (patch) | |
tree | c4c830e4f91eada20f2f51687cf68be3291bbfa9 /writerfilter | |
parent | e75f6e549eb825c310d16d11babf0fba5ee7fd7a (diff) |
RTF import: handle classification during copy&paste
With this, it can't happen that "paste" returns an error, but "paste as
rtf" succeeds (from a classification point of view).
Change-Id: Ia6807e5a6c065557cdd735a574ea858d29a97160
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 54 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtflistener.hxx | 3 |
2 files changed, 55 insertions, 2 deletions
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 6bea01fff696..1c83e66a2b5c 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -22,6 +22,7 @@ #include <unotools/streamwrap.hxx> #include <com/sun/star/drawing/XDrawPageSupplier.hpp> #include <vcl/wmf.hxx> +#include <vcl/layout.hxx> #include <filter/msfilter/util.hxx> #include <comphelper/string.hxx> #include <tools/globname.hxx> @@ -31,6 +32,9 @@ #include <comphelper/sequenceashashmap.hxx> #include <comphelper/sequence.hxx> #include <sfx2/sfxbasemodel.hxx> +#include <sfx2/classificationhelper.hxx> +#include <sfx2/sfx.hrc> +#include <sfx2/sfxresid.hxx> #include <oox/mathml/import.hxx> #include <ooxml/resourceids.hxx> #include <oox/token/namespaces.hxx> @@ -741,6 +745,9 @@ void RTFDocumentImpl::resolve(Stream& rMapper) case RTFError::CHAR_OVER: SAL_INFO("writerfilter", "RTFDocumentImpl::resolve: characters after last '}'"); break; + case RTFError::CLASSIFICATION: + SAL_INFO("writerfilter", "RTFDocumentImpl::resolve: classification prevented paste"); + break; } } @@ -5124,6 +5131,39 @@ bool lcl_containsProperty(const uno::Sequence<beans::Property>& rProperties, con }) != rProperties.end(); } +namespace +{ + +RTFError lcl_checkClassification(const uno::Reference<document::XDocumentProperties>& xSource, const uno::Reference<document::XDocumentProperties>& xDestination) +{ + switch (SfxClassificationHelper::CheckPaste(xSource, xDestination)) + { + case SfxClassificationCheckPasteResult::None: + { + return RTFError::OK; + } + break; + case SfxClassificationCheckPasteResult::TargetDocNotClassified: + { + if (!Application::IsHeadlessModeEnabled()) + ScopedVclPtrInstance<MessageDialog>::Create(nullptr, SfxResId(STR_TARGET_DOC_NOT_CLASSIFIED), VCL_MESSAGE_INFO)->Execute(); + return RTFError::CLASSIFICATION; + } + break; + case SfxClassificationCheckPasteResult::DocClassificationTooLow: + { + if (!Application::IsHeadlessModeEnabled()) + ScopedVclPtrInstance<MessageDialog>::Create(nullptr, SfxResId(STR_DOC_CLASSIFICATION_TOO_LOW), VCL_MESSAGE_INFO)->Execute(); + return RTFError::CLASSIFICATION; + } + break; + } + + return RTFError::OK; +} + +} + RTFError RTFDocumentImpl::popState() { //SAL_INFO("writerfilter", OSL_THIS_FUNC << " before pop: m_pTokenizer->getGroup() " << m_pTokenizer->getGroup() << @@ -5943,6 +5983,14 @@ RTFError RTFDocumentImpl::popState() if (m_xDocumentProperties.is()) { + if (!m_bIsNewDoc) + { + // Check classification. + RTFError nError = lcl_checkClassification(xDocumentProperties, m_xDocumentProperties); + if (nError != RTFError::OK) + return nError; + } + uno::Reference<beans::XPropertyContainer> xClipboardPropertyContainer = xDocumentProperties->getUserDefinedProperties(); uno::Reference<beans::XPropertyContainer> xDocumentPropertyContainer = m_xDocumentProperties->getUserDefinedProperties(); uno::Reference<beans::XPropertySet> xClipboardPropertySet(xClipboardPropertyContainer, uno::UNO_QUERY); @@ -5958,7 +6006,11 @@ RTFError RTFDocumentImpl::popState() try { if (lcl_containsProperty(aDocumentProperties, rKey)) - xDocumentPropertySet->setPropertyValue(rKey, aValue); + { + // When pasting, don't update existing properties. + if (!m_bIsNewDoc) + xDocumentPropertySet->setPropertyValue(rKey, aValue); + } else xDocumentPropertyContainer->addProperty(rKey, beans::PropertyAttribute::REMOVABLE, aValue); } diff --git a/writerfilter/source/rtftok/rtflistener.hxx b/writerfilter/source/rtftok/rtflistener.hxx index dbce2181dd98..ea3d9e222983 100644 --- a/writerfilter/source/rtftok/rtflistener.hxx +++ b/writerfilter/source/rtftok/rtflistener.hxx @@ -30,7 +30,8 @@ enum class RTFError GROUP_OVER, UNEXPECTED_EOF, HEX_INVALID, - CHAR_OVER + CHAR_OVER, + CLASSIFICATION }; /** |