1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #ifndef INCLUDED_SFX2_CLASSIFICATIONHELPER_HXX
11 #define INCLUDED_SFX2_CLASSIFICATIONHELPER_HXX
16 #include <rtl/ustring.hxx>
17 #include <sfx2/dllapi.h>
18 #include <sfx2/infobar.hxx>
20 namespace com::sun::star::beans
{ class XPropertyContainer
; }
21 namespace com::sun::star::document
{ class XDocumentProperties
; }
25 /// Return code of SfxClassificationHelper::CheckPaste().
26 enum class SfxClassificationCheckPasteResult
29 TargetDocNotClassified
= 2,
30 DocClassificationTooLow
= 3
33 /// Specifies a policy type, to be used with SetBACName(). Getters always use IntellectualProperty for now.
34 enum class SfxClassificationPolicyType
38 IntellectualProperty
= 3
41 /// Shared code to handle Business Authorization Identification and Labeling Scheme (BAILS) properties.
42 class SFX2_DLLPUBLIC SfxClassificationHelper
45 std::unique_ptr
<Impl
> m_pImpl
;
48 /// Does the document have any BAILS properties?
49 static bool IsClassified(const css::uno::Reference
<css::document::XDocumentProperties
>& xDocumentProperties
);
50 /// Checks if pasting from xSource to xDestination would leak information.
51 static SfxClassificationCheckPasteResult
CheckPaste(const css::uno::Reference
<css::document::XDocumentProperties
>& xSource
,
52 const css::uno::Reference
<css::document::XDocumentProperties
>& xDestination
);
53 /// Wrapper around CheckPaste(): informs the user if necessary and finds out if the paste can be continued or not.
54 static bool ShowPasteInfo(SfxClassificationCheckPasteResult eResult
);
56 SfxClassificationHelper(const css::uno::Reference
<css::document::XDocumentProperties
>& xDocumentProperties
, bool bUseLocalizedPolicy
= true);
57 ~SfxClassificationHelper();
58 /// Get the currently selected category for eType.
59 const OUString
& GetBACName(SfxClassificationPolicyType eType
) const;
60 /// Return all possible valid category names, based on the policy.
61 std::vector
<OUString
> GetBACNames();
62 /// Return all possible valid category identifiers, based on the policy.
63 std::vector
<OUString
> GetBACIdentifiers();
64 /// Get the currently selected category abbreviation for eType. Returns full name if no abbreviation defined.
65 const OUString
& GetAbbreviatedBACName(const OUString
& sFullName
);
66 /// Get the currently selected category for the identifier.
67 OUString
GetBACNameForIdentifier(const OUString
& sIdentifier
);
68 /// Return all possible valid abbreviated category names, based on the policy.
69 std::vector
<OUString
> GetAbbreviatedBACNames();
70 /// Setting this sets all the other properties, based on the policy.
71 void SetBACName(const OUString
& rName
, SfxClassificationPolicyType eType
);
72 /// Returns the class with the higher priority (based on sensitivity).
73 OUString
GetHigherClass(const OUString
& first
, const OUString
& second
);
74 /// If GetImpactScale() and GetImpactLevel*() will return something meaningful.
75 bool HasImpactLevel();
76 InfobarType
GetImpactLevelType();
77 /// Larger value means more confidential.
78 sal_Int32
GetImpactLevel();
79 /// Comparing the GetImpactLevel() result is only meaningful when the impact scale is the same.
80 OUString
GetImpactScale();
81 OUString
GetDocumentWatermark();
82 /// The selected category has some content for the document header.
83 bool HasDocumentHeader();
84 /// The selected category has some content for the document footer.
85 bool HasDocumentFooter();
86 void UpdateInfobar(SfxViewFrame
& rViewFrame
);
88 std::vector
<OUString
> const & GetMarkings() const;
89 std::vector
<OUString
> const & GetIntellectualPropertyParts() const;
90 std::vector
<OUString
> const & GetIntellectualPropertyPartNumbers() const;
92 /// Does a best-effort conversion of rType to SfxClassificationPolicyType.
93 static SfxClassificationPolicyType
stringToPolicyType(const OUString
& rType
);
94 /// Returns the string representation of a SfxClassificationPolicyType element.
95 static const OUString
& policyTypeToString(SfxClassificationPolicyType eType
);
97 /// Brief text located at the top of each document's pages.
98 static const OUString
& PROP_DOCHEADER();
99 /// Brief text located at the bottom of each document's pages.
100 static const OUString
& PROP_DOCFOOTER();
101 /// Brief text formatted as a watermark on each document's page.
102 static const OUString
& PROP_DOCWATERMARK();
103 /// Get the property prefix for the IntellectualProperty policy type.
104 static const OUString
& PROP_PREFIX_INTELLECTUALPROPERTY();
106 static SfxClassificationPolicyType
getPolicyType();
112 /// Specifies the origin: either defined by the BAF policy or manual via. the advanced classification dialog
113 enum class ClassificationCreationOrigin
120 class ClassificationKeyCreator
123 const SfxClassificationPolicyType m_ePolicyType
;
124 const OUString m_sPolicy
;
125 sal_Int32 m_nTextNumber
;
126 sal_Int32 m_nIPPartNumber
;
127 sal_Int32 m_nMarkingNumber
;
129 OUString
const & getPolicyKey() const
134 ClassificationKeyCreator(SfxClassificationPolicyType ePolicyType
)
135 : m_ePolicyType(ePolicyType
)
136 , m_sPolicy(SfxClassificationHelper::policyTypeToString(m_ePolicyType
))
139 , m_nMarkingNumber(1)
142 OUString
makeTextKey() const
144 return getPolicyKey() + "Custom:Text";
147 OUString
makeNumberedTextKey()
149 return makeTextKey() + ":n" + OUString::number(m_nTextNumber
++);
152 bool isMarkingTextKey(OUString
const & aKey
) const
154 return aKey
.startsWith(makeTextKey());
157 OUString
makeCategoryNameKey() const
159 return getPolicyKey() + "BusinessAuthorizationCategory:Name";
162 bool isCategoryNameKey(OUString
const & aKey
) const
164 return aKey
.startsWith(makeCategoryNameKey());
167 OUString
makeCategoryIdentifierKey() const
169 return getPolicyKey() + "BusinessAuthorizationCategory:Identifier";
172 bool isCategoryIdentifierKey(OUString
const & aKey
) const
174 return aKey
.startsWith(makeCategoryIdentifierKey());
177 OUString
makeMarkingKey() const
179 return getPolicyKey() + "Custom:Marking";
182 OUString
makeNumberedMarkingKey()
184 return makeMarkingKey() + ":n" + OUString::number(m_nMarkingNumber
++);
187 bool isMarkingKey(OUString
const & aKey
) const
189 return aKey
.startsWith(makeMarkingKey());
192 OUString
makeIntellectualPropertyPartKey() const
194 return getPolicyKey() + "Custom:IntellectualPropertyPart";
197 OUString
makeNumberedIntellectualPropertyPartKey()
199 return makeIntellectualPropertyPartKey() + ":n" + OUString::number(m_nIPPartNumber
++);
202 bool isIntellectualPropertyPartKey(OUString
const & aKey
) const
204 return aKey
.startsWith(makeIntellectualPropertyPartKey());
207 OUString
makeFullTextualRepresentationKey() const
209 return getPolicyKey() + "Custom:FullTexturalRepresentation";
212 /// Classification creation origin key
213 OUString
makeCreationOriginKey() const
215 return getPolicyKey() + "CreationOrigin";
219 SFX2_DLLPUBLIC
sfx::ClassificationCreationOrigin
getCreationOriginProperty(
220 css::uno::Reference
<css::beans::XPropertyContainer
> const & rxPropertyContainer
,
221 sfx::ClassificationKeyCreator
const & rKeyCreator
);
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */