summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-12-02 14:09:42 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-12-02 17:16:16 +0100
commit5402ac4e006b9aac6944f7fb9f1a9f256a754472 (patch)
tree6c257cc513629b8b26a3067e926a9cf4f218c8ea /sw
parent6054cfcb6e8531791f3daaf5c78f60050b67e761 (diff)
sw: initial SwRDFHelper
The purpose of this class is to provide access to the subset of the RDF metadata that's interesting for core code and for internal filters. Change-Id: Ibecba302dd839b537a36b9f7a15f012c6ea26869
Diffstat (limited to 'sw')
-rw-r--r--sw/Library_sw.mk1
-rw-r--r--sw/inc/rdfhelper.hxx31
-rw-r--r--sw/source/core/doc/rdfhelper.cxx51
3 files changed, 83 insertions, 0 deletions
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 789a777746c6..f9725be77cdf 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -214,6 +214,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
sw/source/core/doc/notxtfrm \
sw/source/core/doc/number \
sw/source/core/doc/poolfmt \
+ sw/source/core/doc/rdfhelper \
sw/source/core/doc/sortopt \
sw/source/core/doc/swserv \
sw/source/core/doc/swstylemanager \
diff --git a/sw/inc/rdfhelper.hxx b/sw/inc/rdfhelper.hxx
new file mode 100644
index 000000000000..d9787cb0e402
--- /dev/null
+++ b/sw/inc/rdfhelper.hxx
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SW_INC_RDFHELPER_HXX
+#define INCLUDED_SW_INC_RDFHELPER_HXX
+
+#include <map>
+
+#include <rtl/ustring.hxx>
+
+#include <swdllapi.h>
+
+class SwTextNode;
+
+/// Provides access to RDF metadata on core objects.
+class SW_DLLPUBLIC SwRDFHelper
+{
+public:
+ /// Gets all (rTextNode, key, value) statements in RDF graphs of type rType.
+ static std::map<OUString, OUString> getTextNodeStatements(const OUString& rType, SwTextNode& rTextNode);
+};
+
+#endif // INCLUDED_SW_INC_RDFHELPER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/rdfhelper.cxx b/sw/source/core/doc/rdfhelper.cxx
new file mode 100644
index 000000000000..f476bf7bc37e
--- /dev/null
+++ b/sw/source/core/doc/rdfhelper.cxx
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <rdfhelper.hxx>
+
+#include <com/sun/star/rdf/Statement.hpp>
+#include <com/sun/star/rdf/URI.hpp>
+#include <com/sun/star/rdf/XDocumentMetadataAccess.hpp>
+
+#include <comphelper/processfactory.hxx>
+
+#include <doc.hxx>
+#include <docsh.hxx>
+#include <ndtxt.hxx>
+#include <unoparagraph.hxx>
+
+using namespace com::sun::star;
+
+std::map<OUString, OUString> SwRDFHelper::getTextNodeStatements(const OUString& rType, SwTextNode& rTextNode)
+{
+ 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::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>());
+ while (xStatements->hasMoreElements())
+ {
+ rdf::Statement aStatement = xStatements->nextElement().get<rdf::Statement>();
+ aRet[aStatement.Predicate->getStringValue()] = aStatement.Object->getStringValue();
+ }
+ }
+
+ return aRet;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */