summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-02-17 09:13:42 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-02-17 10:04:54 +0100
commit89b928d43a5db1ad3bf761cdb24013c6bcf32e8b (patch)
treeb594a8c2ab86691f6388ef7c6e2e679705904ca1 /sfx2
parentd977a49ef0fb5377379dbb7516cad3ee8ecead41 (diff)
sfx2: introduce initial SfxClassificationHelper
A document's metadata has predefinied keys like title, and has user-defined ones as well. The BAILS specification at <http://www.tscp.org/wp-content/uploads/2013/08/TSCP_BAILSv1.pdf> describes a mechanism to use the generic user-defined key-value pairs to embed classification-related (read: is it public? is it internal only? etc) information in a standard way. One approach in handling these in LO would be to let code here and there parse these user-defined key-value pairs again and again. An other one would be to handle these as first-class properties, even if the majority of the users would never need them. A middle between the above two approaches is this class: all these properties are still just user-defined properties, but if the document has them, then all related code is supposed to be implemented in this central class. Change-Id: Ib0297a5e91779b330c310a153f1a1628759dd028
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/Library_sfx.mk1
-rw-r--r--sfx2/source/view/classificationhelper.cxx87
2 files changed, 88 insertions, 0 deletions
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index 2440cdc06f68..418a836b5465 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -290,6 +290,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
sfx2/source/styles/StyleManager \
sfx2/source/toolbox/imgmgr \
sfx2/source/toolbox/tbxitem \
+ sfx2/source/view/classificationhelper \
sfx2/source/view/frame \
sfx2/source/view/frame2 \
sfx2/source/view/frmload \
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
new file mode 100644
index 000000000000..c4e2245a0bcd
--- /dev/null
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -0,0 +1,87 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sfx2/classificationhelper.hxx>
+
+#include <map>
+
+#include <com/sun/star/beans/XPropertyContainer.hpp>
+#include <com/sun/star/document/XDocumentProperties.hpp>
+
+#include <sfx2/objsh.hxx>
+#include <o3tl/make_unique.hxx>
+
+using namespace com::sun::star;
+
+/// Implementation details of SfxClassificationHelper.
+struct SfxClassificationHelper::Impl
+{
+ std::map<OUString, OUString> m_aLabels;
+};
+
+bool SfxClassificationHelper::IsClassified(SfxObjectShell& rObjectShell)
+{
+ uno::Reference<document::XDocumentProperties> xDocumentProperties = rObjectShell.getDocProperties();
+ uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
+ if (!xPropertyContainer.is())
+ return false;
+
+ uno::Reference<beans::XPropertySet> xPropertySet(xPropertyContainer, uno::UNO_QUERY);
+ uno::Sequence<beans::Property> aProperties = xPropertySet->getPropertySetInfo()->getProperties();
+ for (const beans::Property& rProperty : aProperties)
+ {
+ if (rProperty.Name.startsWith("urn:bails:"))
+ return true;
+ }
+
+ return false;
+}
+
+SfxClassificationHelper::SfxClassificationHelper(SfxObjectShell& rObjectShell)
+ : m_pImpl(o3tl::make_unique<Impl>())
+{
+ uno::Reference<document::XDocumentProperties> xDocumentProperties = rObjectShell.getDocProperties();
+ uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
+ if (!xPropertyContainer.is())
+ return;
+
+ uno::Reference<beans::XPropertySet> xPropertySet(xPropertyContainer, uno::UNO_QUERY);
+ uno::Sequence<beans::Property> aProperties = xPropertySet->getPropertySetInfo()->getProperties();
+ for (const beans::Property& rProperty : aProperties)
+ {
+ uno::Any aAny = xPropertySet->getPropertyValue(rProperty.Name);
+ OUString aValue;
+ if (aAny >>= aValue)
+ m_pImpl->m_aLabels[rProperty.Name] = aValue;
+ }
+}
+
+SfxClassificationHelper::~SfxClassificationHelper()
+{
+}
+
+OUString SfxClassificationHelper::GetBACName()
+{
+ std::map<OUString, OUString>::iterator it = m_pImpl->m_aLabels.find("urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Name");
+ if (it != m_pImpl->m_aLabels.end())
+ return it->second;
+
+ return OUString();
+}
+
+OUString SfxClassificationHelper::GetImpactLevel()
+{
+ std::map<OUString, OUString>::iterator it = m_pImpl->m_aLabels.find("urn:bails:IntellectualProperty:Impact:Level:Confidentiality");
+ if (it != m_pImpl->m_aLabels.end())
+ return it->second;
+
+ return OUString();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */