Bump version to 21.06.18.1
[LibreOffice.git] / include / sfx2 / classificationhelper.hxx
blobf5c47064c9af4d582eae84da4e639f38b8073674
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_SFX2_CLASSIFICATIONHELPER_HXX
11 #define INCLUDED_SFX2_CLASSIFICATIONHELPER_HXX
13 #include <memory>
14 #include <vector>
16 #include <rtl/ustring.hxx>
17 #include <sfx2/dllapi.h>
18 #include <sfx2/infobar.hxx>
20 namespace com::sun::star::beans
22 class XPropertyContainer;
24 namespace com::sun::star::document
26 class XDocumentProperties;
29 class SfxViewFrame;
31 /// Return code of SfxClassificationHelper::CheckPaste().
32 enum class SfxClassificationCheckPasteResult
34 None = 1,
35 TargetDocNotClassified = 2,
36 DocClassificationTooLow = 3
39 /// Specifies a policy type, to be used with SetBACName(). Getters always use IntellectualProperty for now.
40 enum class SfxClassificationPolicyType
42 ExportControl = 1,
43 NationalSecurity = 2,
44 IntellectualProperty = 3
47 /// Shared code to handle Business Authorization Identification and Labeling Scheme (BAILS) properties.
48 class SFX2_DLLPUBLIC SfxClassificationHelper
50 class SAL_DLLPRIVATE Impl;
51 std::unique_ptr<Impl> m_pImpl;
53 public:
54 /// Does the document have any BAILS properties?
55 static bool IsClassified(
56 const css::uno::Reference<css::document::XDocumentProperties>& xDocumentProperties);
57 /// Checks if pasting from xSource to xDestination would leak information.
58 static SfxClassificationCheckPasteResult
59 CheckPaste(const css::uno::Reference<css::document::XDocumentProperties>& xSource,
60 const css::uno::Reference<css::document::XDocumentProperties>& xDestination);
61 /// Wrapper around CheckPaste(): informs the user if necessary and finds out if the paste can be continued or not.
62 static bool ShowPasteInfo(SfxClassificationCheckPasteResult eResult);
64 SfxClassificationHelper(
65 const css::uno::Reference<css::document::XDocumentProperties>& xDocumentProperties,
66 bool bUseLocalizedPolicy = true);
67 ~SfxClassificationHelper();
68 /// Get the currently selected category for eType.
69 const OUString& GetBACName(SfxClassificationPolicyType eType) const;
70 /// Return all possible valid category names, based on the policy.
71 std::vector<OUString> GetBACNames();
72 /// Return all possible valid category identifiers, based on the policy.
73 std::vector<OUString> GetBACIdentifiers();
74 /// Get the currently selected category abbreviation for eType. Returns full name if no abbreviation defined.
75 const OUString& GetAbbreviatedBACName(const OUString& sFullName);
76 /// Get the currently selected category for the identifier.
77 OUString GetBACNameForIdentifier(const OUString& sIdentifier);
78 /// Return all possible valid abbreviated category names, based on the policy.
79 std::vector<OUString> GetAbbreviatedBACNames();
80 /// Setting this sets all the other properties, based on the policy.
81 void SetBACName(const OUString& rName, SfxClassificationPolicyType eType);
82 /// Returns the class with the higher priority (based on sensitivity).
83 OUString GetHigherClass(const OUString& first, const OUString& second);
84 /// If GetImpactScale() and GetImpactLevel*() will return something meaningful.
85 bool HasImpactLevel();
86 InfobarType GetImpactLevelType();
87 /// Larger value means more confidential.
88 sal_Int32 GetImpactLevel();
89 /// Comparing the GetImpactLevel() result is only meaningful when the impact scale is the same.
90 OUString GetImpactScale();
91 OUString GetDocumentWatermark();
92 /// The selected category has some content for the document header.
93 bool HasDocumentHeader();
94 /// The selected category has some content for the document footer.
95 bool HasDocumentFooter();
96 void UpdateInfobar(SfxViewFrame& rViewFrame);
98 std::vector<OUString> const& GetMarkings() const;
99 std::vector<OUString> const& GetIntellectualPropertyParts() const;
100 std::vector<OUString> const& GetIntellectualPropertyPartNumbers() const;
102 /// Does a best-effort conversion of rType to SfxClassificationPolicyType.
103 static SfxClassificationPolicyType stringToPolicyType(const OUString& rType);
104 /// Returns the string representation of a SfxClassificationPolicyType element.
105 static const OUString& policyTypeToString(SfxClassificationPolicyType eType);
107 /// Brief text located at the top of each document's pages.
108 static const OUString& PROP_DOCHEADER();
109 /// Brief text located at the bottom of each document's pages.
110 static const OUString& PROP_DOCFOOTER();
111 /// Brief text formatted as a watermark on each document's page.
112 static const OUString& PROP_DOCWATERMARK();
113 /// Get the property prefix for the IntellectualProperty policy type.
114 static const OUString& PROP_PREFIX_INTELLECTUALPROPERTY();
116 static SfxClassificationPolicyType getPolicyType();
119 namespace sfx
121 /// Specifies the origin: either defined by the BAF policy or manual via. the advanced classification dialog
122 enum class ClassificationCreationOrigin
124 NONE,
125 BAF_POLICY,
126 MANUAL
129 class ClassificationKeyCreator
131 private:
132 const SfxClassificationPolicyType m_ePolicyType;
133 const OUString m_sPolicy;
134 sal_Int32 m_nTextNumber;
135 sal_Int32 m_nIPPartNumber;
136 sal_Int32 m_nMarkingNumber;
138 OUString const& getPolicyKey() const { return m_sPolicy; }
140 public:
141 ClassificationKeyCreator(SfxClassificationPolicyType ePolicyType)
142 : m_ePolicyType(ePolicyType)
143 , m_sPolicy(SfxClassificationHelper::policyTypeToString(m_ePolicyType))
144 , m_nTextNumber(1)
145 , m_nIPPartNumber(1)
146 , m_nMarkingNumber(1)
150 OUString makeTextKey() const { return getPolicyKey() + "Custom:Text"; }
152 OUString makeNumberedTextKey()
154 return makeTextKey() + ":n" + OUString::number(m_nTextNumber++);
157 bool isMarkingTextKey(OUString const& aKey) const { return aKey.startsWith(makeTextKey()); }
159 OUString makeCategoryNameKey() const
161 return getPolicyKey() + "BusinessAuthorizationCategory:Name";
164 bool isCategoryNameKey(OUString const& aKey) const
166 return aKey.startsWith(makeCategoryNameKey());
169 OUString makeCategoryIdentifierKey() const
171 return getPolicyKey() + "BusinessAuthorizationCategory:Identifier";
174 bool isCategoryIdentifierKey(OUString const& aKey) const
176 return aKey.startsWith(makeCategoryIdentifierKey());
179 OUString makeMarkingKey() const { return getPolicyKey() + "Custom:Marking"; }
181 OUString makeNumberedMarkingKey()
183 return makeMarkingKey() + ":n" + OUString::number(m_nMarkingNumber++);
186 bool isMarkingKey(OUString const& aKey) const { return aKey.startsWith(makeMarkingKey()); }
188 OUString makeIntellectualPropertyPartKey() const
190 return getPolicyKey() + "Custom:IntellectualPropertyPart";
193 OUString makeNumberedIntellectualPropertyPartKey()
195 return makeIntellectualPropertyPartKey() + ":n" + OUString::number(m_nIPPartNumber++);
198 bool isIntellectualPropertyPartKey(OUString const& aKey) const
200 return aKey.startsWith(makeIntellectualPropertyPartKey());
203 OUString makeFullTextualRepresentationKey() const
205 return getPolicyKey() + "Custom:FullTexturalRepresentation";
208 /// Classification creation origin key
209 OUString makeCreationOriginKey() const { return getPolicyKey() + "CreationOrigin"; }
212 SFX2_DLLPUBLIC sfx::ClassificationCreationOrigin getCreationOriginProperty(
213 css::uno::Reference<css::beans::XPropertyContainer> const& rxPropertyContainer,
214 sfx::ClassificationKeyCreator const& rKeyCreator);
217 #endif
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */