summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2017-10-01 19:32:28 -0400
committerAshod Nakashian <ashnakash@gmail.com>2017-10-02 14:13:22 +0200
commit807bf0680dfe32d62cf251c7eef63e8f1fc4a828 (patch)
tree3ffd6c4f1888d06cf9e9c8fb38e1c5f1d0af18bf
parentc140d8d97344299be70e32ac4ebc324ba4dc5dba (diff)
TSCP: refactor RDF reading for metadata fields
Change-Id: Ia24500f490d24e28446057bd840d8e6084bf3336 Reviewed-on: https://gerrit.libreoffice.org/43018 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
-rw-r--r--sw/source/core/edit/edfcol.cxx21
1 files changed, 14 insertions, 7 deletions
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index d99374f4bfa9..d41fbf5522ec 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -227,14 +227,23 @@ OString lcl_getParagraphBodyText(const uno::Reference<text::XTextContent>& xText
return strBuf.makeStringAndClear().trim().toUtf8();
}
+/// Returns RDF (key, value) pair associated with the field, if any.
+std::pair<OUString, OUString> lcl_getFieldRDF(const uno::Reference<frame::XModel>& xModel,
+ const uno::Reference<css::text::XTextField>& xField,
+ const OUString& rRDFName)
+{
+ const css::uno::Reference<css::rdf::XResource> xSubject(xField, uno::UNO_QUERY);
+ std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, MetaNS, xSubject);
+ const auto it = aStatements.find(rRDFName);
+ return it != aStatements.end() ? std::make_pair(it->first, it->second) : std::make_pair(OUString(), OUString());
+}
+
/// Returns true iff the field in question is paragraph signature.
/// Note: must have associated RDF, since signatures are othewise just metadata fields.
bool lcl_IsParagraphSignatureField(const uno::Reference<frame::XModel>& xModel,
const uno::Reference<css::text::XTextField>& xField)
{
- const css::uno::Reference<css::rdf::XResource> xSubject(xField, uno::UNO_QUERY);
- std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, MetaNS, xSubject);
- return aStatements.find(ParagraphSignatureRDFName) != aStatements.end();
+ return lcl_getFieldRDF(xModel, xField, ParagraphSignatureRDFName).first == ParagraphSignatureRDFName;
}
/// Validate and return validation result and signature field display text.
@@ -329,10 +338,8 @@ bool lcl_IsParagraphClassificationField(const uno::Reference<frame::XModel>& xMo
const uno::Reference<css::text::XTextField>& xField,
const OUString& sKey = OUString())
{
- const css::uno::Reference<css::rdf::XResource> xSubject(xField, uno::UNO_QUERY);
- std::map<OUString, OUString> aStatements = SwRDFHelper::getStatements(xModel, MetaNS, xSubject);
- const auto it = aStatements.find(ParagraphClassificationRDFName);
- return it != aStatements.end() && (sKey.isEmpty() || it->second == sKey);
+ const std::pair<OUString, OUString> rdfPair = lcl_getFieldRDF(xModel, xField, ParagraphClassificationRDFName);
+ return rdfPair.first == ParagraphClassificationRDFName && (sKey.isEmpty() || rdfPair.second == sKey);
}
uno::Reference<text::XTextField> lcl_FindParagraphClassificationField(const uno::Reference<frame::XModel>& xModel,