File indexing completed on 2024-05-26 16:15:25
0001 /* This file is part of the KDE project 0002 Copyright (C) 2010 KO GmbH <ben.martin@kogmbh.com> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef __rdf_KoRdfPrefixMapping_h__ 0021 #define __rdf_KoRdfPrefixMapping_h__ 0022 0023 #include "kordf_export.h" 0024 #include "RdfForward.h" 0025 // Qt 0026 #include <QSharedPointer> 0027 #include <QObject> 0028 #include <QMap> 0029 #include <QString> 0030 0031 0032 class KoRdfPrefixMappingPrivate; 0033 0034 /** 0035 * @short Supports bidirectional prefix:lname -> uri/lname translation 0036 * 0037 * @author Ben Martin <ben.martin@kogmbh.com> 0038 * @see KoDocumentRdf 0039 * 0040 * Both Rdf and XML support namespaces. This class is intended to allow 0041 * the advanced user to use such namespace mappings in the Calligra suite 0042 * when dealing with Rdf. 0043 * 0044 * For example, to be able to say dc:author for the dublin core author uri 0045 * 0046 */ 0047 class KORDF_EXPORT KoRdfPrefixMapping : public QObject 0048 { 0049 Q_OBJECT 0050 KoRdfPrefixMappingPrivate * const d; 0051 public: 0052 explicit KoRdfPrefixMapping(KoDocumentRdf *rdf); 0053 ~KoRdfPrefixMapping(); 0054 0055 /** 0056 * Convert a URI to a prefix:rest string 0057 * For example, given: 0058 * http://www.example.com/foo/bar 0059 * you might get 0060 * foo:bar 0061 * as the return value 0062 */ 0063 QString URItoPrefexedLocalname(const QString &uri) const; 0064 0065 /** 0066 * Opposite of URItoPrefexedLocalname(). Given foo:bar 0067 * you get http://www.example.com/foo/bar 0068 */ 0069 QString PrefexedLocalnameToURI(const QString &pname) const; 0070 0071 /** 0072 * Lookup the URI associated with a prefix. 0073 * given foo: you might get http://www.example.com/foo/ 0074 */ 0075 QString prefexToURI(const QString &pname) const; 0076 0077 /** 0078 * Insert a new mapping prefix -> uri 0079 */ 0080 void insert(const QString &prefix, const QString &url); 0081 0082 /** 0083 * Delete the mapping for prefix 0084 */ 0085 void remove(const QString &prefix); 0086 0087 /** 0088 * Load the prefix mapping information from the given model. 0089 * 0090 * @see save() 0091 */ 0092 void load(QSharedPointer<Soprano::Model> model); 0093 0094 /** 0095 * Save the prefix mapping into the given Rdf model. If there is 0096 * already a mapping in the model then those triples are deleted 0097 * and fresh triples inserted to represet the this prefix mapping 0098 * state. 0099 * 0100 * @see load() 0101 */ 0102 void save(QSharedPointer<Soprano::Model> model, Soprano::Node context) const; 0103 0104 /** 0105 * Debug method to capture the data structure in the logs. 0106 */ 0107 void dump() const; 0108 0109 private: 0110 friend class KoDocumentRdfEditWidget; 0111 QMap<QString, QString> mappings() const; 0112 QString canonPrefix(const QString &pname) const; 0113 }; 0114 0115 #endif