From 8b312e9d69874d1c4d1e76acaf95f27da5072455 Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Fri, 10 Nov 2017 09:00:52 -0500 Subject: 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 Reviewed-by: Ashod Nakashian --- sw/inc/rdfhelper.hxx | 7 +++++++ sw/source/core/doc/rdfhelper.cxx | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) 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& 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& xSrcModel, + const css::uno::Reference& xDstModel, + const OUString& rType, + const css::uno::Reference& xSrcSubject, + const css::uno::Reference& xDstSubject); + /// Remove all statements in the graph of type rType, if any exists. static void clearStatements(const css::uno::Reference& 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& } } +void SwRDFHelper::cloneStatements(const css::uno::Reference& xSrcModel, + const css::uno::Reference& xDstModel, + const OUString& rType, + const css::uno::Reference& xSrcSubject, + const css::uno::Reference& xDstSubject) +{ + uno::Reference xComponentContext(comphelper::getProcessComponentContext()); + uno::Reference xType = rdf::URI::create(xComponentContext, rType); + uno::Reference xDocumentMetadataAccess(xSrcModel, uno::UNO_QUERY); + uno::Sequence< uno::Reference > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType); + if (!aGraphNames.hasElements()) + return; + + for (const uno::Reference& xGraphName : aGraphNames) + { + uno::Reference xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName); + uno::Reference xStatements = xGraph->getStatements(xSrcSubject, uno::Reference(), uno::Reference()); + while (xStatements->hasMoreElements()) + { + const rdf::Statement aStatement = xStatements->nextElement().get(); + + const OUString sKey = aStatement.Predicate->getStringValue(); + const OUString sValue = aStatement.Object->getStringValue(); + addStatement(xDstModel, rType, xGraphName->getLocalName(), xDstSubject, sKey, sValue); + } + } +} + std::map SwRDFHelper::getTextNodeStatements(const OUString& rType, SwTextNode& rTextNode) { uno::Reference xTextNode(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), uno::UNO_QUERY); -- cgit