/* -*- 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 #include using namespace com::sun::star; std::map SwRDFHelper::getTextNodeStatements(const OUString& rType, const SwTextNode& rNode) { std::map aRet; // We only read the node, but CreateXParagraph() needs a non-cost one. SwTextNode& rTextNode = const_cast(rNode); 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; } void SwRDFHelper::addTextNodeStatement(const OUString& rType, const OUString& rPath, SwTextNode& rTextNode, const OUString& rKey, const OUString& rValue) { 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); uno::Reference xGraphName; if (aGraphNames.hasElements()) xGraphName = aGraphNames[0]; else { uno::Sequence< uno::Reference > xTypes = { xType }; xGraphName = xDocumentMetadataAccess->addMetadataFile(rPath, xTypes); } uno::Reference xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName); uno::Reference xSubject(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), uno::UNO_QUERY); uno::Reference xKey = rdf::URI::create(xComponentContext, rKey); uno::Reference xValue = rdf::Literal::create(xComponentContext, rValue); xGraph->addStatement(xSubject, xKey, xValue); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */