[Libreoffice-commits] core.git: sw/inc sw/source

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Oct 2 12:15:05 UTC 2017


 sw/inc/editsh.hxx               |    1 
 sw/source/core/edit/edfcol.cxx  |   68 ++++++++++++++++++++++++++++++++++++++++
 sw/source/uibase/app/docsh2.cxx |    2 -
 3 files changed, 70 insertions(+), 1 deletion(-)

New commits:
commit 217dd15374a7020aa498817bcf4ea28157e7080f
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Oct 1 19:34:28 2017 -0400

    TSCP: edit paragraph classification
    
    Change-Id: Ib60a22fefe3464e29427a3d82b3af0926375433b
    Reviewed-on: https://gerrit.libreoffice.org/43020
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index f25cd59b0c04..9b9692b4c47e 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -382,6 +382,7 @@ public:
 
     /// Apply the classification to the paragraph at cursor.
     void ApplyParagraphClassification(std::vector<svx::ClassificationResult> aResult);
+    std::vector<svx::ClassificationResult> CollectParagraphClassification();
 
     /// Returns true iff the cursor is within a paragraph metadata field.
     /// Currently there are two variants: signature and classification.
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index fb13fedac53b..e1bd4cbcb144 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -851,6 +851,74 @@ void SwEditShell::ApplyParagraphClassification(std::vector<svx::ClassificationRe
     }
 }
 
+std::vector<svx::ClassificationResult> SwEditShell::CollectParagraphClassification()
+{
+    std::vector<svx::ClassificationResult> aResult;
+
+    SwDocShell* pDocShell = GetDoc()->GetDocShell();
+    if (!pDocShell)
+        return aResult;
+
+    SwTextNode* pNode = GetCursor()->Start()->nNode.GetNode().GetTextNode();
+    if (pNode == nullptr)
+        return aResult;
+
+    uno::Reference<text::XTextContent> xParent = SwXParagraph::CreateXParagraph(*pNode->GetDoc(), pNode);
+    uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
+    uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
+
+    uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParent, uno::UNO_QUERY);
+    if (!xTextPortionEnumerationAccess.is())
+        return aResult;
+
+    uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
+
+    const OUString sPolicy = SfxClassificationHelper::policyTypeToString(getPolicyType());
+    const sal_Int32 nParagraph = 1;
+
+    while (xTextPortions->hasMoreElements())
+    {
+        uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
+        OUString aTextPortionType;
+        xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType;
+        if (aTextPortionType != UNO_NAME_TEXT_FIELD)
+            continue;
+
+        uno::Reference<lang::XServiceInfo> xField;
+        xTextPortion->getPropertyValue(UNO_NAME_TEXT_FIELD) >>= xField;
+        if (!xField->supportsService(MetadataFieldServiceName))
+            continue;
+
+        uno::Reference<text::XTextField> xTextField(xField, uno::UNO_QUERY);
+        const std::pair<OUString, OUString> rdfPair = lcl_getFieldRDF(xModel, xTextField, ParagraphClassificationRDFName);
+
+        uno::Reference<text::XTextRange> xTextRange(xField, uno::UNO_QUERY);
+        const OUString aName = rdfPair.second;
+        if (aName.startsWith(sPolicy + "Marking:Text:"))
+        {
+            const OUString aValue = xTextRange->getString();
+            aResult.push_back({ svx::ClassificationType::TEXT, aValue, nParagraph });
+        }
+        else if (aName.startsWith(sPolicy + "BusinessAuthorizationCategory:Name"))
+        {
+            const OUString aValue = xTextRange->getString();
+            aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, nParagraph });
+        }
+        else if (aName.startsWith(sPolicy + "Extension:Marking"))
+        {
+            const OUString aValue = xTextRange->getString();
+            aResult.push_back({ svx::ClassificationType::MARKING, aValue, nParagraph });
+        }
+        else if (aName.startsWith(sPolicy + "Extension:IntellectualPropertyPart"))
+        {
+            const OUString aValue = xTextRange->getString();
+            aResult.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, aValue, nParagraph });
+        }
+    }
+
+    return aResult;
+}
+
 sal_Int16 lcl_GetAngle(const drawing::HomogenMatrix3& rMatrix)
 {
     basegfx::B2DHomMatrix aTransformation;
diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx
index 944e9aec3d45..3deb35e4690d 100644
--- a/sw/source/uibase/app/docsh2.cxx
+++ b/sw/source/uibase/app/docsh2.cxx
@@ -1186,7 +1186,7 @@ void SwDocShell::Execute(SfxRequest& rReq)
                 pShell->SignParagraph();
             }));
 
-            std::vector<svx::ClassificationResult> aInput = pShell->CollectAdvancedClassification();
+            std::vector<svx::ClassificationResult> aInput = pShell->CollectParagraphClassification();
             pDialog->setupValues(aInput);
 
             if (RET_OK == pDialog->Execute())


More information about the Libreoffice-commits mailing list