/src/libreoffice/include/sfx2/classificationhelper.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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 | | */ |
9 | | |
10 | | #ifndef INCLUDED_SFX2_CLASSIFICATIONHELPER_HXX |
11 | | #define INCLUDED_SFX2_CLASSIFICATIONHELPER_HXX |
12 | | |
13 | | #include <memory> |
14 | | #include <string_view> |
15 | | #include <vector> |
16 | | |
17 | | #include <o3tl/string_view.hxx> |
18 | | #include <rtl/ustring.hxx> |
19 | | #include <sfx2/dllapi.h> |
20 | | |
21 | | enum class InfobarType; |
22 | | |
23 | | namespace com::sun::star::beans |
24 | | { |
25 | | class XPropertyContainer; |
26 | | } |
27 | | namespace com::sun::star::document |
28 | | { |
29 | | class XDocumentProperties; |
30 | | } |
31 | | namespace com::sun::star::uno |
32 | | { |
33 | | template <class interface_type> class Reference; |
34 | | } |
35 | | |
36 | | class SfxViewFrame; |
37 | | |
38 | | /// Return code of SfxClassificationHelper::CheckPaste(). |
39 | | enum class SfxClassificationCheckPasteResult |
40 | | { |
41 | | None = 1, |
42 | | TargetDocNotClassified = 2, |
43 | | DocClassificationTooLow = 3 |
44 | | }; |
45 | | |
46 | | /// Specifies a policy type, to be used with SetBACName(). Getters always use IntellectualProperty for now. |
47 | | enum class SfxClassificationPolicyType |
48 | | { |
49 | | ExportControl = 1, |
50 | | NationalSecurity = 2, |
51 | | IntellectualProperty = 3 |
52 | | }; |
53 | | |
54 | | /// Shared code to handle Business Authorization Identification and Labeling Scheme (BAILS) properties. |
55 | | class SFX2_DLLPUBLIC SfxClassificationHelper |
56 | | { |
57 | | class SAL_DLLPRIVATE Impl; |
58 | | std::unique_ptr<Impl> m_pImpl; |
59 | | |
60 | | public: |
61 | | /// Does the document have any BAILS properties? |
62 | | static bool IsClassified( |
63 | | const css::uno::Reference<css::document::XDocumentProperties>& xDocumentProperties); |
64 | | /// Checks if pasting from xSource to xDestination would leak information. |
65 | | static SfxClassificationCheckPasteResult |
66 | | CheckPaste(const css::uno::Reference<css::document::XDocumentProperties>& xSource, |
67 | | const css::uno::Reference<css::document::XDocumentProperties>& xDestination); |
68 | | /// Wrapper around CheckPaste(): informs the user if necessary and finds out if the paste can be continued or not. |
69 | | static bool ShowPasteInfo(SfxClassificationCheckPasteResult eResult); |
70 | | |
71 | | SfxClassificationHelper( |
72 | | const css::uno::Reference<css::document::XDocumentProperties>& xDocumentProperties, |
73 | | bool bUseLocalizedPolicy = true); |
74 | | ~SfxClassificationHelper(); |
75 | | /// Get the currently selected category for eType. |
76 | | const OUString& GetBACName(SfxClassificationPolicyType eType) const; |
77 | | /// Return all possible valid category names, based on the policy. |
78 | | std::vector<OUString> GetBACNames(); |
79 | | /// Return all possible valid category identifiers, based on the policy. |
80 | | std::vector<OUString> GetBACIdentifiers(); |
81 | | /// Get the currently selected category abbreviation for eType. Returns full name if no abbreviation defined. |
82 | | const OUString& GetAbbreviatedBACName(const OUString& sFullName); |
83 | | /// Get the currently selected category for the identifier. |
84 | | OUString GetBACNameForIdentifier(std::u16string_view sIdentifier); |
85 | | /// Return all possible valid abbreviated category names, based on the policy. |
86 | | std::vector<OUString> GetAbbreviatedBACNames(); |
87 | | /// Setting this sets all the other properties, based on the policy. |
88 | | void SetBACName(const OUString& rName, SfxClassificationPolicyType eType); |
89 | | /// Returns the class with the higher priority (based on sensitivity). |
90 | | OUString GetHigherClass(const OUString& first, const OUString& second); |
91 | | /// If GetImpactScale() and GetImpactLevel*() will return something meaningful. |
92 | | bool HasImpactLevel(); |
93 | | InfobarType GetImpactLevelType(); |
94 | | /// Larger value means more confidential. |
95 | | sal_Int32 GetImpactLevel(); |
96 | | /// Comparing the GetImpactLevel() result is only meaningful when the impact scale is the same. |
97 | | OUString GetImpactScale(); |
98 | | OUString GetDocumentWatermark(); |
99 | | /// The selected category has some content for the document header. |
100 | | bool HasDocumentHeader(); |
101 | | /// The selected category has some content for the document footer. |
102 | | bool HasDocumentFooter(); |
103 | | void UpdateInfobar(SfxViewFrame& rViewFrame); |
104 | | |
105 | | std::vector<OUString> const& GetMarkings() const; |
106 | | std::vector<OUString> const& GetIntellectualPropertyParts() const; |
107 | | std::vector<OUString> const& GetIntellectualPropertyPartNumbers() const; |
108 | | |
109 | | /// Does a best-effort conversion of rType to SfxClassificationPolicyType. |
110 | | static SfxClassificationPolicyType stringToPolicyType(std::u16string_view rType); |
111 | | /// Returns the string representation of a SfxClassificationPolicyType element. |
112 | | static const OUString& policyTypeToString(SfxClassificationPolicyType eType); |
113 | | |
114 | | /// Brief text located at the top of each document's pages. |
115 | | static const OUString& PROP_DOCHEADER(); |
116 | | /// Brief text located at the bottom of each document's pages. |
117 | | static const OUString& PROP_DOCFOOTER(); |
118 | | /// Brief text formatted as a watermark on each document's page. |
119 | | static const OUString& PROP_DOCWATERMARK(); |
120 | | /// Get the property prefix for the IntellectualProperty policy type. |
121 | | static const OUString& PROP_PREFIX_INTELLECTUALPROPERTY(); |
122 | | |
123 | | static SfxClassificationPolicyType getPolicyType(); |
124 | | }; |
125 | | |
126 | | namespace sfx |
127 | | { |
128 | | /// Specifies the origin: either defined by the BAF policy or manual via. the advanced classification dialog |
129 | | enum class ClassificationCreationOrigin |
130 | | { |
131 | | NONE, |
132 | | BAF_POLICY, |
133 | | MANUAL |
134 | | }; |
135 | | |
136 | | class ClassificationKeyCreator |
137 | | { |
138 | | private: |
139 | | const SfxClassificationPolicyType m_ePolicyType; |
140 | | const OUString m_sPolicy; |
141 | | sal_Int32 m_nTextNumber; |
142 | | sal_Int32 m_nIPPartNumber; |
143 | | sal_Int32 m_nMarkingNumber; |
144 | | |
145 | 0 | OUString const& getPolicyKey() const { return m_sPolicy; } |
146 | | |
147 | | public: |
148 | | ClassificationKeyCreator(SfxClassificationPolicyType ePolicyType) |
149 | 8.61k | : m_ePolicyType(ePolicyType) |
150 | 8.61k | , m_sPolicy(SfxClassificationHelper::policyTypeToString(m_ePolicyType)) |
151 | 8.61k | , m_nTextNumber(1) |
152 | 8.61k | , m_nIPPartNumber(1) |
153 | 8.61k | , m_nMarkingNumber(1) |
154 | 8.61k | { |
155 | 8.61k | } |
156 | | |
157 | 0 | OUString makeTextKey() const { return getPolicyKey() + "Custom:Text"; } |
158 | | |
159 | | OUString makeNumberedTextKey() |
160 | 0 | { |
161 | 0 | return makeTextKey() + ":n" + OUString::number(m_nTextNumber++); |
162 | 0 | } |
163 | | |
164 | | bool isMarkingTextKey(std::u16string_view aKey) const |
165 | 0 | { |
166 | 0 | return o3tl::starts_with(aKey, makeTextKey()); |
167 | 0 | } |
168 | | |
169 | | OUString makeCategoryNameKey() const |
170 | 0 | { |
171 | 0 | return getPolicyKey() + "BusinessAuthorizationCategory:Name"; |
172 | 0 | } |
173 | | |
174 | | bool isCategoryNameKey(std::u16string_view aKey) const |
175 | 0 | { |
176 | 0 | return o3tl::starts_with(aKey, makeCategoryNameKey()); |
177 | 0 | } |
178 | | |
179 | | OUString makeCategoryIdentifierKey() const |
180 | 0 | { |
181 | 0 | return getPolicyKey() + "BusinessAuthorizationCategory:Identifier"; |
182 | 0 | } |
183 | | |
184 | | bool isCategoryIdentifierKey(std::u16string_view aKey) const |
185 | 0 | { |
186 | 0 | return o3tl::starts_with(aKey, makeCategoryIdentifierKey()); |
187 | 0 | } |
188 | | |
189 | 0 | OUString makeMarkingKey() const { return getPolicyKey() + "Custom:Marking"; } |
190 | | |
191 | | OUString makeNumberedMarkingKey() |
192 | 0 | { |
193 | 0 | return makeMarkingKey() + ":n" + OUString::number(m_nMarkingNumber++); |
194 | 0 | } |
195 | | |
196 | | bool isMarkingKey(std::u16string_view aKey) const |
197 | 0 | { |
198 | 0 | return o3tl::starts_with(aKey, makeMarkingKey()); |
199 | 0 | } |
200 | | |
201 | | OUString makeIntellectualPropertyPartKey() const |
202 | 0 | { |
203 | 0 | return getPolicyKey() + "Custom:IntellectualPropertyPart"; |
204 | 0 | } |
205 | | |
206 | | OUString makeNumberedIntellectualPropertyPartKey() |
207 | 0 | { |
208 | 0 | return makeIntellectualPropertyPartKey() + ":n" + OUString::number(m_nIPPartNumber++); |
209 | 0 | } |
210 | | |
211 | | bool isIntellectualPropertyPartKey(std::u16string_view aKey) const |
212 | 0 | { |
213 | 0 | return o3tl::starts_with(aKey, makeIntellectualPropertyPartKey()); |
214 | 0 | } |
215 | | |
216 | | OUString makeFullTextualRepresentationKey() const |
217 | 0 | { |
218 | 0 | return getPolicyKey() + "Custom:FullTexturalRepresentation"; |
219 | 0 | } |
220 | | |
221 | | /// Classification creation origin key |
222 | 0 | OUString makeCreationOriginKey() const { return getPolicyKey() + "CreationOrigin"; } |
223 | | }; |
224 | | |
225 | | SFX2_DLLPUBLIC sfx::ClassificationCreationOrigin getCreationOriginProperty( |
226 | | css::uno::Reference<css::beans::XPropertyContainer> const& rxPropertyContainer, |
227 | | sfx::ClassificationKeyCreator const& rKeyCreator); |
228 | | } |
229 | | |
230 | | #endif |
231 | | |
232 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |