TSCP: separate out paragraph classification name and value in RDF

Change-Id: I99eb764842838b1481483b69d9183e52834e1298
Reviewed-on: https://gerrit.libreoffice.org/43629
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
This commit is contained in:
Ashod Nakashian
2017-10-19 11:50:34 +04:00
committed by Ashod Nakashian
parent 81892b2037
commit 3c5fe72ac3

View File

@@ -92,7 +92,8 @@ static const OUString MetaFilename("bails.rdf");
static const OUString MetaNS("urn:bails"); static const OUString MetaNS("urn:bails");
static const OUString ParagraphSignatureRDFName = "loext:paragraph:signature"; static const OUString ParagraphSignatureRDFName = "loext:paragraph:signature";
static const OUString ParagraphSignatureUsageRDFName = "loext:paragraph:signature:usage"; 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 MetadataFieldServiceName = "com.sun.star.text.textfield.MetadataField";
static const OUString DocInfoServiceName = "com.sun.star.text.TextField.DocInfo.Custom"; static const OUString DocInfoServiceName = "com.sun.star.text.TextField.DocInfo.Custom";
@@ -238,8 +239,8 @@ OString lcl_getParagraphBodyText(const uno::Reference<text::XTextContent>& xText
/// Returns RDF (key, value) pair associated with the field, if any. /// Returns RDF (key, value) pair associated with the field, if any.
std::pair<OUString, OUString> lcl_getFieldRDF(const uno::Reference<frame::XModel>& xModel, std::pair<OUString, OUString> lcl_getFieldRDF(const uno::Reference<frame::XModel>& xModel,
const uno::Reference<css::text::XTextField>& xField, const uno::Reference<css::text::XTextField>& xField,
const OUString& rRDFName) const OUString& rRDFName)
{ {
const css::uno::Reference<css::rdf::XResource> xSubject(xField, uno::UNO_QUERY); const css::uno::Reference<css::rdf::XResource> xSubject(xField, uno::UNO_QUERY);
std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, MetaNS, xSubject); std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, MetaNS, xSubject);
@@ -351,17 +352,17 @@ bool lcl_IsParagraphClassificationField(const uno::Reference<frame::XModel>& xMo
const uno::Reference<css::text::XTextField>& xField, const uno::Reference<css::text::XTextField>& xField,
const OUString& sKey = OUString()) const OUString& sKey = OUString())
{ {
const std::pair<OUString, OUString> rdfPair = lcl_getFieldRDF(xModel, xField, ParagraphClassificationRDFName); const std::pair<OUString, OUString> rdfPair = lcl_getFieldRDF(xModel, xField, ParagraphClassificationNameRDFName);
return rdfPair.first == ParagraphClassificationRDFName && (sKey.isEmpty() || rdfPair.second == sKey); return rdfPair.first == ParagraphClassificationNameRDFName && (sKey.isEmpty() || rdfPair.second == sKey);
} }
uno::Reference<text::XTextField> lcl_FindParagraphClassificationField(const uno::Reference<frame::XModel>& xModel, uno::Reference<text::XTextField> lcl_FindParagraphClassificationField(const uno::Reference<frame::XModel>& xModel,
const uno::Reference<text::XTextContent>& xParent, const uno::Reference<text::XTextContent>& xParagraph,
const OUString& sKey = OUString()) const OUString& sKey = OUString())
{ {
uno::Reference<text::XTextField> xTextField; uno::Reference<text::XTextField> xTextField;
uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParent, uno::UNO_QUERY); uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraph, uno::UNO_QUERY);
if (!xTextPortionEnumerationAccess.is()) if (!xTextPortionEnumerationAccess.is())
return xTextField; return xTextField;
@@ -408,7 +409,8 @@ bool lcl_UpdateParagraphClassificationField(SwDoc* pDoc,
const uno::Reference<frame::XModel>& xModel, const uno::Reference<frame::XModel>& xModel,
const uno::Reference<css::text::XTextField>& xField, const uno::Reference<css::text::XTextField>& xField,
const OUString& sKey, const OUString& sKey,
const OUString& utf8Text) const OUString& sValue,
const OUString& sDisplayText)
{ {
// Disable undo to avoid introducing noise when we edit the metadata field. // Disable undo to avoid introducing noise when we edit the metadata field.
const bool isUndoEnabled = pDoc->GetIDocumentUndoRedo().DoesUndo(); const bool isUndoEnabled = pDoc->GetIDocumentUndoRedo().DoesUndo();
@@ -418,13 +420,14 @@ bool lcl_UpdateParagraphClassificationField(SwDoc* pDoc,
}); });
const css::uno::Reference<css::rdf::XResource> xSubject(xField, uno::UNO_QUERY); const css::uno::Reference<css::rdf::XResource> 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<css::text::XTextRange> xText(xField, uno::UNO_QUERY); uno::Reference<css::text::XTextRange> xText(xField, uno::UNO_QUERY);
const OUString curText = xText->getString(); const OUString curDisplayText = xText->getString();
if (curText != utf8Text) if (curDisplayText != sDisplayText)
{ {
xText->setString(utf8Text); xText->setString(sDisplayText);
return true; return true;
} }
@@ -925,8 +928,11 @@ void SwEditShell::ApplyParagraphClassification(std::vector<svx::ClassificationRe
} }
uno::Reference<text::XTextField> xTextField = lcl_InsertParagraphClassification(xModel, xParent); uno::Reference<text::XTextField> xTextField = lcl_InsertParagraphClassification(xModel, xParent);
const OUString text = (isFirst ? ("(" + rResult.msString) : isLast ? (rResult.msString + ")") : rResult.msString); const OUString sValue = rResult.msString;
lcl_UpdateParagraphClassificationField(GetDoc(), xModel, xTextField, sKey, text); OUString sDisplayText = (isFirst ? ("(" + sValue) : sValue);
if (isLast)
sDisplayText += ")";
lcl_UpdateParagraphClassificationField(GetDoc(), xModel, xTextField, sKey, sValue, sDisplayText);
} }
} }
@@ -969,29 +975,27 @@ std::vector<svx::ClassificationResult> SwEditShell::CollectParagraphClassificati
continue; continue;
uno::Reference<text::XTextField> xTextField(xField, uno::UNO_QUERY); uno::Reference<text::XTextField> xTextField(xField, uno::UNO_QUERY);
const std::pair<OUString, OUString> rdfPair = lcl_getFieldRDF(xModel, xTextField, ParagraphClassificationRDFName); const std::pair<OUString, OUString> rdfNamePair = lcl_getFieldRDF(xModel, xTextField, ParagraphClassificationNameRDFName);
const std::pair<OUString, OUString> rdfValuePair = lcl_getFieldRDF(xModel, xTextField, ParagraphClassificationValueRDFName);
uno::Reference<text::XTextRange> xTextRange(xField, uno::UNO_QUERY); uno::Reference<text::XTextRange> 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:")) if (aName.startsWith(sPolicy + "Marking:Text:"))
{ {
const OUString aValue = xTextRange->getString();
aResult.push_back({ svx::ClassificationType::TEXT, aValue, nParagraph }); aResult.push_back({ svx::ClassificationType::TEXT, aValue, nParagraph });
} }
else if (aName.startsWith(sPolicy + "BusinessAuthorizationCategory:Name")) else if (aName.startsWith(sPolicy + "BusinessAuthorizationCategory:Name"))
{ {
const OUString aValue = xTextRange->getString();
aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, nParagraph }); aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, nParagraph });
} }
else if (aName.startsWith(sPolicy + "Extension:Marking")) else if (aName.startsWith(sPolicy + "Extension:Marking"))
{ {
const OUString aValue = xTextRange->getString();
aResult.push_back({ svx::ClassificationType::MARKING, aValue, nParagraph }); aResult.push_back({ svx::ClassificationType::MARKING, aValue, nParagraph });
} }
else if (aName.startsWith(sPolicy + "Extension:IntellectualPropertyPart")) else if (aName.startsWith(sPolicy + "Extension:IntellectualPropertyPart"))
{ {
const OUString aValue = xTextRange->getString(); aResult.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, xTextRange->getString(), nParagraph });
aResult.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, aValue, nParagraph });
} }
} }
@@ -1527,7 +1531,7 @@ bool SwEditShell::IsCursorInParagraphMetadataField() const
uno::Reference<frame::XModel> xModel = pDocSh->GetBaseModel(); uno::Reference<frame::XModel> xModel = pDocSh->GetBaseModel();
const std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, MetaNS, xSubject); const std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, MetaNS, xSubject);
if (aStatements.find(ParagraphSignatureRDFName) != aStatements.end() || if (aStatements.find(ParagraphSignatureRDFName) != aStatements.end() ||
aStatements.find(ParagraphClassificationRDFName) != aStatements.end()) aStatements.find(ParagraphClassificationNameRDFName) != aStatements.end())
return true; return true;
} }
} }