Kaydet (Commit) 7ddfd67e authored tarafından Ashod Nakashian's avatar Ashod Nakashian Kaydeden (comit) Ashod Nakashian

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: 's avatarAshod Nakashian <ashnakash@gmail.com>
üst 8c84672e
......@@ -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,
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment