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

sw: new RDF helpers

These are to help with adding paragraph
signature metadata.

Change-Id: Icac32c9e7937696f755ff3c99d619e97d56fc2e8
Reviewed-on: https://gerrit.libreoffice.org/41590Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarAshod Nakashian <ashnakash@gmail.com>
üst 60c5955c
...@@ -16,20 +16,58 @@ ...@@ -16,20 +16,58 @@
#include <swdllapi.h> #include <swdllapi.h>
#include <com/sun/star/uno/Reference.hxx>
class SwTextNode; class SwTextNode;
namespace com { namespace sun { namespace star {
namespace frame {
class XModel;
}
namespace rdf {
class XResource;
}
}}}
/// Provides access to RDF metadata on core objects. /// Provides access to RDF metadata on core objects.
class SW_DLLPUBLIC SwRDFHelper class SW_DLLPUBLIC SwRDFHelper
{ {
public: public:
/// 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);
/// 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,
const OUString& rType, const OUString& rPath,
const css::uno::Reference<css::rdf::XResource>& xSubject,
const OUString& rKey, const OUString& rValue);
/// Remove an (XResource, key, value) statement in the graph of type rType, if it exists.
static void removeStatement(const css::uno::Reference<css::frame::XModel>& xModel,
const OUString& rType,
const css::uno::Reference<css::rdf::XResource>& xSubject,
const OUString& rKey, const OUString& rValue);
/// 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,
const css::uno::Reference<css::rdf::XResource>& xSubject);
/// Gets all (rTextNode, key, value) statements in RDF graphs of type rType. /// Gets all (rTextNode, key, value) statements in RDF graphs of type rType.
static std::map<OUString, OUString> getTextNodeStatements(const OUString& rType, SwTextNode& rTextNode); static std::map<OUString, OUString> getTextNodeStatements(const OUString& rType, SwTextNode& rTextNode);
/// Add an (rTextNode, key, value) statement in the graph of type rType -- or if it does not exist, create a graph at rPath first. /// Add an (rTextNode, key, value) statement in the graph of type rType -- or if it does not exist, create a graph at rPath first.
static void addTextNodeStatement(const OUString& rType, const OUString& rPath, SwTextNode& rTextNode, const OUString& rKey, const OUString& rValue); static void addTextNodeStatement(const OUString& rType, const OUString& rPath, SwTextNode& rTextNode, const OUString& rKey, const OUString& rValue);
/// Remove an (rTextNode, key, value) statement in the graph of type rType.
static void removeTextNodeStatement(const OUString& rType, SwTextNode& rTextNode, const OUString& rKey, const OUString& rValue);
/// Update an (rTextNode, key, value) statement in the graph of type rType from old value to new. Creates the graph at rPath if doesn't exist. /// Update an (rTextNode, key, value) statement in the graph of type rType from old value to new. Creates the graph at rPath if doesn't exist.
static void updateTextNodeStatement(const OUString& rType, const OUString& rPath, SwTextNode& rTextNode, const OUString& rKey, const OUString& rOldValue, const OUString& rNewValue); static void updateTextNodeStatement(const OUString& rType, const OUString& rPath, SwTextNode& rTextNode, const OUString& rKey, const OUString& rOldValue, const OUString& rNewValue);
}; };
#endif // INCLUDED_SW_INC_RDFHELPER_HXX #endif // INCLUDED_SW_INC_RDFHELPER_HXX
......
...@@ -23,22 +23,23 @@ ...@@ -23,22 +23,23 @@
using namespace com::sun::star; using namespace com::sun::star;
std::map<OUString, OUString> SwRDFHelper::getTextNodeStatements(const OUString& rType, SwTextNode& rTextNode) 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)
{ {
std::map<OUString, OUString> aRet; 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::XURI> xType = rdf::URI::create(xComponentContext, rType);
uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(rTextNode.GetDoc()->GetDocShell()->GetBaseModel(), uno::UNO_QUERY); uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType); uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
if (!aGraphNames.hasElements()) if (!aGraphNames.hasElements())
return aRet; return aRet;
uno::Reference<rdf::XResource> xTextNode(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), uno::UNO_QUERY);
for (const uno::Reference<rdf::XURI>& xGraphName : aGraphNames) for (const uno::Reference<rdf::XURI>& xGraphName : aGraphNames)
{ {
uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName); uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
uno::Reference<container::XEnumeration> xStatements = xGraph->getStatements(xTextNode, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>()); uno::Reference<container::XEnumeration> xStatements = xGraph->getStatements(xSubject, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>());
while (xStatements->hasMoreElements()) while (xStatements->hasMoreElements())
{ {
rdf::Statement aStatement = xStatements->nextElement().get<rdf::Statement>(); rdf::Statement aStatement = xStatements->nextElement().get<rdf::Statement>();
...@@ -49,11 +50,14 @@ std::map<OUString, OUString> SwRDFHelper::getTextNodeStatements(const OUString& ...@@ -49,11 +50,14 @@ std::map<OUString, OUString> SwRDFHelper::getTextNodeStatements(const OUString&
return aRet; return aRet;
} }
void SwRDFHelper::addTextNodeStatement(const OUString& rType, const OUString& rPath, SwTextNode& rTextNode, const OUString& rKey, const OUString& rValue) 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,
const OUString& rKey, const OUString& rValue)
{ {
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::XURI> xType = rdf::URI::create(xComponentContext, rType);
uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(rTextNode.GetDoc()->GetDocShell()->GetBaseModel(), uno::UNO_QUERY); uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType); uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
uno::Reference<rdf::XURI> xGraphName; uno::Reference<rdf::XURI> xGraphName;
if (aGraphNames.hasElements()) if (aGraphNames.hasElements())
...@@ -64,12 +68,83 @@ void SwRDFHelper::addTextNodeStatement(const OUString& rType, const OUString& rP ...@@ -64,12 +68,83 @@ void SwRDFHelper::addTextNodeStatement(const OUString& rType, const OUString& rP
xGraphName = xDocumentMetadataAccess->addMetadataFile(rPath, xTypes); xGraphName = xDocumentMetadataAccess->addMetadataFile(rPath, xTypes);
} }
uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName); uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
uno::Reference<rdf::XResource> xSubject(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), uno::UNO_QUERY);
uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey); uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey);
uno::Reference<rdf::XLiteral> xValue = rdf::Literal::create(xComponentContext, rValue); uno::Reference<rdf::XLiteral> xValue = rdf::Literal::create(xComponentContext, rValue);
xGraph->addStatement(xSubject, xKey, xValue); xGraph->addStatement(xSubject, xKey, xValue);
} }
void SwRDFHelper::removeStatement(const css::uno::Reference<css::frame::XModel>& xModel,
const OUString& rType,
const css::uno::Reference<css::rdf::XResource>& xSubject,
const OUString& rKey, const OUString& rValue)
{
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;
uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(aGraphNames[0]);
uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey);
uno::Reference<rdf::XLiteral> xValue = rdf::Literal::create(xComponentContext, rValue);
xGraph->removeStatements(xSubject, xKey, xValue);
}
void SwRDFHelper::clearStatements(const css::uno::Reference<css::frame::XModel>& xModel,
const OUString& rType,
const css::uno::Reference<css::rdf::XResource>& xSubject)
{
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;
for (const uno::Reference<rdf::XURI>& xGraphName : aGraphNames)
{
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>());
while (xStatements->hasMoreElements())
{
rdf::Statement aStatement = xStatements->nextElement().get<rdf::Statement>();
uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, aStatement.Predicate->getStringValue());
uno::Reference<rdf::XLiteral> xValue = rdf::Literal::create(xComponentContext, aStatement.Object->getStringValue());
xGraph->removeStatements(xSubject, xKey, xValue);
}
}
}
std::map<OUString, OUString> SwRDFHelper::getTextNodeStatements(const OUString& rType, SwTextNode& rTextNode)
{
uno::Reference<rdf::XResource> xTextNode(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), uno::UNO_QUERY);
return getStatements(rTextNode.GetDoc()->GetDocShell()->GetBaseModel(), rType, xTextNode);
}
void SwRDFHelper::addTextNodeStatement(const OUString& rType, const OUString& rPath, SwTextNode& rTextNode, const OUString& rKey, const OUString& rValue)
{
uno::Reference<rdf::XResource> xSubject(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), uno::UNO_QUERY);
addStatement(rTextNode.GetDoc()->GetDocShell()->GetBaseModel(), rType, rPath, xSubject, rKey, rValue);
}
void SwRDFHelper::removeTextNodeStatement(const OUString& rType, SwTextNode& rTextNode, const OUString& rKey, const OUString& rValue)
{
uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(rTextNode.GetDoc()->GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
if (!aGraphNames.hasElements())
return;
uno::Reference<rdf::XURI> xGraphName = aGraphNames[0];
uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
uno::Reference<rdf::XResource> xSubject(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), uno::UNO_QUERY);
uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey);
uno::Reference<rdf::XLiteral> xValue = rdf::Literal::create(xComponentContext, rValue);
xGraph->removeStatements(xSubject, xKey, xValue);
}
void SwRDFHelper::updateTextNodeStatement(const OUString& rType, const OUString& rPath, SwTextNode& rTextNode, const OUString& rKey, const OUString& rOldValue, const OUString& rNewValue) void SwRDFHelper::updateTextNodeStatement(const OUString& rType, const OUString& rPath, SwTextNode& rTextNode, const OUString& rKey, const OUString& rOldValue, const OUString& rNewValue)
{ {
uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext()); uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
......
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