From 5402ac4e006b9aac6944f7fb9f1a9f256a754472 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 2 Dec 2015 14:09:42 +0100 Subject: 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 --- sw/Library_sw.mk | 1 + sw/inc/rdfhelper.hxx | 31 ++++++++++++++++++++++++ sw/source/core/doc/rdfhelper.cxx | 51 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 sw/inc/rdfhelper.hxx create mode 100644 sw/source/core/doc/rdfhelper.cxx (limited to 'sw') 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 + +#include + +#include + +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 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 + +#include +#include +#include + +#include + +#include +#include +#include +#include + +using namespace com::sun::star; + +std::map SwRDFHelper::getTextNodeStatements(const OUString& rType, SwTextNode& rTextNode) +{ + std::map aRet; + + uno::Reference xComponentContext(comphelper::getProcessComponentContext()); + uno::Reference xType = rdf::URI::create(xComponentContext, rType); + uno::Reference xDocumentMetadataAccess(rTextNode.GetDoc()->GetDocShell()->GetBaseModel(), uno::UNO_QUERY); + uno::Sequence< uno::Reference > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType); + if (!aGraphNames.hasElements()) + return aRet; + + uno::Reference xTextNode(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), uno::UNO_QUERY); + for (const uno::Reference& xGraphName : aGraphNames) + { + uno::Reference xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName); + uno::Reference xStatements = xGraph->getStatements(xTextNode, uno::Reference(), uno::Reference()); + while (xStatements->hasMoreElements()) + { + rdf::Statement aStatement = xStatements->nextElement().get(); + aRet[aStatement.Predicate->getStringValue()] = aStatement.Object->getStringValue(); + } + } + + return aRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit