[Libreoffice-commits] core.git: 4 commits - include/sfx2 sfx2/source sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Tue Feb 23 13:02:36 UTC 2016
include/sfx2/classificationhelper.hxx | 2
sfx2/source/view/classificationhelper.cxx | 298 +++++++++++++++++++++++++++++-
sw/source/core/edit/edfcol.cxx | 11 -
3 files changed, 308 insertions(+), 3 deletions(-)
New commits:
commit 0926adba5557eab2114a57c30d92c977d334f57a
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Feb 23 12:26:11 2016 +0100
sfx2 classification result: copy category labels to document labels
Still need to push them back to the user-defined document property map,
though.
Change-Id: Ic6f48ce30af42e975cd69b2a9cc7fad01702c1dc
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index 55b1efa..58e17c6 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -431,10 +431,19 @@ OUString SfxClassificationHelper::GetDocumentWatermark()
return OUString();
}
-void SfxClassificationHelper::SetBACName(const OUString& /*rName*/)
+void SfxClassificationHelper::SetBACName(const OUString& rName)
{
if (m_pImpl->m_aCategories.empty())
m_pImpl->parsePolicy();
+
+ std::map<OUString, SfxClassificationCategory>::iterator it = m_pImpl->m_aCategories.find(rName);
+ if (it == m_pImpl->m_aCategories.end())
+ {
+ SAL_WARN("sfx.view", "'" << rName << "' is not a recognized category name");
+ return;
+ }
+
+ m_pImpl->m_aLabels = it->second.m_aLabels;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 24d6ac273bc272dd19f795919df643388e974be2
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Feb 23 10:50:41 2016 +0100
sfx2 classification: initial policy parser
Change-Id: Ia7406bdc94cbceb5b66ab9d12355c1e9f4061206
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index 979f60c..55b1efa 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -13,12 +13,24 @@
#include <com/sun/star/beans/XPropertyContainer.hpp>
#include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/xml/sax/Parser.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/SAXParseException.hpp>
#include <sfx2/objsh.hxx>
#include <o3tl/make_unique.hxx>
+#include <comphelper/processfactory.hxx>
+#include <rtl/bootstrap.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <unotools/streamwrap.hxx>
+#include <cppuhelper/implbase.hxx>
+#include <config_folders.h>
using namespace com::sun::star;
+namespace
+{
+
/// Represents one category of a classification policy.
class SfxClassificationCategory
{
@@ -26,14 +38,274 @@ public:
std::map<OUString, OUString> m_aLabels;
};
+/// Parses a policy XML conforming to the TSCP BAF schema.
+class SfxClassificationParser : public cppu::WeakImplHelper<xml::sax::XDocumentHandler>
+{
+public:
+ std::map<OUString, SfxClassificationCategory> m_aCategories;
+
+ OUString m_aPolicyAuthorityName;
+ bool m_bInPolicyAuthorityName;
+ OUString m_aPolicyName;
+ bool m_bInPolicyName;
+ OUString m_aProgramID;
+ bool m_bInProgramID;
+ OUString m_aScale;
+ bool m_bInScale;
+ OUString m_aConfidentalityValue;
+ bool m_bInConfidentalityValue;
+ OUString m_aIdentifier;
+ bool m_bInIdentifier;
+ OUString m_aValue;
+ bool m_bInValue;
+
+ /// Pointer to a value in m_aCategories, the currently parsed category.
+ SfxClassificationCategory* m_pCategory;
+
+ SfxClassificationParser();
+ virtual ~SfxClassificationParser();
+
+ virtual void SAL_CALL startDocument() throw (xml::sax::SAXException, uno::RuntimeException, std::exception) override;
+
+ virtual void SAL_CALL endDocument() throw (xml::sax::SAXException, uno::RuntimeException, std::exception) override;
+
+ virtual void SAL_CALL startElement(const OUString& aName, const uno::Reference<xml::sax::XAttributeList>& xAttribs)
+ throw (xml::sax::SAXException, uno::RuntimeException, std::exception) override;
+
+ virtual void SAL_CALL endElement(const OUString& aName) throw (xml::sax::SAXException, uno::RuntimeException, std::exception) override;
+
+ virtual void SAL_CALL characters(const OUString& aChars) throw (xml::sax::SAXException, uno::RuntimeException, std::exception) override;
+
+ virtual void SAL_CALL ignorableWhitespace(const OUString& aWhitespaces) throw (xml::sax::SAXException, uno::RuntimeException, std::exception) override;
+
+ virtual void SAL_CALL processingInstruction(const OUString& aTarget, const OUString& aData) throw (xml::sax::SAXException, uno::RuntimeException, std::exception) override;
+
+ virtual void SAL_CALL setDocumentLocator(const uno::Reference<xml::sax::XLocator>& xLocator)
+ throw (xml::sax::SAXException, uno::RuntimeException, std::exception) override;
+};
+
+SfxClassificationParser::SfxClassificationParser()
+ : m_bInPolicyAuthorityName(false)
+ , m_bInPolicyName(false)
+ , m_bInProgramID(false)
+ , m_bInConfidentalityValue(false)
+ , m_bInIdentifier(false)
+ , m_bInValue(false)
+ , m_pCategory(nullptr)
+{
+}
+
+SfxClassificationParser::~SfxClassificationParser()
+{
+}
+
+void SAL_CALL SfxClassificationParser::startDocument() throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+}
+
+void SAL_CALL SfxClassificationParser::endDocument() throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+}
+
+void SAL_CALL SfxClassificationParser::startElement(const OUString& rName, const uno::Reference<xml::sax::XAttributeList>& xAttribs)
+throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+ if (rName == "baf:PolicyAuthorityName")
+ {
+ m_aPolicyAuthorityName.clear();
+ m_bInPolicyAuthorityName = true;
+ }
+ else if (rName == "baf:PolicyName")
+ {
+ m_aPolicyName.clear();
+ m_bInPolicyName = true;
+ }
+ else if (rName == "baf:ProgramID")
+ {
+ m_aProgramID.clear();
+ m_bInProgramID = true;
+ }
+ else if (rName == "baf:BusinessAuthorizationCategory")
+ {
+ OUString aIdentifier = xAttribs->getValueByName("Identifier");
+ OUString aName = xAttribs->getValueByName("Name");
+ if (!m_pCategory && !aName.isEmpty())
+ {
+ // Create a new category and initialize it with the data that's true for all categories.
+ SfxClassificationCategory& rCategory = m_aCategories[aName];
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:PolicyAuthority:Name"] = m_aPolicyAuthorityName;
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Policy:Name"] = m_aPolicyName;
+
+ // Also initialize defaults.
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:PolicyAuthority:Identifier"] = "None";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:PolicyAuthority:Country"] = "None";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Policy:Identifier"] = "None";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorization:Name"] = "None";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorization:Identifier"] = "None";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorization:Locator"] = "None";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Name"] = "None";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Identifier"] = "None";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Identifier:OID"] = "None";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Locator"] = "None";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorization:Locator"] = "None";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:MarkingPrecedence"] = "None";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-summary"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-warning-statement"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-warning-statement:ext:2"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-warning-statement:ext:3"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-warning-statement:ext:4"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-distribution-statement"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-distribution-statement:ext:2"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-distribution-statement:ext:3"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:general-distribution-statement:ext:4"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:document-footer"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:document-header"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:document-watermark"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:email-first-line-of-text"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:email-last-line-of-text"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:email-subject-prefix"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Marking:email-subject-suffix"] = "";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Authorization:StartValidity"] = "None";
+ rCategory.m_aLabels["urn:bails:IntellectualProperty:Authorization:StopValidity"] = "None";
+ m_pCategory = &rCategory;
+ }
+ }
+ else if (rName == "baf:Scale")
+ {
+ m_aScale.clear();
+ m_bInScale = true;
+ }
+ else if (rName == "baf:ConfidentalityValue")
+ {
+ m_aConfidentalityValue.clear();
+ m_bInConfidentalityValue = true;
+ }
+ else if (rName == "baf:Identifier")
+ {
+ m_aIdentifier.clear();
+ m_bInIdentifier = true;
+ }
+ else if (rName == "baf:Value")
+ {
+ m_aValue.clear();
+ m_bInValue = true;
+ }
+}
+
+void SAL_CALL SfxClassificationParser::endElement(const OUString& rName) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+ if (rName == "baf:PolicyAuthorityName")
+ m_bInPolicyAuthorityName = false;
+ else if (rName == "baf:PolicyName")
+ m_bInPolicyName = false;
+ else if (rName == "baf:ProgramID")
+ m_bInProgramID = false;
+ else if (rName == "baf:BusinessAuthorizationCategory")
+ m_pCategory = nullptr;
+ else if (rName == "baf:Scale")
+ {
+ m_bInScale = false;
+ if (m_pCategory)
+ m_pCategory->m_aLabels["urn:bails:IntellectualProperty:Impact:Scale"] = m_aScale;
+ }
+ else if (rName == "baf:ConfidentalityValue")
+ {
+ m_bInConfidentalityValue = false;
+ if (m_pCategory)
+ {
+ std::map<OUString, OUString>& rLabels = m_pCategory->m_aLabels;
+ rLabels["urn:bails:IntellectualProperty:Impact:Level:Confidentiality"] = m_aConfidentalityValue;
+ // Set the two other type of levels as well, if they're not set
+ // yet: they're optional in BAF, but not in BAILS.
+ if (rLabels.find("urn:bails:IntellectualProperty:Impact:Level:Integrity") == rLabels.end())
+ rLabels["urn:bails:IntellectualProperty:Impact:Level:Integrity"] = m_aConfidentalityValue;
+ if (rLabels.find("urn:bails:IntellectualProperty:Impact:Level:Availability") == rLabels.end())
+ rLabels["urn:bails:IntellectualProperty:Impact:Level:Availability"] = m_aConfidentalityValue;
+ }
+ }
+ else if (rName == "baf:Identifier")
+ m_bInIdentifier = false;
+ else if (rName == "baf:Value")
+ {
+ if (m_pCategory)
+ {
+ if (m_aIdentifier == "Document: Header")
+ m_pCategory->m_aLabels["urn:bails:IntellectualProperty:Marking:document-header"] = m_aValue;
+ else if (m_aIdentifier == "Document: Footer")
+ m_pCategory->m_aLabels["urn:bails:IntellectualProperty:Marking:document-footer"] = m_aValue;
+ else if (m_aIdentifier == "Document: Watermark")
+ m_pCategory->m_aLabels["urn:bails:IntellectualProperty:Marking:document-watermark"] = m_aValue;
+ }
+ }
+}
+
+void SAL_CALL SfxClassificationParser::characters(const OUString& rChars) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+ if (m_bInPolicyAuthorityName)
+ m_aPolicyAuthorityName += rChars;
+ else if (m_bInPolicyName)
+ m_aPolicyName += rChars;
+ else if (m_bInProgramID)
+ m_aProgramID += rChars;
+ else if (m_bInScale)
+ m_aScale += rChars;
+ else if (m_bInConfidentalityValue)
+ m_aConfidentalityValue += rChars;
+ else if (m_bInIdentifier)
+ m_aIdentifier += rChars;
+ else if (m_bInValue)
+ m_aValue += rChars;
+}
+
+void SAL_CALL SfxClassificationParser::ignorableWhitespace(const OUString& /*rWhitespace*/) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+}
+
+void SAL_CALL SfxClassificationParser::processingInstruction(const OUString& /*rTarget*/, const OUString& /*rData*/) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+}
+
+void SAL_CALL SfxClassificationParser::setDocumentLocator(const uno::Reference<xml::sax::XLocator>& /*xLocator*/) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+}
+
+} // anonymous namespace
+
/// Implementation details of SfxClassificationHelper.
-struct SfxClassificationHelper::Impl
+class SfxClassificationHelper::Impl
{
+public:
std::map<OUString, OUString> m_aLabels;
/// Possible categories of a policy to choose from.
std::map<OUString, SfxClassificationCategory> m_aCategories;
+
+ void parsePolicy();
};
+void SfxClassificationHelper::Impl::parsePolicy()
+{
+ OUString aPath("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/classification/example.xml");
+ rtl::Bootstrap::expandMacros(aPath);
+ SvStream* pStream = utl::UcbStreamHelper::CreateStream(aPath, StreamMode::READ);
+ uno::Reference<io::XInputStream> xInputStream(new utl::OStreamWrapper(*pStream));
+ xml::sax::InputSource aParserInput;
+ aParserInput.aInputStream = xInputStream;
+
+ uno::Reference<xml::sax::XParser> xParser = xml::sax::Parser::create(comphelper::getProcessComponentContext());
+ rtl::Reference<SfxClassificationParser> xClassificationParser(new SfxClassificationParser());
+ uno::Reference<xml::sax::XDocumentHandler> xHandler(xClassificationParser.get());
+ xParser->setDocumentHandler(xHandler);
+ try
+ {
+ xParser->parseStream(aParserInput);
+ }
+ catch (const xml::sax::SAXParseException& rException)
+ {
+ SAL_WARN("sfx.view", "parsePolicy() failed: " << rException.Message);
+ }
+ m_aCategories = xClassificationParser->m_aCategories;
+}
+
bool SfxClassificationHelper::IsClassified(SfxObjectShell& rObjectShell)
{
uno::Reference<document::XDocumentProperties> xDocumentProperties = rObjectShell.getDocProperties();
@@ -161,6 +433,8 @@ OUString SfxClassificationHelper::GetDocumentWatermark()
void SfxClassificationHelper::SetBACName(const OUString& /*rName*/)
{
+ if (m_pImpl->m_aCategories.empty())
+ m_pImpl->parsePolicy();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 1f1199574e839ab5da4fc0a494a2fe21cef3c24e
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Feb 23 10:31:31 2016 +0100
sfx2: initial SfxClassificationCategory
Change-Id: I56f834093a1ee00b793580525ba052026e25289f
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index 86ab579..979f60c 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -19,10 +19,19 @@
using namespace com::sun::star;
+/// Represents one category of a classification policy.
+class SfxClassificationCategory
+{
+public:
+ std::map<OUString, OUString> m_aLabels;
+};
+
/// Implementation details of SfxClassificationHelper.
struct SfxClassificationHelper::Impl
{
std::map<OUString, OUString> m_aLabels;
+ /// Possible categories of a policy to choose from.
+ std::map<OUString, SfxClassificationCategory> m_aCategories;
};
bool SfxClassificationHelper::IsClassified(SfxObjectShell& rObjectShell)
commit b84dca7cd508e806842341329456dc33d6179e28
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Feb 23 10:21:28 2016 +0100
sfx2 classification: add interface to set category name
Change-Id: I289b46f5f57ef000de5f482b5c8ed7bcaa89ddab
diff --git a/include/sfx2/classificationhelper.hxx b/include/sfx2/classificationhelper.hxx
index 613d35e..e1c4252 100644
--- a/include/sfx2/classificationhelper.hxx
+++ b/include/sfx2/classificationhelper.hxx
@@ -34,6 +34,8 @@ public:
SfxClassificationHelper(SfxObjectShell& rObjectShell);
~SfxClassificationHelper();
OUString GetBACName();
+ /// Setting this sets all the other properties, based on the policy.
+ void SetBACName(const OUString& rName);
/// If GetImpactLevelColor() will return something meaningful.
bool HasImpactLevel();
basegfx::BColor GetImpactLevelColor();
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index d062eac..86ab579 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -150,4 +150,8 @@ OUString SfxClassificationHelper::GetDocumentWatermark()
return OUString();
}
+void SfxClassificationHelper::SetBACName(const OUString& /*rName*/)
+{
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index 8b462f7..c5ced4b 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -19,6 +19,7 @@
#include <hintids.hxx>
#include <editeng/formatbreakitem.hxx>
+#include <sfx2/classificationhelper.hxx>
#include <editsh.hxx>
#include <doc.hxx>
#include <IDocumentUndoRedo.hxx>
@@ -31,6 +32,7 @@
#include <numrule.hxx>
#include <swundo.hxx>
#include <docary.hxx>
+#include <docsh.hxx>
SwTextFormatColl& SwEditShell::GetDfltTextFormatColl() const
{
@@ -47,9 +49,14 @@ SwTextFormatColl& SwEditShell::GetTextFormatColl( sal_uInt16 nFormatColl) const
return *((*(GetDoc()->GetTextFormatColls()))[nFormatColl]);
}
-void SwEditShell::SetClassification(const OUString& /*rName*/)
+void SwEditShell::SetClassification(const OUString& rName)
{
- (void)this;//TODO
+ SwDocShell* pDocShell = GetDoc()->GetDocShell();
+ if (!pDocShell)
+ return;
+
+ SfxClassificationHelper aHelper(*pDocShell);
+ aHelper.SetBACName(rName);
}
// #i62675#
More information about the Libreoffice-commits
mailing list