• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

syndication/rdf

  • syndication
  • rdf
modelmaker.cpp
1/*
2 * This file is part of the syndication library
3 *
4 * Copyright (C) 2006 Frank Osterfeld <osterfeld@kde.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#include "modelmaker.h"
24#include "literal.h"
25#include "model.h"
26#include "property.h"
27#include "rdfvocab.h"
28#include "resource.h"
29#include "sequence.h"
30#include "statement.h"
31
32#include <QtXml/QDomElement>
33#include <QtCore/QString>
34
35namespace Syndication {
36namespace RDF {
37
38
39Model ModelMaker::createFromXML(const QDomDocument& doc)
40{
41 Model model;
42
43 if (doc.isNull())
44 return model;
45
46 QDomElement rdfNode = doc.documentElement();
47
48 QDomNodeList list = rdfNode.childNodes();
49
50 for (uint i = 0; i < list.length(); ++i)
51 {
52 if (list.item(i).isElement())
53 {
54 QDomElement el = list.item(i).toElement();
55 readResource(model, el);
56 }
57 }
58
59 return model;
60}
61
62ResourcePtr ModelMaker::readResource(Model& model, const QDomElement& el)
63{
64 QString rdfns = RDFVocab::self()->namespaceURI();
65 QString about = QLatin1String("about");
66 QString resource = QLatin1String("resource");
67 QString descriptionStr = QLatin1String("Description");
68
69 ResourcePtr res;
70
71 ResourcePtr type = model.createResource(el.namespaceURI() + el.localName());
72
73 if (*type == *(RDFVocab::self()->seq()))
74 {
75 SequencePtr seq = model.createSequence(el.attribute(about));
76
77 res = seq;
78 }
79 else
80 {
81 res = model.createResource(el.attribute(about));
82 }
83
84 model.addStatement(res, RDFVocab::self()->type(), type);
85
86 QDomNodeList children = el.childNodes();
87
88 bool isSeq = res->isSequence();
89
90 for (uint i = 0; i < children.length(); ++i)
91 {
92 if (children.item(i).isElement())
93 {
94 QDomElement ce = children.item(i).toElement();
95
96 PropertyPtr pred = model.createProperty(ce.namespaceURI() + ce.localName());
97
98 if (ce.hasAttribute(resource)) // referenced Resource via (rdf:)resource
99 {
100 NodePtr obj = model.createResource(ce.attribute(resource));
101
102 if (isSeq && *pred == *(RDFVocab::self()->li()))
103 {
104 SequencePtr tseq = boost::static_pointer_cast<Sequence>(res);
105 tseq->append(obj);
106 }
107 else
108 model.addStatement(res, pred, obj);
109 }
110 else if (!ce.text().isEmpty() && ce.lastChildElement().isNull()) // Literal
111 {
112 NodePtr obj = model.createLiteral(ce.text());
113
114 if (isSeq && *pred == *(RDFVocab::self()->li()))
115 {
116 SequencePtr tseq = boost::static_pointer_cast<Sequence>(res);
117 tseq->append(obj);
118 }
119 else
120 model.addStatement(res, pred, obj);
121 }
122 else // embedded description
123 {
124 QDomElement re = ce.lastChildElement();
125
126 QString uri = re.attribute(about);
127
128 // read recursively
129 NodePtr obj = readResource(model, re);
130
131 if (isSeq && *pred == *(RDFVocab::self()->li()))
132 {
133 SequencePtr tseq = boost::static_pointer_cast<Sequence>(res);
134 tseq->append(obj);
135 }
136 else
137 model.addStatement(res, pred, obj);
138
139 }
140
141 //TODO: bag, reification (nice to have, but not important for basic RSS 1.0)
142 }
143 }
144
145 return res;
146}
147
148} // namespace RDF
149} // namespace Syndication
Syndication::RDF::ModelMaker::createFromXML
Model createFromXML(const QDomDocument &doc)
parses an RDF model from RDF/XML
Definition modelmaker.cpp:39
Syndication::RDF::Model
An RDF model, a set of RDF statements.
Definition model.h:50
Syndication::RDF::Model::addStatement
virtual StatementPtr addStatement(ResourcePtr subject, PropertyPtr predicate, NodePtr object)
adds a statement to the model.
Definition model.cpp:146
Syndication::RDF::Model::createResource
virtual ResourcePtr createResource(const QString &uri=QString())
creates a resource and associates it with this model.
Definition model.cpp:80
Syndication::RDF::Model::createSequence
virtual SequencePtr createSequence(const QString &uri=QString())
creates a sequence and associates it with this model.
Definition model.cpp:98
Syndication::RDF::Model::createProperty
virtual PropertyPtr createProperty(const QString &uri)
creates a property and associates it with this model.
Definition model.cpp:55
Syndication::RDF::Model::createLiteral
virtual LiteralPtr createLiteral(const QString &text)
creates a literal and associates it with this model.
Definition model.cpp:123
Syndication::RDF::RDFVocab::self
static RDFVocab * self()
returns the singleton instance
Definition rdfvocab.cpp:51
Syndication::RDF::RDFVocab::namespaceURI
QString namespaceURI()
the RDF namespace, which is http://www.w3.org/1999/02/22-rdf-syntax-ns#
Definition rdfvocab.cpp:92
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

syndication/rdf

Skip menu "syndication/rdf"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal