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

syndication/atom

  • syndication
  • atom
entry.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#include "entry.h"
23#include "category.h"
24#include "constants.h"
25#include "content.h"
26#include "link.h"
27#include "person.h"
28#include "source.h"
29#include "atomtools.h"
30
31#include <specificitemvisitor.h>
32#include <tools.h>
33
34#include <QtXml/QDomElement>
35#include <QtCore/QString>
36
37namespace Syndication {
38namespace Atom {
39
40Entry::Entry() : ElementWrapper()
41{
42}
43
44Entry::Entry(const QDomElement& element) : ElementWrapper(element)
45{
46}
47
48void Entry::setFeedAuthors(const QList<Person>& feedAuthors)
49{
50 m_feedAuthors = feedAuthors;
51}
52
53QList<Person> Entry::authors() const
54{
55 QList<QDomElement> a =
56 elementsByTagNameNS(atom1Namespace(),
57 QLatin1String("author"));
58 QList<Person> list;
59
60 if (!a.isEmpty())
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 else
72 {
73 list = source().authors();
74 }
75
76 if (!list.isEmpty())
77 return list;
78
79 return m_feedAuthors;
80}
81
82QList<Person> Entry::contributors() const
83{
84 QList<QDomElement> a =
85 elementsByTagNameNS(atom1Namespace(),
86 QLatin1String("contributor"));
87 QList<Person> list;
88
89 QList<QDomElement>::ConstIterator it = a.constBegin();
90 QList<QDomElement>::ConstIterator end = a.constEnd();
91
92
93 for ( ; it != end; ++it)
94 {
95 list.append(Person(*it));
96 }
97
98 return list;
99}
100
101QList<Category> Entry::categories() const
102{
103 QList<QDomElement> a =
104 elementsByTagNameNS(atom1Namespace(),
105 QLatin1String("category"));
106 QList<Category> list;
107
108 QList<QDomElement>::ConstIterator it = a.constBegin();
109 QList<QDomElement>::ConstIterator end = a.constEnd();
110
111
112 for ( ; it != end; ++it)
113 {
114 list.append(Category(*it));
115 }
116
117 return list;
118}
119
120QString Entry::id() const
121{
122 return extractElementTextNS(atom1Namespace(),
123 QLatin1String("id"));
124
125}
126
127QList<Link> Entry::links() const
128{
129 QList<QDomElement> a =
130 elementsByTagNameNS(atom1Namespace(),
131 QLatin1String("link"));
132 QList<Link> list;
133
134 QList<QDomElement>::ConstIterator it = a.constBegin();
135 QList<QDomElement>::ConstIterator end = a.constEnd();
136
137
138 for ( ; it != end; ++it)
139 {
140 list.append(Link(*it));
141 }
142
143 return list;
144}
145
146QString Entry::rights() const
147{
148 return extractAtomText(*this, QLatin1String("rights"));
149}
150
151Source Entry::source() const
152{
153 return Source(firstElementByTagNameNS(atom1Namespace(),
154 QLatin1String("source")));
155}
156
157time_t Entry::published() const
158{
159 QString pub = extractElementTextNS(atom1Namespace(),
160 QLatin1String("published"));
161 return parseDate(pub, ISODate);
162}
163
164time_t Entry::updated() const
165{
166 QString upd = extractElementTextNS(atom1Namespace(),
167 QLatin1String("updated"));
168 return parseDate(upd, ISODate);
169}
170
171QString Entry::summary() const
172{
173 return extractAtomText(*this, QLatin1String("summary"));
174}
175
176QString Entry::title() const
177{
178 return extractAtomText(*this, QLatin1String("title"));
179}
180
181Content Entry::content() const
182{
183 return Content(firstElementByTagNameNS(atom1Namespace(),
184 QLatin1String("content")));
185}
186
187QList<QDomElement> Entry::unhandledElements() const
188{
189 // TODO: do not hardcode this list here
190 QList<ElementType> handled;
191 handled.append(ElementType(QLatin1String("author"), atom1Namespace()));
192 handled.append(ElementType(QLatin1String("contributor"), atom1Namespace()));
193 handled.append(ElementType(QLatin1String("category"), atom1Namespace()));
194 handled.append(ElementType(QLatin1String("id"), atom1Namespace()));
195 handled.append(ElementType(QLatin1String("link"), atom1Namespace()));
196 handled.append(ElementType(QLatin1String("rights"), atom1Namespace()));
197 handled.append(ElementType(QLatin1String("source"), atom1Namespace()));
198 handled.append(ElementType(QLatin1String("published"), atom1Namespace()));
199 handled.append(ElementType(QLatin1String("updated"), atom1Namespace()));
200 handled.append(ElementType(QLatin1String("summary"), atom1Namespace()));
201 handled.append(ElementType(QLatin1String("title"), atom1Namespace()));
202 handled.append(ElementType(QLatin1String("content"), atom1Namespace()));
203
204 QList<QDomElement> notHandled;
205
206 QDomNodeList children = element().childNodes();
207 for (int i = 0; i < children.size(); ++i)
208 {
209 QDomElement el = children.at(i).toElement();
210 if (!el.isNull()
211 && !handled.contains(ElementType(el.localName(), el.namespaceURI())))
212 {
213 notHandled.append(el);
214 }
215 }
216
217 return notHandled;
218}
219
220QString Entry::debugInfo() const
221{
222 QString info;
223 info += QLatin1String("### Entry: ###################\n");
224 if (!title().isEmpty())
225 info += QLatin1String("title: #") + title() + QLatin1String("#\n");
226 if (!summary().isEmpty())
227 info += QLatin1String("summary: #") + summary() + QLatin1String("#\n");
228 if (!id().isEmpty())
229 info += QLatin1String("id: #") + id() + QLatin1String("#\n");
230 if (!content().isNull())
231 info += content().debugInfo();
232
233 if (!rights().isEmpty())
234 info += QLatin1String("rights: #") + rights() + QLatin1String("#\n");
235
236
237 QString dupdated = dateTimeToString(updated());
238 if (!dupdated.isNull())
239 info += QLatin1String("updated: #") + dupdated + QLatin1String("#\n");
240
241 QString dpublished = dateTimeToString(published());
242 if (!dpublished.isNull())
243 info += QLatin1String("published: #") + dpublished + QLatin1String("#\n");
244
245 QList<Link> dlinks = links();
246 QList<Link>::ConstIterator endlinks = dlinks.constEnd();
247 for (QList<Link>::ConstIterator it = dlinks.constBegin(); it != endlinks; ++it)
248 info += (*it).debugInfo();
249
250 QList<Category> dcats = categories();
251 QList<Category>::ConstIterator endcats = dcats.constEnd();
252 for (QList<Category>::ConstIterator it = dcats.constBegin(); it != endcats; ++it)
253 info += (*it).debugInfo();
254
255 info += QLatin1String("### Authors: ###################\n");
256
257 QList<Person> dauthors = authors();
258 QList<Person>::ConstIterator endauthors = dauthors.constEnd();
259 for (QList<Person>::ConstIterator it = dauthors.constBegin(); it != endauthors; ++it)
260 info += (*it).debugInfo();
261
262 info += QLatin1String("### Contributors: ###################\n");
263
264 QList<Person> dcontri = contributors();
265 QList<Person>::ConstIterator endcontri = dcontri.constEnd();
266 for (QList<Person>::ConstIterator it = dcontri.constBegin(); it != endcontri; ++it)
267 info += (*it).debugInfo();
268
269 if (!source().isNull())
270 info += source().debugInfo();
271
272 info += QLatin1String("### Entry end ################\n");
273
274 return info;
275}
276
277bool Entry::accept(SpecificItemVisitor* visitor)
278{
279 return visitor->visitAtomEntry(this);
280}
281
282} // namespace Atom
283} //namespace Syndication
284
Syndication::Atom::Category
A category for categorizing items or whole feeds.
Definition category.h:46
Syndication::Atom::Content
The content element either contains or links the content of an entry.
Definition content.h:47
Syndication::Atom::Content::debugInfo
QString debugInfo() const
returns a description of the content object for debugging purposes
Definition content.cpp:185
Syndication::Atom::Entry::contributors
QList< Person > contributors() const
list of persons contributing to this entry (optional)
Definition entry.cpp:82
Syndication::Atom::Entry::rights
QString rights() const
copyright information (optional)
Definition entry.cpp:146
Syndication::Atom::Entry::published
time_t published() const
The datetime of the publication of this entry (optional).
Definition entry.cpp:157
Syndication::Atom::Entry::title
QString title() const
title of the entry (required).
Definition entry.cpp:176
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
Syndication::Atom::Entry::content
Content content() const
content of the entry (optional) See Content for details
Definition entry.cpp:181
Syndication::Atom::Entry::Entry
Entry()
creates a null entry object
Definition entry.cpp:40
Syndication::Atom::Entry::unhandledElements
QList< QDomElement > unhandledElements() const
returns all child elements of this entry not covered by this class.
Definition entry.cpp:187
Syndication::Atom::Entry::source
Source source() const
source description of the content (optional)
Definition entry.cpp:151
Syndication::Atom::Entry::debugInfo
QString debugInfo() const
returns a description of this entry for debugging purposes
Definition entry.cpp:220
Syndication::Atom::Entry::accept
bool accept(SpecificItemVisitor *visitor)
Used by visitors for double dispatch.
Definition entry.cpp:277
Syndication::Atom::Entry::authors
QList< Person > authors() const
list of persons who are authors of this entry.
Definition entry.cpp:53
Syndication::Atom::Entry::updated
time_t updated() const
The datetime of the last modification of this entry (required).
Definition entry.cpp:164
Syndication::Atom::Entry::summary
QString summary() const
a short summary, abstract or excerpt of an entry.
Definition entry.cpp:171
Syndication::Atom::Entry::id
QString id() const
ID of the article.
Definition entry.cpp:120
Syndication::Atom::Entry::categories
QList< Category > categories() const
a list of categories this entry is filed to (optional)
Definition entry.cpp:101
Syndication::Atom::Entry::links
QList< Link > links() const
links pointing to associated web sites and other resources.
Definition entry.cpp:127
Syndication::Atom::Link
A link, pointing to webpages, media files on the web ("podcast"), related content,...
Definition link.h:40
Syndication::Atom::Person
describes a person, with name and optional URI and e-mail address.
Definition person.h:41
Syndication::Atom::Source
If an entry was copied from another feed, this class contains a description of the source feed.
Definition source.h:50
Syndication::Atom::Source::authors
QList< Person > authors() const
authors of the original content (optional)
Definition source.cpp:48
Syndication::Atom::Source::debugInfo
QString debugInfo() const
description of this source object for debugging purposes
Definition source.cpp:170
Syndication::Atom::atom1Namespace
QString atom1Namespace()
namespace used by Atom 1.0 elements
Definition constants.cpp:30
Syndication::Atom::extractAtomText
QString extractAtomText(const Syndication::ElementWrapper &parent, const QString &tagname)
extracts the content of an atomTextConstruct.
Definition atomtools.cpp:35
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/atom

Skip menu "syndication/atom"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • 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