sc: filter: rtf: add method "AddFont"
[LibreOffice.git] / include / sfx2 / classificationhelper.hxx
blob5a4fa6b1eeab8ba7fdfcea14a9fb2e776ffb5e4d
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 <string_view>
15 #include <vector>
17 #include <o3tl/string_view.hxx>
18 #include <rtl/ustring.hxx>
19 #include <sfx2/dllapi.h>
20 #include <sfx2/infobar.hxx>
22 namespace com::sun::star::beans
24 class XPropertyContainer;
26 namespace com::sun::star::document
28 class XDocumentProperties;
31 class SfxViewFrame;
33 /// Return code of SfxClassificationHelper::CheckPaste().
34 enum class SfxClassificationCheckPasteResult
36 None = 1,
37 TargetDocNotClassified = 2,
38 DocClassificationTooLow = 3
41 /// Specifies a policy type, to be used with SetBACName(). Getters always use IntellectualProperty for now.
42 enum class SfxClassificationPolicyType
44 ExportControl = 1,
45 NationalSecurity = 2,
46 IntellectualProperty = 3
49 /// Shared code to handle Business Authorization Identification and Labeling Scheme (BAILS) properties.
50 class SFX2_DLLPUBLIC SfxClassificationHelper
52 class SAL_DLLPRIVATE Impl;
53 std::unique_ptr<Impl> m_pImpl;
55 public:
56 /// Does the document have any BAILS properties?
57 static bool IsClassified(
58 const css::uno::Reference<css::document::XDocumentProperties>& xDocumentProperties);
59 /// Checks if pasting from xSource to xDestination would leak information.
60 static SfxClassificationCheckPasteResult
61 CheckPaste(const css::uno::Reference<css::document::XDocumentProperties>& xSource,
62 const css::uno::Reference<css::document::XDocumentProperties>& xDestination);
63 /// Wrapper around CheckPaste(): informs the user if necessary and finds out if the paste can be continued or not.
64 static bool ShowPasteInfo(SfxClassificationCheckPasteResult eResult);
66 SfxClassificationHelper(
67 const css::uno::Reference<css::document::XDocumentProperties>& xDocumentProperties,
68 bool bUseLocalizedPolicy = true);
69 ~SfxClassificationHelper();
70 /// Get the currently selected category for eType.
71 const OUString& GetBACName(SfxClassificationPolicyType eType) const;
72 /// Return all possible valid category names, based on the policy.
73 std::vector<OUString> GetBACNames();
74 /// Return all possible valid category identifiers, based on the policy.
75 std::vector<OUString> GetBACIdentifiers();
76 /// Get the currently selected category abbreviation for eType. Returns full name if no abbreviation defined.
77 const OUString& GetAbbreviatedBACName(const OUString& sFullName);
78 /// Get the currently selected category for the identifier.
79 OUString GetBACNameForIdentifier(std::u16string_view sIdentifier);
80 /// Return all possible valid abbreviated category names, based on the policy.
81 std::vector<OUString> GetAbbreviatedBACNames();
82 /// Setting this sets all the other properties, based on the policy.
83 void SetBACName(const OUString& rName, SfxClassificationPolicyType eType);
84 /// Returns the class with the higher priority (based on sensitivity).
85 OUString GetHigherClass(const OUString& first, const OUString& second);
86 /// If GetImpactScale() and GetImpactLevel*() will return something meaningful.
87 bool HasImpactLevel();
88 InfobarType GetImpactLevelType();
89 /// Larger value means more confidential.
90 sal_Int32 GetImpactLevel();
91 /// Comparing the GetImpactLevel() result is only meaningful when the impact scale is the same.
92 OUString GetImpactScale();
93 OUString GetDocumentWatermark();
94 /// The selected category has some content for the document header.
95 bool HasDocumentHeader();
96 /// The selected category has some content for the document footer.
97 bool HasDocumentFooter();
98 void UpdateInfobar(SfxViewFrame& rViewFrame);
100 std::vector<OUString> const& GetMarkings() const;
101 std::vector<OUString> const& GetIntellectualPropertyParts() const;
102 std::vector<OUString> const& GetIntellectualPropertyPartNumbers() const;
104 /// Does a best-effort conversion of rType to SfxClassificationPolicyType.
105 static SfxClassificationPolicyType stringToPolicyType(std::u16string_view rType);
106 /// Returns the string representation of a SfxClassificationPolicyType element.
107 static const OUString& policyTypeToString(SfxClassificationPolicyType eType);
109 /// Brief text located at the top of each document's pages.
110 static const OUString& PROP_DOCHEADER();
111 /// Brief text located at the bottom of each document's pages.
112 static const OUString& PROP_DOCFOOTER();
113 /// Brief text formatted as a watermark on each document's page.
114 static const OUString& PROP_DOCWATERMARK();
115 /// Get the property prefix for the IntellectualProperty policy type.
116 static const OUString& PROP_PREFIX_INTELLECTUALPROPERTY();
118 static SfxClassificationPolicyType getPolicyType();
121 namespace sfx
123 /// Specifies the origin: either defined by the BAF policy or manual via. the advanced classification dialog
124 enum class ClassificationCreationOrigin
126 NONE,
127 BAF_POLICY,
128 MANUAL
131 class ClassificationKeyCreator
133 private:
134 const SfxClassificationPolicyType m_ePolicyType;
135 const OUString m_sPolicy;
136 sal_Int32 m_nTextNumber;
137 sal_Int32 m_nIPPartNumber;
138 sal_Int32 m_nMarkingNumber;
140 OUString const& getPolicyKey() const { return m_sPolicy; }
142 public:
143 ClassificationKeyCreator(SfxClassificationPolicyType ePolicyType)
144 : m_ePolicyType(ePolicyType)
145 , m_sPolicy(SfxClassificationHelper::policyTypeToString(m_ePolicyType))
146 , m_nTextNumber(1)
147 , m_nIPPartNumber(1)
148 , m_nMarkingNumber(1)
152 OUString makeTextKey() const { return getPolicyKey() + "Custom:Text"; }
154 OUString makeNumberedTextKey()
156 return makeTextKey() + ":n" + OUString::number(m_nTextNumber++);
159 bool isMarkingTextKey(std::u16string_view aKey) const
161 return o3tl::starts_with(aKey, makeTextKey());
164 OUString makeCategoryNameKey() const
166 return getPolicyKey() + "BusinessAuthorizationCategory:Name";
169 bool isCategoryNameKey(std::u16string_view aKey) const
171 return o3tl::starts_with(aKey, makeCategoryNameKey());
174 OUString makeCategoryIdentifierKey() const
176 return getPolicyKey() + "BusinessAuthorizationCategory:Identifier";
179 bool isCategoryIdentifierKey(std::u16string_view aKey) const
181 return o3tl::starts_with(aKey, makeCategoryIdentifierKey());
184 OUString makeMarkingKey() const { return getPolicyKey() + "Custom:Marking"; }
186 OUString makeNumberedMarkingKey()
188 return makeMarkingKey() + ":n" + OUString::number(m_nMarkingNumber++);
191 bool isMarkingKey(std::u16string_view aKey) const
193 return o3tl::starts_with(aKey, makeMarkingKey());
196 OUString makeIntellectualPropertyPartKey() const
198 return getPolicyKey() + "Custom:IntellectualPropertyPart";
201 OUString makeNumberedIntellectualPropertyPartKey()
203 return makeIntellectualPropertyPartKey() + ":n" + OUString::number(m_nIPPartNumber++);
206 bool isIntellectualPropertyPartKey(std::u16string_view aKey) const
208 return o3tl::starts_with(aKey, makeIntellectualPropertyPartKey());
211 OUString makeFullTextualRepresentationKey() const
213 return getPolicyKey() + "Custom:FullTexturalRepresentation";
216 /// Classification creation origin key
217 OUString makeCreationOriginKey() const { return getPolicyKey() + "CreationOrigin"; }
220 SFX2_DLLPUBLIC sfx::ClassificationCreationOrigin getCreationOriginProperty(
221 css::uno::Reference<css::beans::XPropertyContainer> const& rxPropertyContainer,
222 sfx::ClassificationKeyCreator const& rKeyCreator);
225 #endif
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */