[Libreoffice-commits] core.git: sw/inc sw/source
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Sat Nov 11 16:03:35 UTC 2017
sw/inc/rdfhelper.hxx | 7 +++++++
sw/source/core/doc/rdfhelper.cxx | 28 ++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
New commits:
commit 8b312e9d69874d1c4d1e76acaf95f27da5072455
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Fri Nov 10 09:00:52 2017 -0500
RDF: support cloning of all entries for a given type
This is currently unused, but can come in handy later
on when we implement copy/pasting of metadata fields.
Change-Id: Idd4d6c186fa5c75e06f0ab1b0dfcbc85b6343116
Reviewed-on: https://gerrit.libreoffice.org/44602
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/sw/inc/rdfhelper.hxx b/sw/inc/rdfhelper.hxx
index bf72a5be40be..5ec56b8a1935 100644
--- a/sw/inc/rdfhelper.hxx
+++ b/sw/inc/rdfhelper.hxx
@@ -55,6 +55,13 @@ public:
const css::uno::Reference<css::rdf::XResource>& xSubject,
const OUString& rKey, const OUString& rValue);
+ /// Clone all statements in the graph of type rType, if any exists, from one subject to another.
+ static void cloneStatements(const css::uno::Reference<css::frame::XModel>& xSrcModel,
+ const css::uno::Reference<css::frame::XModel>& xDstModel,
+ const OUString& rType,
+ const css::uno::Reference<css::rdf::XResource>& xSrcSubject,
+ const css::uno::Reference<css::rdf::XResource>& xDstSubject);
+
/// Remove all statements in the graph of type rType, if any exists.
static void clearStatements(const css::uno::Reference<css::frame::XModel>& xModel,
const OUString& rType,
diff --git a/sw/source/core/doc/rdfhelper.cxx b/sw/source/core/doc/rdfhelper.cxx
index 4834dd2a5a12..8e8c78d90313 100644
--- a/sw/source/core/doc/rdfhelper.cxx
+++ b/sw/source/core/doc/rdfhelper.cxx
@@ -125,6 +125,34 @@ void SwRDFHelper::clearStatements(const css::uno::Reference<css::frame::XModel>&
}
}
+void SwRDFHelper::cloneStatements(const css::uno::Reference<css::frame::XModel>& xSrcModel,
+ const css::uno::Reference<css::frame::XModel>& xDstModel,
+ const OUString& rType,
+ const css::uno::Reference<css::rdf::XResource>& xSrcSubject,
+ const css::uno::Reference<css::rdf::XResource>& xDstSubject)
+{
+ uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
+ uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
+ uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xSrcModel, uno::UNO_QUERY);
+ uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
+ if (!aGraphNames.hasElements())
+ return;
+
+ for (const uno::Reference<rdf::XURI>& xGraphName : aGraphNames)
+ {
+ uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
+ uno::Reference<container::XEnumeration> xStatements = xGraph->getStatements(xSrcSubject, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>());
+ while (xStatements->hasMoreElements())
+ {
+ const rdf::Statement aStatement = xStatements->nextElement().get<rdf::Statement>();
+
+ const OUString sKey = aStatement.Predicate->getStringValue();
+ const OUString sValue = aStatement.Object->getStringValue();
+ addStatement(xDstModel, rType, xGraphName->getLocalName(), xDstSubject, sKey, sValue);
+ }
+ }
+}
+
std::map<OUString, OUString> SwRDFHelper::getTextNodeStatements(const OUString& rType, SwTextNode& rTextNode)
{
uno::Reference<rdf::XResource> xTextNode(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), uno::UNO_QUERY);
More information about the Libreoffice-commits
mailing list