Kaydet (Commit) 2d928a87 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

TSCP: simplify key creation and detection

Change-Id: I5f87e77cf529d1c4d37ea55b8858c374a66ea9e4
Reviewed-on: https://gerrit.libreoffice.org/44018Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst f0306eee
......@@ -106,6 +106,74 @@ public:
static SfxClassificationPolicyType getPolicyType();
};
namespace sfx
{
class ClassificationKeyCreator
{
private:
SfxClassificationPolicyType m_ePolicyType;
sal_Int32 m_nTextNumber;
OUString getPolicyKey() const
{
return SfxClassificationHelper::policyTypeToString(m_ePolicyType);
}
public:
ClassificationKeyCreator(SfxClassificationPolicyType ePolicyType)
: m_ePolicyType(ePolicyType)
, m_nTextNumber(1)
{}
OUString makeMarkingTextKey() const
{
return getPolicyKey() + "Marking:Text";
}
OUString makeNumberedMarkingTextKey()
{
OUString sKey = makeMarkingTextKey() + ":" + OUString::number(m_nTextNumber);
m_nTextNumber++;
return sKey;
}
bool isMarkingTextKey(OUString const & aKey) const
{
return aKey.startsWith(makeMarkingTextKey());
}
OUString makeCategoryKey() const
{
return getPolicyKey() + "BusinessAuthorizationCategory:Name";
}
bool isCategoryKey(OUString const & aKey) const
{
return aKey.startsWith(makeCategoryKey());
}
OUString makeMarkingKey() const
{
return getPolicyKey() + "Extension:Marking";
}
bool isMarkingKey(OUString const & aKey) const
{
return aKey.startsWith(makeMarkingKey());
}
OUString makeIntellectualPropertyPartKey() const
{
return getPolicyKey() + "Extension:IntellectualPropertyPart";
}
bool isIntellectualPropertyPartKey(OUString const & aKey) const
{
return aKey.startsWith(makeIntellectualPropertyPartKey());
}
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -292,7 +292,7 @@ private:
void iterateSectionsAndCollect(std::vector<editeng::Section> const & rSections, EditTextObject const & rEditText)
{
OUString sPolicy = SfxClassificationHelper::policyTypeToString(SfxClassificationHelper::getPolicyType());
sfx::ClassificationKeyCreator aKeyCreator(SfxClassificationHelper::getPolicyType());
uno::Reference<document::XDocumentProperties> xDocumentProperties = SfxObjectShell::Current()->getDocProperties();
uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
......@@ -316,22 +316,22 @@ private:
{
const auto* pCustomPropertyField = dynamic_cast<const editeng::CustomPropertyField*>(pFieldItem->GetField());
OUString aKey = pCustomPropertyField->GetKey();
if (aKey.startsWith(sPolicy + "Marking:Text:"))
if (aKeyCreator.isMarkingTextKey(aKey))
{
OUString aValue = lcl_getProperty(xPropertyContainer, aKey);
m_aResults.push_back({ svx::ClassificationType::TEXT, aValue, sBlank });
}
else if (aKey.startsWith(sPolicy + "BusinessAuthorizationCategory:Name"))
else if (aKeyCreator.isCategoryKey(aKey))
{
OUString aValue = lcl_getProperty(xPropertyContainer, aKey);
m_aResults.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank });
}
else if (aKey.startsWith(sPolicy + "Extension:Marking"))
else if (aKeyCreator.isMarkingKey(aKey))
{
OUString aValue = lcl_getProperty(xPropertyContainer, aKey);
m_aResults.push_back({ svx::ClassificationType::MARKING, aValue, sBlank });
}
else if (aKey.startsWith(sPolicy + "Extension:IntellectualPropertyPart"))
else if (aKeyCreator.isIntellectualPropertyPartKey(aKey))
{
OUString aValue = lcl_getProperty(xPropertyContainer, aKey);
m_aResults.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, aValue, sBlank });
......@@ -403,8 +403,8 @@ private:
/// Delete the previous existing classification object(s) - if they exists
void deleteExistingObjects()
{
OUString sPolicy = SfxClassificationHelper::policyTypeToString(SfxClassificationHelper::getPolicyType());
OUString sKey = sPolicy + "BusinessAuthorizationCategory:Name";
sfx::ClassificationKeyCreator aKeyCreator(SfxClassificationHelper::getPolicyType());
OUString sKey = aKeyCreator.makeCategoryKey();
const sal_uInt16 nCount = m_rDrawViewShell.GetDoc()->GetMasterSdPageCount(PageKind::Standard);
......@@ -471,8 +471,7 @@ public:
aHelper.SetBACName(rResult.msString, SfxClassificationHelper::getPolicyType());
}
OUString sPolicy = SfxClassificationHelper::policyTypeToString(SfxClassificationHelper::getPolicyType());
sal_Int32 nTextNumber = 1;
sfx::ClassificationKeyCreator aKeyCreator(SfxClassificationHelper::getPolicyType());
Outliner* pOutliner = m_rDrawViewShell.GetDoc()->GetInternalOutliner();
OutlinerMode eOutlinerMode = pOutliner->GetMode();
......@@ -489,8 +488,7 @@ public:
{
case svx::ClassificationType::TEXT:
{
OUString sKey = sPolicy + "Marking:Text:" + OUString::number(nTextNumber);
nTextNumber++;
OUString sKey = aKeyCreator.makeNumberedMarkingTextKey();
addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msString);
pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey), EE_FEATURE_FIELD), aPosition);
}
......@@ -498,14 +496,14 @@ public:
case svx::ClassificationType::CATEGORY:
{
OUString sKey = sPolicy + "BusinessAuthorizationCategory:Name";
OUString sKey = aKeyCreator.makeCategoryKey();
pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey), EE_FEATURE_FIELD), aPosition);
}
break;
case svx::ClassificationType::MARKING:
{
OUString sKey = sPolicy + "Extension:Marking";
OUString sKey = aKeyCreator.makeMarkingKey();
addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msString);
pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey), EE_FEATURE_FIELD), aPosition);
}
......@@ -513,7 +511,7 @@ public:
case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART:
{
OUString sKey = sPolicy + "Extension:IntellectualPropertyPart";
OUString sKey = aKeyCreator.makeIntellectualPropertyPartKey();
addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msString);
pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey), EE_FEATURE_FIELD), aPosition);
}
......
......@@ -681,21 +681,20 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes
uno::Reference<text::XText> xFooterText;
xPageStyle->getPropertyValue(UNO_NAME_FOOTER_TEXT) >>= xFooterText;
sal_Int32 nTextNumber = 1;
uno::Reference<text::XParagraphCursor> xHeaderParagraphCursor(xHeaderText->createTextCursor(), uno::UNO_QUERY);
uno::Reference<text::XParagraphCursor> xFooterParagraphCursor(xFooterText->createTextCursor(), uno::UNO_QUERY);
sal_Int32 nParagraph = -1;
sfx::ClassificationKeyCreator aCreator(SfxClassificationHelper::getPolicyType());
for (svx::ClassificationResult const & rResult : rResults)
{
switch(rResult.meType)
{
case svx::ClassificationType::TEXT:
{
OUString sKey = sPolicy + "Marking:Text:" + OUString::number(nTextNumber);
nTextNumber++;
OUString sKey = aCreator.makeNumberedMarkingTextKey();
addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msString);
insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey);
......@@ -705,7 +704,7 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes
case svx::ClassificationType::CATEGORY:
{
OUString sKey = sPolicy + "BusinessAuthorizationCategory:Name";
OUString sKey = aCreator.makeCategoryKey();
insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey);
insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey);
}
......@@ -713,7 +712,7 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes
case svx::ClassificationType::MARKING:
{
OUString sKey = sPolicy + "Extension:Marking";
OUString sKey = aCreator.makeMarkingKey();
addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msString);
insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey);
insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey);
......@@ -722,7 +721,7 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes
case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART:
{
OUString sKey = sPolicy + "Extension:IntellectualPropertyPart";
OUString sKey = aCreator.makeIntellectualPropertyPartKey();
addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msString);
insertFieldToDocument(xMultiServiceFactory, xHeaderText, xHeaderParagraphCursor, sKey);
insertFieldToDocument(xMultiServiceFactory, xFooterText, xFooterParagraphCursor, sKey);
......@@ -795,7 +794,7 @@ std::vector<svx::ClassificationResult> SwEditShell::CollectAdvancedClassificatio
uno::Reference<document::XDocumentProperties> xDocumentProperties = SfxObjectShell::Current()->getDocProperties();
uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
OUString sPolicy = SfxClassificationHelper::policyTypeToString(SfxClassificationHelper::getPolicyType());
sfx::ClassificationKeyCreator aCreator(SfxClassificationHelper::getPolicyType());
const OUString sBlank("");
......@@ -830,25 +829,25 @@ std::vector<svx::ClassificationResult> SwEditShell::CollectAdvancedClassificatio
uno::Reference<beans::XPropertySet> xPropertySet(xTextField, uno::UNO_QUERY);
xPropertySet->getPropertyValue(UNO_NAME_NAME) >>= aName;
if (aName.startsWith(sPolicy + "Marking:Text:"))
if (aCreator.isMarkingTextKey(aName))
{
const OUString aValue = lcl_getProperty(xPropertyContainer, aName);
if (!aValue.isEmpty())
aResult.push_back({ svx::ClassificationType::TEXT, aValue, sBlank });
}
else if (aName.startsWith(sPolicy + "BusinessAuthorizationCategory:Name"))
else if (aCreator.isCategoryKey(aName))
{
const OUString aValue = lcl_getProperty(xPropertyContainer, aName);
if (!aValue.isEmpty())
aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank });
}
else if (aName.startsWith(sPolicy + "Extension:Marking"))
else if (aCreator.isMarkingKey(aName))
{
const OUString aValue = lcl_getProperty(xPropertyContainer, aName);
if (!aValue.isEmpty())
aResult.push_back({ svx::ClassificationType::MARKING, aValue, sBlank });
}
else if (aName.startsWith(sPolicy + "Extension:IntellectualPropertyPart"))
else if (aCreator.isIntellectualPropertyPartKey(aName))
{
const OUString aValue = lcl_getProperty(xPropertyContainer, aName);
if (!aValue.isEmpty())
......@@ -959,7 +958,7 @@ void SwEditShell::ApplyParagraphClassification(std::vector<svx::ClassificationRe
uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
const OUString sPolicy = SfxClassificationHelper::policyTypeToString(SfxClassificationHelper::getPolicyType());
sfx::ClassificationKeyCreator aKeyCreator(SfxClassificationHelper::getPolicyType());
// Prevent recursive validation since this is triggered on node updates, which we do below.
const bool bOldValidationFlag = SetParagraphSignatureValidation(false);
......@@ -979,7 +978,7 @@ void SwEditShell::ApplyParagraphClassification(std::vector<svx::ClassificationRe
// Since we always insert at the start of the paragraph,
// need to insert in reverse order.
std::reverse(aResults.begin(), aResults.end());
sal_Int32 nTextNumber = 1;
for (size_t nIndex = 0; nIndex < aResults.size(); ++nIndex)
{
const svx::ClassificationResult& rResult = aResults[nIndex];
......@@ -995,25 +994,25 @@ void SwEditShell::ApplyParagraphClassification(std::vector<svx::ClassificationRe
{
case svx::ClassificationType::TEXT:
{
sKey = sPolicy + "Marking:Text:" + OUString::number(nTextNumber++);
sKey = aKeyCreator.makeNumberedMarkingTextKey();
}
break;
case svx::ClassificationType::CATEGORY:
{
sKey = sPolicy + "BusinessAuthorizationCategory:Name";
sKey = aKeyCreator.makeCategoryKey();
}
break;
case svx::ClassificationType::MARKING:
{
sKey = sPolicy + "Extension:Marking";
sKey = aKeyCreator.makeMarkingKey();
}
break;
case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART:
{
sKey = sPolicy + "Extension:IntellectualPropertyPart";
sKey = aKeyCreator.makeIntellectualPropertyPartKey();
}
break;
......@@ -1051,7 +1050,7 @@ std::vector<svx::ClassificationResult> SwEditShell::CollectParagraphClassificati
uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
const OUString sPolicy = SfxClassificationHelper::policyTypeToString(SfxClassificationHelper::getPolicyType());
const sfx::ClassificationKeyCreator aKeyCreator(SfxClassificationHelper::getPolicyType());
while (xTextPortions->hasMoreElements())
{
......@@ -1074,19 +1073,19 @@ std::vector<svx::ClassificationResult> SwEditShell::CollectParagraphClassificati
const OUString aName = rdfNamePair.second;
const OUString aValue = rdfValuePair.second;
const OUString sBlank("");
if (aName.startsWith(sPolicy + "Marking:Text:"))
if (aKeyCreator.isMarkingTextKey(aName))
{
aResult.push_back({ svx::ClassificationType::TEXT, aValue, sBlank });
}
else if (aName.startsWith(sPolicy + "BusinessAuthorizationCategory:Name"))
else if (aKeyCreator.isCategoryKey(aName))
{
aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, sBlank });
}
else if (aName.startsWith(sPolicy + "Extension:Marking"))
else if (aKeyCreator.isMarkingKey(aName))
{
aResult.push_back({ svx::ClassificationType::MARKING, aValue, sBlank });
}
else if (aName.startsWith(sPolicy + "Extension:IntellectualPropertyPart"))
else if (aKeyCreator.isIntellectualPropertyPartKey(aName))
{
aResult.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, xTextRange->getString(), sBlank });
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment