From 3c5fe72ac31d7ba65b04025b1635b711d68b77b3 Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Thu, 19 Oct 2017 11:50:34 +0400 Subject: TSCP: separate out paragraph classification name and value in RDF Change-Id: I99eb764842838b1481483b69d9183e52834e1298 Reviewed-on: https://gerrit.libreoffice.org/43629 Tested-by: Jenkins Reviewed-by: Ashod Nakashian --- sw/source/core/edit/edfcol.cxx | 48 +++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index ca5252cddf81..8767a27d3588 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -92,7 +92,8 @@ static const OUString MetaFilename("bails.rdf"); static const OUString MetaNS("urn:bails"); static const OUString ParagraphSignatureRDFName = "loext:paragraph:signature"; static const OUString ParagraphSignatureUsageRDFName = "loext:paragraph:signature:usage"; -static const OUString ParagraphClassificationRDFName = "loext:paragraph:classification"; +static const OUString ParagraphClassificationNameRDFName = "loext:paragraph:classification:name"; +static const OUString ParagraphClassificationValueRDFName = "loext:paragraph:classification:value"; static const OUString MetadataFieldServiceName = "com.sun.star.text.textfield.MetadataField"; static const OUString DocInfoServiceName = "com.sun.star.text.TextField.DocInfo.Custom"; @@ -238,8 +239,8 @@ OString lcl_getParagraphBodyText(const uno::Reference& xText /// Returns RDF (key, value) pair associated with the field, if any. std::pair lcl_getFieldRDF(const uno::Reference& xModel, - const uno::Reference& xField, - const OUString& rRDFName) + const uno::Reference& xField, + const OUString& rRDFName) { const css::uno::Reference xSubject(xField, uno::UNO_QUERY); std::map aStatements = SwRDFHelper::getStatements(xModel, MetaNS, xSubject); @@ -351,17 +352,17 @@ bool lcl_IsParagraphClassificationField(const uno::Reference& xMo const uno::Reference& xField, const OUString& sKey = OUString()) { - const std::pair rdfPair = lcl_getFieldRDF(xModel, xField, ParagraphClassificationRDFName); - return rdfPair.first == ParagraphClassificationRDFName && (sKey.isEmpty() || rdfPair.second == sKey); + const std::pair rdfPair = lcl_getFieldRDF(xModel, xField, ParagraphClassificationNameRDFName); + return rdfPair.first == ParagraphClassificationNameRDFName && (sKey.isEmpty() || rdfPair.second == sKey); } uno::Reference lcl_FindParagraphClassificationField(const uno::Reference& xModel, - const uno::Reference& xParent, + const uno::Reference& xParagraph, const OUString& sKey = OUString()) { uno::Reference xTextField; - uno::Reference xTextPortionEnumerationAccess(xParent, uno::UNO_QUERY); + uno::Reference xTextPortionEnumerationAccess(xParagraph, uno::UNO_QUERY); if (!xTextPortionEnumerationAccess.is()) return xTextField; @@ -408,7 +409,8 @@ bool lcl_UpdateParagraphClassificationField(SwDoc* pDoc, const uno::Reference& xModel, const uno::Reference& xField, const OUString& sKey, - const OUString& utf8Text) + const OUString& sValue, + const OUString& sDisplayText) { // Disable undo to avoid introducing noise when we edit the metadata field. const bool isUndoEnabled = pDoc->GetIDocumentUndoRedo().DoesUndo(); @@ -418,13 +420,14 @@ bool lcl_UpdateParagraphClassificationField(SwDoc* pDoc, }); const css::uno::Reference xSubject(xField, uno::UNO_QUERY); - SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xSubject, ParagraphClassificationRDFName, sKey); + SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xSubject, ParagraphClassificationNameRDFName, sKey); + SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xSubject, ParagraphClassificationValueRDFName, sValue); uno::Reference xText(xField, uno::UNO_QUERY); - const OUString curText = xText->getString(); - if (curText != utf8Text) + const OUString curDisplayText = xText->getString(); + if (curDisplayText != sDisplayText) { - xText->setString(utf8Text); + xText->setString(sDisplayText); return true; } @@ -925,8 +928,11 @@ void SwEditShell::ApplyParagraphClassification(std::vector xTextField = lcl_InsertParagraphClassification(xModel, xParent); - const OUString text = (isFirst ? ("(" + rResult.msString) : isLast ? (rResult.msString + ")") : rResult.msString); - lcl_UpdateParagraphClassificationField(GetDoc(), xModel, xTextField, sKey, text); + const OUString sValue = rResult.msString; + OUString sDisplayText = (isFirst ? ("(" + sValue) : sValue); + if (isLast) + sDisplayText += ")"; + lcl_UpdateParagraphClassificationField(GetDoc(), xModel, xTextField, sKey, sValue, sDisplayText); } } @@ -969,29 +975,27 @@ std::vector SwEditShell::CollectParagraphClassificati continue; uno::Reference xTextField(xField, uno::UNO_QUERY); - const std::pair rdfPair = lcl_getFieldRDF(xModel, xTextField, ParagraphClassificationRDFName); + const std::pair rdfNamePair = lcl_getFieldRDF(xModel, xTextField, ParagraphClassificationNameRDFName); + const std::pair rdfValuePair = lcl_getFieldRDF(xModel, xTextField, ParagraphClassificationValueRDFName); uno::Reference xTextRange(xField, uno::UNO_QUERY); - const OUString aName = rdfPair.second; + const OUString aName = rdfNamePair.second; + const OUString aValue = rdfValuePair.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 }); + aResult.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, xTextRange->getString(), nParagraph }); } } @@ -1527,7 +1531,7 @@ bool SwEditShell::IsCursorInParagraphMetadataField() const uno::Reference xModel = pDocSh->GetBaseModel(); const std::map aStatements = SwRDFHelper::getStatements(xModel, MetaNS, xSubject); if (aStatements.find(ParagraphSignatureRDFName) != aStatements.end() || - aStatements.find(ParagraphClassificationRDFName) != aStatements.end()) + aStatements.find(ParagraphClassificationNameRDFName) != aStatements.end()) return true; } } -- cgit