Syndication

atom/source.cpp
1 /*
2  This file is part of the syndication library
3  SPDX-FileCopyrightText: 2006 Frank Osterfeld <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "source.h"
9 #include "atomtools.h"
10 #include "category.h"
11 #include "constants.h"
12 #include "generator.h"
13 #include "link.h"
14 #include "person.h"
15 
16 #include <tools.h>
17 
18 #include <QDomElement>
19 #include <QList>
20 #include <QString>
21 
22 namespace Syndication
23 {
24 namespace Atom
25 {
27  : ElementWrapper()
28 {
29 }
30 
31 Source::Source(const QDomElement &element)
32  : ElementWrapper(element)
33 {
34 }
35 
37 {
38  const QList<QDomElement> a = elementsByTagNameNS(atom1Namespace(), QStringLiteral("author"));
39 
40  QList<Person> list;
41  list.reserve(a.count());
42 
43  std::transform(a.cbegin(), a.cend(), std::back_inserter(list), [](const QDomElement &element) {
44  return Person(element);
45  });
46 
47  return list;
48 }
49 
51 {
52  const QList<QDomElement> a = elementsByTagNameNS(atom1Namespace(), QStringLiteral("contributor"));
53  QList<Person> list;
54  list.reserve(a.count());
55 
56  std::transform(a.cbegin(), a.cend(), std::back_inserter(list), [](const QDomElement &element) {
57  return Person(element);
58  });
59 
60  return list;
61 }
62 
64 {
65  const QList<QDomElement> a = elementsByTagNameNS(atom1Namespace(), QStringLiteral("category"));
66  QList<Category> list;
67  list.reserve(a.count());
68 
69  std::transform(a.cbegin(), a.cend(), std::back_inserter(list), [](const QDomElement &element) {
70  return Category(element);
71  });
72 
73  return list;
74 }
75 
77 {
78  return Generator(firstElementByTagNameNS(atom1Namespace(), QStringLiteral("generator")));
79 }
80 
82 {
83  return extractElementTextNS(atom1Namespace(), QStringLiteral("icon"));
84 }
85 
87 {
88  return extractElementTextNS(atom1Namespace(), QStringLiteral("id"));
89 }
90 
92 {
93  const QList<QDomElement> a = elementsByTagNameNS(atom1Namespace(), QStringLiteral("link"));
94  QList<Link> list;
95  list.reserve(a.count());
96 
97  std::transform(a.cbegin(), a.cend(), std::back_inserter(list), [](const QDomElement &element) {
98  return Link(element);
99  });
100 
101  return list;
102 }
103 
105 {
106  return extractElementTextNS(atom1Namespace(), QStringLiteral("logo"));
107 }
108 
110 {
111  return extractAtomText(*this, QStringLiteral("rights"));
112 }
113 
115 {
116  return extractAtomText(*this, QStringLiteral("subtitle"));
117 }
118 
120 {
121  return extractAtomText(*this, QStringLiteral("title"));
122 }
123 
124 time_t Source::updated() const
125 {
126  const QString upd = extractElementTextNS(atom1Namespace(), QStringLiteral("updated"));
127  return parseDate(upd, ISODate);
128 }
129 
131 {
132  QString info = QLatin1String("### Source: ###################\n");
133  if (!title().isEmpty()) {
134  info += QLatin1String("title: #") + title() + QLatin1String("#\n");
135  }
136  if (!subtitle().isEmpty()) {
137  info += QLatin1String("subtitle: #") + subtitle() + QLatin1String("#\n");
138  }
139  if (!id().isEmpty()) {
140  info += QLatin1String("id: #") + id() + QLatin1String("#\n");
141  }
142 
143  if (!rights().isEmpty()) {
144  info += QLatin1String("rights: #") + rights() + QLatin1String("#\n");
145  }
146  if (!icon().isEmpty()) {
147  info += QLatin1String("icon: #") + icon() + QLatin1String("#\n");
148  }
149  if (!logo().isEmpty()) {
150  info += QLatin1String("logo: #") + logo() + QLatin1String("#\n");
151  }
152  if (!generator().isNull()) {
153  info += generator().debugInfo();
154  }
155 
156  QString dupdated = dateTimeToString(updated());
157  if (!dupdated.isNull()) {
158  info += QLatin1String("updated: #") + dupdated + QLatin1String("#\n");
159  }
160 
161  const QList<Link> dlinks = links();
162  for (const auto &link : dlinks) {
163  info += link.debugInfo();
164  }
165 
166  const QList<Category> dcats = categories();
167  for (const auto &cat : dcats) {
168  info += cat.debugInfo();
169  }
170 
171  info += QLatin1String("### Authors: ###################\n");
172 
173  const QList<Person> dauthors = authors();
174  for (const auto &author : dauthors) {
175  info += author.debugInfo();
176  }
177 
178  info += QLatin1String("### Contributors: ###################\n");
179 
180  const QList<Person> dcontri = contributors();
181  for (const auto &person : dcontri) {
182  info += person.debugInfo();
183  }
184 
185  info += QLatin1String("### Source end ################\n");
186 
187  return info;
188 }
189 
190 } // namespace Atom
191 } // namespace Syndication
QList< Person > contributors() const
contributors to the original content (optional)
Definition: atom/source.cpp:50
bool isNull() const const
QString subtitle() const
description or subtitle of the source feed (optional).
int count(const T &value) const const
A wrapper for XML elements.
QList< Link > links() const
a list of links.
Definition: atom/source.cpp:91
QDomElement firstElementByTagNameNS(const QString &nsURI, const QString &tagName) const
searches the direct children of the wrapped element for an element with a given namespace and tag nam...
void reserve(int alloc)
QList< Category > categories() const
categories the source feed is assigned to (optional)
Definition: atom/source.cpp:63
QList< QDomElement > elementsByTagNameNS(const QString &nsURI, const QString &tagName) const
returns all child elements with tag name tagname and namespace URI nsURI.
QString debugInfo() const
a description of this generator for debugging purposes.
Definition: generator.cpp:42
QString extractElementTextNS(const QString &namespaceURI, const QString &localName) const
extracts the text from a child element, respecting namespaces.
bool isNull() const
returns whether the wrapped element is a null element
Description of the agent used to generate the feed.
Definition: generator.h:25
QList::const_iterator cend() const const
QString atom1Namespace()
namespace used by Atom 1.0 elements
KCALUTILS_EXPORT QString dateTimeToString(const QDateTime &date, bool dateOnly=false, bool shortfmt=true)
QList< Person > authors() const
authors of the original content (optional)
Definition: atom/source.cpp:36
QString extractAtomText(const Syndication::ElementWrapper &parent, const QString &tagname)
extracts the content of an atomTextConstruct.
Definition: atomtools.cpp:21
QString title() const
source feed title (optional).
QString rights() const
copyright information (optional)
QString icon() const
URL of an image serving as a feed icon (optional)
Definition: atom/source.cpp:81
QList::const_iterator cbegin() const const
QString id() const
a string that unambiguously identifies the source feed (optional)
Definition: atom/source.cpp:86
Generator generator() const
description of the software which generated the source feed (optional)
Definition: atom/source.cpp:76
Source()
creates a null source object
Definition: atom/source.cpp:26
QString logo() const
URL of an image, the logo of the source feed (optional)
const QDomElement & element() const
returns the wrapped resource.
time_t updated() const
The datetime of the last modification of the source feed content.
QString debugInfo() const
description of this source object for debugging purposes
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 15 2022 04:03:41 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.