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

syndication/atom

  • 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<QDomElement>::ConstIterator it = a.constBegin();
187  QList<QDomElement>::ConstIterator end = a.constEnd();
188 
189 
190  for ( ; it != end; ++it)
191  {
192  list.append(Entry(*it));
193  }
194 
195  return list;
196 }
197 
198 QList<QDomElement> FeedDocument::unhandledElements() const
199 {
200  // TODO: do not hardcode this list here
201  QList<ElementType> handled;
202  handled.append(ElementType(QLatin1String("author"), atom1Namespace()));
203  handled.append(ElementType(QLatin1String("contributor"), atom1Namespace()));
204  handled.append(ElementType(QLatin1String("category"), atom1Namespace()));
205  handled.append(ElementType(QLatin1String("generator"), atom1Namespace()));
206  handled.append(ElementType(QLatin1String("icon"), atom1Namespace()));
207  handled.append(ElementType(QLatin1String("logo"), atom1Namespace()));
208  handled.append(ElementType(QLatin1String("id"), atom1Namespace()));
209  handled.append(ElementType(QLatin1String("rights"), atom1Namespace()));
210  handled.append(ElementType(QLatin1String("title"), atom1Namespace()));
211  handled.append(ElementType(QLatin1String("subtitle"), atom1Namespace()));
212  handled.append(ElementType(QLatin1String("updated"), atom1Namespace()));
213  handled.append(ElementType(QLatin1String("link"), atom1Namespace()));
214  handled.append(ElementType(QLatin1String("entry"), atom1Namespace()));
215 
216  QList<QDomElement> notHandled;
217 
218  QDomNodeList children = element().childNodes();
219  for (int i = 0; i < children.size(); ++i)
220  {
221  QDomElement el = children.at(i).toElement();
222  if (!el.isNull()
223  && !handled.contains(ElementType(el.localName(), el.namespaceURI())))
224  {
225  notHandled.append(el);
226  }
227  }
228 
229  return notHandled;
230 }
231 
232 bool FeedDocument::isValid() const
233 {
234  return !isNull();
235 }
236 
237 QString FeedDocument::debugInfo() const
238 {
239  QString info;
240  info += QLatin1String("### FeedDocument: ###################\n");
241  if (!title().isEmpty())
242  info += QLatin1String("title: #") + title() + QLatin1String("#\n");
243  if (!subtitle().isEmpty())
244  info += QLatin1String("subtitle: #") + subtitle() + QLatin1String("#\n");
245  if (!id().isEmpty())
246  info += QLatin1String("id: #") + id() + QLatin1String("#\n");
247 
248  if (!rights().isEmpty())
249  info += QLatin1String("rights: #") + rights() + QLatin1String("#\n");
250  if (!icon().isEmpty())
251  info += QLatin1String("icon: #") + icon() + QLatin1String("#\n");
252  if (!logo().isEmpty())
253  info += QLatin1String("logo: #") + logo() + QLatin1String("#\n");
254  if (!generator().isNull())
255  info += generator().debugInfo();
256 
257 
258  QString dupdated = dateTimeToString(updated());
259  if (!dupdated.isNull())
260  info += QLatin1String("updated: #") + dupdated + QLatin1String("#\n");
261 
262  QList<Link> dlinks = links();
263  QList<Link>::ConstIterator endlinks = dlinks.constEnd();
264  for (QList<Link>::ConstIterator it = dlinks.constBegin(); it != endlinks; ++it)
265  info += (*it).debugInfo();
266 
267  QList<Category> dcats = categories();
268  QList<Category>::ConstIterator endcats = dcats.constEnd();
269  for (QList<Category>::ConstIterator it = dcats.constBegin(); it != endcats; ++it)
270  info += (*it).debugInfo();
271 
272  info += QLatin1String("### Authors: ###################\n");
273 
274  QList<Person> dauthors = authors();
275  QList<Person>::ConstIterator endauthors = dauthors.constEnd();
276  for (QList<Person>::ConstIterator it = dauthors.constBegin(); it != endauthors; ++it)
277  info += (*it).debugInfo();
278 
279  info += QLatin1String("### Contributors: ###################\n");
280 
281  QList<Person> dcontri = contributors();
282  QList<Person>::ConstIterator endcontri = dcontri.constEnd();
283  for (QList<Person>::ConstIterator it = dcontri.constBegin(); it != endcontri; ++it)
284  info += (*it).debugInfo();
285 
286  QList<Entry> dentries = entries();
287  QList<Entry>::ConstIterator endentries = dentries.constEnd();
288  for (QList<Entry>::ConstIterator it = dentries.constBegin(); it != endentries; ++it)
289  info += (*it).debugInfo();
290 
291  info += QLatin1String("### FeedDocument end ################\n");
292 
293  return info;
294 }
295 
296 EntryDocument::EntryDocument() : ElementWrapper()
297 {
298 }
299 
300 EntryDocument::EntryDocument(const QDomElement& element) : ElementWrapper(element)
301 {
302 }
303 
304 bool EntryDocument::accept(DocumentVisitor* visitor)
305 {
306  return visitor->visitAtomEntryDocument(this);
307 }
308 
309 Entry EntryDocument::entry() const
310 {
311  return Entry(element());
312 }
313 
314 
315 bool EntryDocument::isValid() const
316 {
317  return !isNull();
318 }
319 
320 QString EntryDocument::debugInfo() const
321 {
322  QString info;
323  info += QLatin1String("### EntryDocument: ##################\n");
324 
325  Entry dentry = entry();
326  if (!dentry.isNull())
327  info += dentry.debugInfo();
328 
329  info += QLatin1String("### EntryDocument end ###############\n");
330  return info;
331 }
332 
333 } // namespace Atom
334 } // 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 (&quot;podcast&quot;), 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
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
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
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:296
Syndication::Atom::EntryDocument::accept
bool accept(DocumentVisitor *visitor)
Used by visitors for double dispatch.
Definition: document.cpp:304
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:198
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
Syndication::Atom::EntryDocument::isValid
bool isValid() const
returns whether this document is valid or not.
Definition: document.cpp:315
Syndication::Atom::Entry
an Atom entry, equivalent to the &quot;items&quot; in the RSS world.
Definition: entry.h:52
Syndication::Atom::FeedDocument::debugInfo
QString debugInfo() const
returns a description of this feed document for debugging purposes.
Definition: document.cpp:237
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:206
Syndication::Atom::FeedDocument::generator
Generator generator() const
description of the agent used to generate the feed.
Definition: document.cpp:112
Syndication::Atom::EntryDocument::entry
Entry entry() const
returns the single entry described in the source.
Definition: document.cpp:309
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:232
Syndication::Atom::FeedDocument::updated
time_t updated() const
The datetime of the last modification of the feed content.
Definition: document.cpp:153
Syndication::Atom::EntryDocument::debugInfo
QString debugInfo() const
returns a description of this entry document for debugging purposes.
Definition: document.cpp:320
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:02:42 by doxygen 1.8.5 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-4.11.3 API Reference

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