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

syndication/atom

  • sources
  • kde-4.14
  • kdepimlibs
  • syndication
  • atom
document.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 "document.h"
24 #include "category.h"
25 #include "constants.h"
26 #include "entry.h"
27 #include "generator.h"
28 #include "link.h"
29 #include "person.h"
30 #include "atomtools.h"
31 
32 #include <documentvisitor.h>
33 #include <tools.h>
34 
35 #include <QtXml/QDomElement>
36 #include <QtCore/QList>
37 #include <QtCore/QString>
38 
39 namespace Syndication {
40 namespace Atom {
41 
42 FeedDocument::FeedDocument() : ElementWrapper()
43 {
44 }
45 
46 FeedDocument::FeedDocument(const QDomElement& element) : ElementWrapper(element)
47 {
48 }
49 
50 bool FeedDocument::accept(DocumentVisitor* visitor)
51 {
52  return visitor->visitAtomFeedDocument(this);
53 }
54 
55 QList<Person> FeedDocument::authors() const
56 {
57  QList<QDomElement> a =
58  elementsByTagNameNS(atom1Namespace(),
59  QLatin1String("author"));
60  QList<Person> list;
61 
62  QList<QDomElement>::ConstIterator it = a.constBegin();
63  QList<QDomElement>::ConstIterator end = a.constEnd();
64 
65 
66  for ( ; it != end; ++it)
67  {
68  list.append(Person(*it));
69  }
70 
71  return list;
72 }
73 
74 QList<Person> FeedDocument::contributors() const
75 {
76  QList<QDomElement> a =
77  elementsByTagNameNS(atom1Namespace(),
78  QLatin1String("contributor"));
79  QList<Person> list;
80 
81  QList<QDomElement>::ConstIterator it = a.constBegin();
82  QList<QDomElement>::ConstIterator end = a.constEnd();
83 
84 
85  for ( ; it != end; ++it)
86  {
87  list.append(Person(*it));
88  }
89 
90  return list;
91 }
92 
93 QList<Category> FeedDocument::categories() const
94 {
95  QList<QDomElement> a =
96  elementsByTagNameNS(atom1Namespace(),
97  QLatin1String("category"));
98  QList<Category> list;
99 
100  QList<QDomElement>::ConstIterator it = a.constBegin();
101  QList<QDomElement>::ConstIterator end = a.constEnd();
102 
103 
104  for ( ; it != end; ++it)
105  {
106  list.append(Category(*it));
107  }
108 
109  return list;
110 }
111 
112 Generator FeedDocument::generator() const
113 {
114  return Generator(firstElementByTagNameNS(atom1Namespace(),
115  QLatin1String("generator")));
116 }
117 
118 QString FeedDocument::icon() const
119 {
120  return completeURI(extractElementTextNS(atom1Namespace(),
121  QLatin1String("icon")));
122 
123 }
124 
125 QString FeedDocument::logo() const
126 {
127  return completeURI(extractElementTextNS(atom1Namespace(),
128  QLatin1String("logo")));
129 }
130 
131 QString FeedDocument::id() const
132 {
133  return extractElementTextNS(atom1Namespace(),
134  QLatin1String("id"));
135 }
136 
137 QString FeedDocument::rights() const
138 {
139 
140  return extractAtomText(*this, QLatin1String("rights"));
141 }
142 
143 QString FeedDocument::title() const
144 {
145  return extractAtomText(*this, QLatin1String("title"));
146 }
147 
148 QString FeedDocument::subtitle() const
149 {
150  return extractAtomText(*this, QLatin1String("subtitle"));
151 }
152 
153 time_t FeedDocument::updated() const
154 {
155  QString upd = extractElementTextNS(atom1Namespace(),
156  QLatin1String("updated"));
157  return parseDate(upd, ISODate);
158 }
159 
160 QList<Link> FeedDocument::links() const
161 {
162  QList<QDomElement> a =
163  elementsByTagNameNS(atom1Namespace(),
164  QLatin1String("link"));
165  QList<Link> list;
166 
167  QList<QDomElement>::ConstIterator it = a.constBegin();
168  QList<QDomElement>::ConstIterator end = a.constEnd();
169 
170 
171  for ( ; it != end; ++it)
172  {
173  list.append(Link(*it));
174  }
175 
176  return list;
177 }
178 
179 QList<Entry> FeedDocument::entries() const
180 {
181  QList<QDomElement> a =
182  elementsByTagNameNS(atom1Namespace(),
183  QLatin1String("entry"));
184  QList<Entry> list;
185 
186  QList<Person> feedAuthors = authors();
187  QList<QDomElement>::ConstIterator it = a.constBegin();
188  QList<QDomElement>::ConstIterator end = a.constEnd();
189 
190 
191  for ( ; it != end; ++it)
192  {
193  Entry entry(*it);
194  entry.setFeedAuthors(feedAuthors);
195  list.append(entry);
196  }
197 
198  return list;
199 }
200 
201 QList<QDomElement> FeedDocument::unhandledElements() const
202 {
203  // TODO: do not hardcode this list here
204  QList<ElementType> handled;
205  handled.append(ElementType(QLatin1String("author"), atom1Namespace()));
206  handled.append(ElementType(QLatin1String("contributor"), atom1Namespace()));
207  handled.append(ElementType(QLatin1String("category"), atom1Namespace()));
208  handled.append(ElementType(QLatin1String("generator"), atom1Namespace()));
209  handled.append(ElementType(QLatin1String("icon"), atom1Namespace()));
210  handled.append(ElementType(QLatin1String("logo"), atom1Namespace()));
211  handled.append(ElementType(QLatin1String("id"), atom1Namespace()));
212  handled.append(ElementType(QLatin1String("rights"), atom1Namespace()));
213  handled.append(ElementType(QLatin1String("title"), atom1Namespace()));
214  handled.append(ElementType(QLatin1String("subtitle"), atom1Namespace()));
215  handled.append(ElementType(QLatin1String("updated"), atom1Namespace()));
216  handled.append(ElementType(QLatin1String("link"), atom1Namespace()));
217  handled.append(ElementType(QLatin1String("entry"), atom1Namespace()));
218 
219  QList<QDomElement> notHandled;
220 
221  QDomNodeList children = element().childNodes();
222  for (int i = 0; i < children.size(); ++i)
223  {
224  QDomElement el = children.at(i).toElement();
225  if (!el.isNull()
226  && !handled.contains(ElementType(el.localName(), el.namespaceURI())))
227  {
228  notHandled.append(el);
229  }
230  }
231 
232  return notHandled;
233 }
234 
235 bool FeedDocument::isValid() const
236 {
237  return !isNull();
238 }
239 
240 QString FeedDocument::debugInfo() const
241 {
242  QString info;
243  info += QLatin1String("### FeedDocument: ###################\n");
244  if (!title().isEmpty())
245  info += QLatin1String("title: #") + title() + QLatin1String("#\n");
246  if (!subtitle().isEmpty())
247  info += QLatin1String("subtitle: #") + subtitle() + QLatin1String("#\n");
248  if (!id().isEmpty())
249  info += QLatin1String("id: #") + id() + QLatin1String("#\n");
250 
251  if (!rights().isEmpty())
252  info += QLatin1String("rights: #") + rights() + QLatin1String("#\n");
253  if (!icon().isEmpty())
254  info += QLatin1String("icon: #") + icon() + QLatin1String("#\n");
255  if (!logo().isEmpty())
256  info += QLatin1String("logo: #") + logo() + QLatin1String("#\n");
257  if (!generator().isNull())
258  info += generator().debugInfo();
259 
260 
261  QString dupdated = dateTimeToString(updated());
262  if (!dupdated.isNull())
263  info += QLatin1String("updated: #") + dupdated + QLatin1String("#\n");
264 
265  QList<Link> dlinks = links();
266  QList<Link>::ConstIterator endlinks = dlinks.constEnd();
267  for (QList<Link>::ConstIterator it = dlinks.constBegin(); it != endlinks; ++it)
268  info += (*it).debugInfo();
269 
270  QList<Category> dcats = categories();
271  QList<Category>::ConstIterator endcats = dcats.constEnd();
272  for (QList<Category>::ConstIterator it = dcats.constBegin(); it != endcats; ++it)
273  info += (*it).debugInfo();
274 
275  info += QLatin1String("### Authors: ###################\n");
276 
277  QList<Person> dauthors = authors();
278  QList<Person>::ConstIterator endauthors = dauthors.constEnd();
279  for (QList<Person>::ConstIterator it = dauthors.constBegin(); it != endauthors; ++it)
280  info += (*it).debugInfo();
281 
282  info += QLatin1String("### Contributors: ###################\n");
283 
284  QList<Person> dcontri = contributors();
285  QList<Person>::ConstIterator endcontri = dcontri.constEnd();
286  for (QList<Person>::ConstIterator it = dcontri.constBegin(); it != endcontri; ++it)
287  info += (*it).debugInfo();
288 
289  QList<Entry> dentries = entries();
290  QList<Entry>::ConstIterator endentries = dentries.constEnd();
291  for (QList<Entry>::ConstIterator it = dentries.constBegin(); it != endentries; ++it)
292  info += (*it).debugInfo();
293 
294  info += QLatin1String("### FeedDocument end ################\n");
295 
296  return info;
297 }
298 
299 EntryDocument::EntryDocument() : ElementWrapper()
300 {
301 }
302 
303 EntryDocument::EntryDocument(const QDomElement& element) : ElementWrapper(element)
304 {
305 }
306 
307 bool EntryDocument::accept(DocumentVisitor* visitor)
308 {
309  return visitor->visitAtomEntryDocument(this);
310 }
311 
312 Entry EntryDocument::entry() const
313 {
314  return Entry(element());
315 }
316 
317 
318 bool EntryDocument::isValid() const
319 {
320  return !isNull();
321 }
322 
323 QString EntryDocument::debugInfo() const
324 {
325  QString info;
326  info += QLatin1String("### EntryDocument: ##################\n");
327 
328  Entry dentry = entry();
329  if (!dentry.isNull())
330  info += dentry.debugInfo();
331 
332  info += QLatin1String("### EntryDocument end ###############\n");
333  return info;
334 }
335 
336 } // namespace Atom
337 } // namespace Syndication
Syndication::Atom::Category
A category for categorizing items or whole feeds.
Definition: category.h:45
Syndication::Atom::Link
A link, pointing to webpages, media files on the web ("podcast"), related content, etc.
Definition: link.h:39
Syndication::Atom::Generator
Description of the agent used to generate the feed.
Definition: generator.h:39
Syndication::Atom::FeedDocument::rights
QString rights() const
copyright information (optional)
Definition: document.cpp:137
Syndication::Atom::FeedDocument::authors
QList< Person > authors() const
a list of persons who are the authors of this feed.
Definition: document.cpp:55
Syndication::Atom::FeedDocument::categories
QList< Category > categories() const
a list of categories this feed is assigned to (optional)
Definition: document.cpp:93
QDomNodeList
QDomNode::namespaceURI
QString namespaceURI() const
Syndication::Atom::FeedDocument::links
QList< Link > links() const
a list of links.
Definition: document.cpp:160
Syndication::Atom::Generator::debugInfo
QString debugInfo() const
a description of this generator for debugging purposes.
Definition: generator.cpp:54
QString::isNull
bool isNull() const
QDomNode::toElement
QDomElement toElement() const
Syndication::Atom::FeedDocument::title
QString title() const
feed title (required).
Definition: document.cpp:143
Syndication::Atom::atom1Namespace
QString atom1Namespace()
namespace used by Atom 1.0 elements
Definition: constants.cpp:30
QList::append
void append(const T &value)
QDomNode::localName
QString localName() const
Syndication::Atom::FeedDocument::FeedDocument
FeedDocument()
default constructor, creates a null feed, which is invalid.
Definition: document.cpp:42
Syndication::Atom::FeedDocument::entries
QList< Entry > entries() const
a list of the entries (items) in this feed.
Definition: document.cpp:179
Syndication::Atom::EntryDocument::EntryDocument
EntryDocument()
default constructor, creates a null document, which is invalid.
Definition: document.cpp:299
Syndication::Atom::EntryDocument::accept
bool accept(DocumentVisitor *visitor)
Used by visitors for double dispatch.
Definition: document.cpp:307
Syndication::Atom::Entry::setFeedAuthors
void setFeedAuthors(const QList< Person > &feedAuthors)
Sets the list of the containing feed's authors, which will be used as a fallback in authors() in case...
Definition: entry.cpp:48
QString
QList
Definition: document.h:31
Syndication::Atom::FeedDocument::logo
QString logo() const
URL of an image serving as a feed logo (optional)
Definition: document.cpp:125
Syndication::Atom::FeedDocument::unhandledElements
QList< QDomElement > unhandledElements() const
returns all child elements of this feed not covered by this class.
Definition: document.cpp:201
Syndication::Atom::extractAtomText
QString extractAtomText(const Syndication::ElementWrapper &parent, const QString &tagname)
extracts the content of an atomTextConstruct.
Definition: atomtools.cpp:35
Syndication::Atom::FeedDocument::icon
QString icon() const
URL of an image serving as a feed icon (optional)
Definition: document.cpp:118
QList::contains
bool contains(const T &value) const
QDomNode::isNull
bool isNull() const
Syndication::Atom::EntryDocument::isValid
bool isValid() const
returns whether this document is valid or not.
Definition: document.cpp:318
Syndication::Atom::Entry
an Atom entry, equivalent to the "items" in the RSS world.
Definition: entry.h:53
QLatin1String
Syndication::Atom::FeedDocument::debugInfo
QString debugInfo() const
returns a description of this feed document for debugging purposes.
Definition: document.cpp:240
Syndication::Atom::FeedDocument::subtitle
QString subtitle() const
description or subtitle of the feed (optional).
Definition: document.cpp:148
Syndication::Atom::FeedDocument::id
QString id() const
a string that unambigously identifies the feed (required)
Definition: document.cpp:131
Syndication::Atom::Person
describes a person, with name and optional URI and e-mail address.
Definition: person.h:40
Syndication::Atom::FeedDocument::accept
bool accept(DocumentVisitor *visitor)
Used by visitors for double dispatch.
Definition: document.cpp:50
Syndication::Atom::Entry::debugInfo
QString debugInfo() const
returns a description of this entry for debugging purposes
Definition: entry.cpp:220
QDomNodeList::size
int size() const
QList::constEnd
const_iterator constEnd() const
Syndication::Atom::FeedDocument::generator
Generator generator() const
description of the agent used to generate the feed.
Definition: document.cpp:112
QList::constBegin
const_iterator constBegin() const
Syndication::Atom::EntryDocument::entry
Entry entry() const
returns the single entry described in the source.
Definition: document.cpp:312
Syndication::Atom::FeedDocument::contributors
QList< Person > contributors() const
a list of persons who contribute to this feed.
Definition: document.cpp:74
Syndication::Atom::FeedDocument::isValid
bool isValid() const
returns whether this document is valid or not.
Definition: document.cpp:235
QDomElement
Syndication::Atom::FeedDocument::updated
time_t updated() const
The datetime of the last modification of the feed content.
Definition: document.cpp:153
QDomNodeList::at
QDomNode at(int index) const
Syndication::Atom::EntryDocument::debugInfo
QString debugInfo() const
returns a description of this entry document for debugging purposes.
Definition: document.cpp:323
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:35 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

syndication/atom

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

kdepimlibs API Reference

Skip menu "kdepimlibs 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

Search



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