diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2018-10-01 07:22:00 -0400 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2018-12-03 08:11:23 +0100 |
commit | 7ddfd67e71a1e7ec0769e4277c28b4f6580885b1 (patch) | |
tree | fbd1e341699eaf45dadd818c0c3ac544f68daa1f /sw | |
parent | 8c84672e93a6bcdc53d93e7a3c8321684ed36736 (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.
Change-Id: I75425df201becb41105ba1fa6ba580af202d035c
Reviewed-on: https://gerrit.libreoffice.org/63002
Tested-by: Jenkins
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/rdfhelper.hxx | 17 | ||||
-rw-r--r-- | sw/source/core/doc/rdfhelper.cxx | 42 |
2 files changed, 44 insertions, 15 deletions
diff --git a/sw/inc/rdfhelper.hxx b/sw/inc/rdfhelper.hxx index 18ddd87127d7..218b81b0708c 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.h> class SwTextNode; @@ -26,6 +27,7 @@ namespace com { namespace sun { namespace star { } namespace rdf { class XResource; + class XURI; } }}} @@ -33,11 +35,20 @@ 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, - const OUString& rType, - const css::uno::Reference<css::rdf::XResource>& xSubject); + static std::map<OUString, OUString> + getStatements(const css::uno::Reference<css::frame::XModel>& xModel, const OUString& rType, + const css::uno::Reference<css::rdf::XResource>& xSubject); /// Add an (XResource, key, value) statement in the graph of type rType -- or if it does not exist, create a graph at rPath first. static void addStatement(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, |