• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 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/QList>
36 #include <QtCore/QString>
37 
38 namespace Syndication {
39 namespace Atom {
40 
41 Entry::Entry() : ElementWrapper()
42 {
43 }
44 
45 Entry::Entry(const QDomElement& element) : ElementWrapper(element)
46 {
47 }
48 
49 QList<Person> Entry::authors() const
50 {
51  QList<QDomElement> a =
52  elementsByTagNameNS(atom1Namespace(),
53  QLatin1String("author"));
54  QList<Person> list;
55 
56  QList<QDomElement>::ConstIterator it = a.constBegin();
57  QList<QDomElement>::ConstIterator end = a.constEnd();
58 
59 
60  for ( ; it != end; ++it)
61  {
62  list.append(Person(*it));
63  }
64 
65  return list;
66 }
67 
68 QList<Person> Entry::contributors() const
69 {
70  QList<QDomElement> a =
71  elementsByTagNameNS(atom1Namespace(),
72  QLatin1String("contributor"));
73  QList<Person> list;
74 
75  QList<QDomElement>::ConstIterator it = a.constBegin();
76  QList<QDomElement>::ConstIterator end = a.constEnd();
77 
78 
79  for ( ; it != end; ++it)
80  {
81  list.append(Person(*it));
82  }
83 
84  return list;
85 }
86 
87 QList<Category> Entry::categories() const
88 {
89  QList<QDomElement> a =
90  elementsByTagNameNS(atom1Namespace(),
91  QLatin1String("category"));
92  QList<Category> list;
93 
94  QList<QDomElement>::ConstIterator it = a.constBegin();
95  QList<QDomElement>::ConstIterator end = a.constEnd();
96 
97 
98  for ( ; it != end; ++it)
99  {
100  list.append(Category(*it));
101  }
102 
103  return list;
104 }
105 
106 QString Entry::id() const
107 {
108  return extractElementTextNS(atom1Namespace(),
109  QLatin1String("id"));
110 
111 }
112 
113 QList<Link> Entry::links() const
114 {
115  QList<QDomElement> a =
116  elementsByTagNameNS(atom1Namespace(),
117  QLatin1String("link"));
118  QList<Link> list;
119 
120  QList<QDomElement>::ConstIterator it = a.constBegin();
121  QList<QDomElement>::ConstIterator end = a.constEnd();
122 
123 
124  for ( ; it != end; ++it)
125  {
126  list.append(Link(*it));
127  }
128 
129  return list;
130 }
131 
132 QString Entry::rights() const
133 {
134  return extractAtomText(*this, QLatin1String("rights"));
135 }
136 
137 Source Entry::source() const
138 {
139  return Source(firstElementByTagNameNS(atom1Namespace(),
140  QLatin1String("source")));
141 }
142 
143 time_t Entry::published() const
144 {
145  QString pub = extractElementTextNS(atom1Namespace(),
146  QLatin1String("published"));
147  return parseDate(pub, ISODate);
148 }
149 
150 time_t Entry::updated() const
151 {
152  QString upd = extractElementTextNS(atom1Namespace(),
153  QLatin1String("updated"));
154  return parseDate(upd, ISODate);
155 }
156 
157 QString Entry::summary() const
158 {
159  return extractAtomText(*this, QLatin1String("summary"));
160 }
161 
162 QString Entry::title() const
163 {
164  return extractAtomText(*this, QLatin1String("title"));
165 }
166 
167 Content Entry::content() const
168 {
169  return Content(firstElementByTagNameNS(atom1Namespace(),
170  QLatin1String("content")));
171 }
172 
173 QList<QDomElement> Entry::unhandledElements() const
174 {
175  // TODO: do not hardcode this list here
176  QList<ElementType> handled;
177  handled.append(ElementType(QLatin1String("author"), atom1Namespace()));
178  handled.append(ElementType(QLatin1String("contributor"), atom1Namespace()));
179  handled.append(ElementType(QLatin1String("category"), atom1Namespace()));
180  handled.append(ElementType(QLatin1String("id"), atom1Namespace()));
181  handled.append(ElementType(QLatin1String("link"), atom1Namespace()));
182  handled.append(ElementType(QLatin1String("rights"), atom1Namespace()));
183  handled.append(ElementType(QLatin1String("source"), atom1Namespace()));
184  handled.append(ElementType(QLatin1String("published"), atom1Namespace()));
185  handled.append(ElementType(QLatin1String("updated"), atom1Namespace()));
186  handled.append(ElementType(QLatin1String("summary"), atom1Namespace()));
187  handled.append(ElementType(QLatin1String("title"), atom1Namespace()));
188  handled.append(ElementType(QLatin1String("content"), atom1Namespace()));
189 
190  QList<QDomElement> notHandled;
191 
192  QDomNodeList children = element().childNodes();
193  for (int i = 0; i < children.size(); ++i)
194  {
195  QDomElement el = children.at(i).toElement();
196  if (!el.isNull()
197  && !handled.contains(ElementType(el.localName(), el.namespaceURI())))
198  {
199  notHandled.append(el);
200  }
201  }
202 
203  return notHandled;
204 }
205 
206 QString Entry::debugInfo() const
207 {
208  QString info;
209  info += QLatin1String("### Entry: ###################\n");
210  if (!title().isEmpty())
211  info += QLatin1String("title: #") + title() + QLatin1String("#\n");
212  if (!summary().isEmpty())
213  info += QLatin1String("summary: #") + summary() + QLatin1String("#\n");
214  if (!id().isEmpty())
215  info += QLatin1String("id: #") + id() + QLatin1String("#\n");
216  if (!content().isNull())
217  info += content().debugInfo();
218 
219  if (!rights().isEmpty())
220  info += QLatin1String("rights: #") + rights() + QLatin1String("#\n");
221 
222 
223  QString dupdated = dateTimeToString(updated());
224  if (!dupdated.isNull())
225  info += QLatin1String("updated: #") + dupdated + QLatin1String("#\n");
226 
227  QString dpublished = dateTimeToString(published());
228  if (!dpublished.isNull())
229  info += QLatin1String("published: #") + dpublished + QLatin1String("#\n");
230 
231  QList<Link> dlinks = links();
232  QList<Link>::ConstIterator endlinks = dlinks.constEnd();
233  for (QList<Link>::ConstIterator it = dlinks.constBegin(); it != endlinks; ++it)
234  info += (*it).debugInfo();
235 
236  QList<Category> dcats = categories();
237  QList<Category>::ConstIterator endcats = dcats.constEnd();
238  for (QList<Category>::ConstIterator it = dcats.constBegin(); it != endcats; ++it)
239  info += (*it).debugInfo();
240 
241  info += QLatin1String("### Authors: ###################\n");
242 
243  QList<Person> dauthors = authors();
244  QList<Person>::ConstIterator endauthors = dauthors.constEnd();
245  for (QList<Person>::ConstIterator it = dauthors.constBegin(); it != endauthors; ++it)
246  info += (*it).debugInfo();
247 
248  info += QLatin1String("### Contributors: ###################\n");
249 
250  QList<Person> dcontri = contributors();
251  QList<Person>::ConstIterator endcontri = dcontri.constEnd();
252  for (QList<Person>::ConstIterator it = dcontri.constBegin(); it != endcontri; ++it)
253  info += (*it).debugInfo();
254 
255  if (!source().isNull())
256  info += source().debugInfo();
257 
258  info += QLatin1String("### Entry end ################\n");
259 
260  return info;
261 }
262 
263 bool Entry::accept(SpecificItemVisitor* visitor)
264 {
265  return visitor->visitAtomEntry(this);
266 }
267 
268 } // namespace Atom
269 } //namespace Syndication
270 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:26:22 by doxygen 1.8.3.1 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.10.5 API Reference

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