diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2017-11-10 09:00:52 -0500 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2017-11-11 17:03:02 +0100 |
commit | 8b312e9d69874d1c4d1e76acaf95f27da5072455 (patch) | |
tree | 1b2fa6d40d86c02d1ec18e5801d2789d00d0cca0 | |
parent | eaa7f27ca89d4048934baff6b2c3e1b9d6a5b1a4 (diff) |
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@libreoffice.org>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
-rw-r--r-- | sw/inc/rdfhelper.hxx | 7 | ||||
-rw-r--r-- | sw/source/core/doc/rdfhelper.cxx | 28 |
2 files changed, 35 insertions, 0 deletions
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); |