summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2017-08-25 13:32:04 -0400
committerAshod Nakashian <ashnakash@gmail.com>2017-08-26 23:45:19 +0200
commit714282573cd6fe8c9d95d3072c15d1e6cb94dc73 (patch)
tree7d3fde000e10ea1cdaee1fe7fa2a50d11acadc79
parent60c5955cb9f75a066cde0be3a3e39de83845279b (diff)
sw: new RDF helpers
These are to help with adding paragraph signature metadata. Change-Id: Icac32c9e7937696f755ff3c99d619e97d56fc2e8 Reviewed-on: https://gerrit.libreoffice.org/41590 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
-rw-r--r--sw/inc/rdfhelper.hxx38
-rw-r--r--sw/source/core/doc/rdfhelper.cxx89
2 files changed, 120 insertions, 7 deletions
diff --git a/sw/inc/rdfhelper.hxx b/sw/inc/rdfhelper.hxx
index c47ba0b5c9a6..dccd152d026f 100644
--- a/sw/inc/rdfhelper.hxx
+++ b/sw/inc/rdfhelper.hxx
@@ -16,20 +16,58 @@
#include <swdllapi.h>
+#include <com/sun/star/uno/Reference.hxx>
+
class SwTextNode;
+namespace com { namespace sun { namespace star {
+ namespace frame {
+ class XModel;
+ }
+ namespace rdf {
+ class XResource;
+ }
+}}}
+
/// Provides access to RDF metadata on core objects.
class SW_DLLPUBLIC SwRDFHelper
{
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.
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.
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.
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
diff --git a/sw/source/core/doc/rdfhelper.cxx b/sw/source/core/doc/rdfhelper.cxx
index 390e17ba7d79..3e146c80db39 100644
--- a/sw/source/core/doc/rdfhelper.cxx
+++ b/sw/source/core/doc/rdfhelper.cxx
@@ -23,22 +23,23 @@
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;
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::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
if (!aGraphNames.hasElements())
return aRet;
- uno::Reference<rdf::XResource> xTextNode(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), uno::UNO_QUERY);
for (const uno::Reference<rdf::XURI>& xGraphName : aGraphNames)
{
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())
{
rdf::Statement aStatement = xStatements->nextElement().get<rdf::Statement>();
@@ -49,11 +50,14 @@ std::map<OUString, OUString> SwRDFHelper::getTextNodeStatements(const OUString&
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<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::Reference<rdf::XURI> xGraphName;
if (aGraphNames.hasElements())
@@ -64,12 +68,83 @@ void SwRDFHelper::addTextNodeStatement(const OUString& rType, const OUString& rP
xGraphName = xDocumentMetadataAccess->addMetadataFile(rPath, xTypes);
}
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->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)
{
uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());