diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2017-10-29 13:30:10 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2017-11-01 11:15:02 +0100 |
commit | 2d928a87788644f7c6d46b70ab03bc13a8bf89d3 (patch) | |
tree | 9652bb800ff00a11773ff6d58b920f4d7bc2a1b2 /sw | |
parent | f0306eee4d3ef8322c511a0bc642f0d907a2e83d (diff) |
TSCP: simplify key creation and detection
Change-Id: I5f87e77cf529d1c4d37ea55b8858c374a66ea9e4
Reviewed-on: https://gerrit.libreoffice.org/44018
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/edit/edfcol.cxx | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 0162cfaab48e..3b9a466e660e 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -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 }); } |