diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2018-10-01 07:22:00 -0400 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2019-12-26 03:42:46 +0100 |
commit | 391db9909b9456042492b3fdc73eff140d724adf (patch) | |
tree | 050f9a66f8368500afed1d5faf5ad35968f17e97 | |
parent | 2be9633f3c1a145255d979a4d63aa957db5bff10 (diff) |
sw: rdf: Split graph-name lookup from getStatement
The graph-name lookup is significantly costly (compared
to the statement lookup, esp. when no statements exist).
Luckily, the graph-names do not change often and in the
course of enumerating all paragraphs (as happens for
paragraph-signature validation) it doesn't change at all.
This split allows for doing the graph-name lookup only
once and also allows for passing custom graph-names
directly, if we know them already.
Reviewed-on: https://gerrit.libreoffice.org/63002
Tested-by: Jenkins
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
(cherry picked from commit d5c9288e00cf39292d077d58be550af566b779ac)
Change-Id: I75425df201becb41105ba1fa6ba580af202d035c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85802
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
-rw-r--r-- | sw/inc/rdfhelper.hxx | 11 | ||||
-rw-r--r-- | sw/source/core/doc/rdfhelper.cxx | 42 |
2 files changed, 41 insertions, 12 deletions
diff --git a/sw/inc/rdfhelper.hxx b/sw/inc/rdfhelper.hxx index 18ddd87127d7..9ccb39156cb3 100644 --- a/sw/inc/rdfhelper.hxx +++ b/sw/inc/rdfhelper.hxx @@ -17,6 +17,7 @@ #include "swdllapi.h" #include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/Sequence.hxx> class SwTextNode; @@ -26,6 +27,7 @@ namespace com { namespace sun { namespace star { } namespace rdf { class XResource; + class XURI; } }}} @@ -33,6 +35,15 @@ namespace com { namespace sun { namespace star { class SW_DLLPUBLIC SwRDFHelper { public: + /// Gets all graph-names in RDF of a given type. + static css::uno::Sequence<css::uno::Reference<css::rdf::XURI>> + getGraphNames(const css::uno::Reference<css::frame::XModel>& xModel, const OUString& rType); + + /// Gets all (XResource, key, value) statements in RDF graphs given the graph-names. + static std::map<OUString, OUString> + getStatements(const css::uno::Reference<css::frame::XModel>& xModel, + const css::uno::Sequence<css::uno::Reference<css::rdf::XURI>>& rGraphNames, + const css::uno::Reference<css::rdf::XResource>& xSubject); /// Gets all (XResource, key, value) statements in RDF graphs of type rType. static std::map<OUString, OUString> getStatements(const css::uno::Reference<css::frame::XModel>& xModel, diff --git a/sw/source/core/doc/rdfhelper.cxx b/sw/source/core/doc/rdfhelper.cxx index 8e8c78d90313..29e9e8dcf230 100644 --- a/sw/source/core/doc/rdfhelper.cxx +++ b/sw/source/core/doc/rdfhelper.cxx @@ -23,26 +23,36 @@ using namespace com::sun::star; -std::map<OUString, OUString> SwRDFHelper::getStatements(const css::uno::Reference<css::frame::XModel>& xModel, - const OUString& rType, - const css::uno::Reference<css::rdf::XResource>& xSubject) +css::uno::Sequence<uno::Reference<css::rdf::XURI>> +SwRDFHelper::getGraphNames(const css::uno::Reference<css::frame::XModel>& xModel, + const OUString& rType) { - std::map<OUString, OUString> aRet; - - uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext()); + uno::Reference<uno::XComponentContext> xComponentContext( + comphelper::getProcessComponentContext()); uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType); uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel, uno::UNO_QUERY); - uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType); - if (!aGraphNames.hasElements()) + return xDocumentMetadataAccess->getMetadataGraphsWithType(xType); +} + +std::map<OUString, OUString> +SwRDFHelper::getStatements(const css::uno::Reference<css::frame::XModel>& xModel, + const uno::Sequence<uno::Reference<css::rdf::XURI>>& rGraphNames, + const css::uno::Reference<css::rdf::XResource>& xSubject) +{ + std::map<OUString, OUString> aRet; + if (!rGraphNames.hasElements()) return aRet; - for (const uno::Reference<rdf::XURI>& xGraphName : aGraphNames) + uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel, uno::UNO_QUERY); + const uno::Reference<rdf::XRepository>& xRepo = xDocumentMetadataAccess->getRDFRepository(); + for (const uno::Reference<rdf::XURI>& xGraphName : rGraphNames) { - uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName); - uno::Reference<container::XEnumeration> xStatements = xGraph->getStatements(xSubject, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>()); + uno::Reference<rdf::XNamedGraph> xGraph = xRepo->getGraph(xGraphName); + uno::Reference<container::XEnumeration> xStatements = xGraph->getStatements( + xSubject, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>()); while (xStatements->hasMoreElements()) { - rdf::Statement aStatement = xStatements->nextElement().get<rdf::Statement>(); + const rdf::Statement aStatement = xStatements->nextElement().get<rdf::Statement>(); aRet[aStatement.Predicate->getStringValue()] = aStatement.Object->getStringValue(); } } @@ -50,6 +60,14 @@ std::map<OUString, OUString> SwRDFHelper::getStatements(const css::uno::Referenc return aRet; } +std::map<OUString, OUString> +SwRDFHelper::getStatements(const css::uno::Reference<css::frame::XModel>& xModel, + const OUString& rType, + const css::uno::Reference<css::rdf::XResource>& xSubject) +{ + return getStatements(xModel, getGraphNames(xModel, rType), xSubject); +} + void SwRDFHelper::addStatement(const css::uno::Reference<css::frame::XModel>& xModel, const OUString& rType, const OUString& rPath, const css::uno::Reference<css::rdf::XResource>& xSubject, |