Syndication

itematomimpl.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 "itematomimpl.h"
9 #include "categoryatomimpl.h"
10 #include "enclosureatomimpl.h"
11 
12 #include <atom/category.h>
13 #include <atom/content.h>
14 #include <atom/link.h>
15 #include <atom/person.h>
16 #include <category.h>
17 #include <constants.h>
18 #include <enclosure.h>
19 #include <personimpl.h>
20 #include <tools.h>
21 
22 #include <QDomElement>
23 #include <QList>
24 #include <QMultiMap>
25 #include <QString>
26 
30 
31 namespace Syndication
32 {
33 ItemAtomImpl::ItemAtomImpl(const Syndication::Atom::Entry &entry)
34  : m_entry(entry)
35 {
36 }
37 
39 {
40  return m_entry.title();
41 }
42 
44 {
45  QList<Syndication::Atom::Link> links = m_entry.links();
48 
49  // return first link where rel="alternate"
50  for (; it != end; ++it) {
51  if ((*it).rel() == QLatin1String("alternate")) {
52  return (*it).href();
53  }
54  }
55 
56  return QString();
57 }
58 
60 {
61  return m_entry.summary();
62 }
63 
65 {
66  Content content = m_entry.content();
67  if (content.isNull()) {
68  return QString();
69  }
70 
71  return content.asString();
72 }
73 
75 {
76  QList<Syndication::Atom::Person> atomps = m_entry.authors();
77  QList<Syndication::Atom::Person> contributorAtoms = m_entry.contributors();
80 
81  QList<PersonPtr> list;
82  list.reserve(atomps.count() + contributorAtoms.count());
83 
84  for (; it != end; ++it) {
85  PersonImplPtr ptr(new PersonImpl((*it).name(), (*it).uri(), (*it).email()));
86  list.append(ptr);
87  }
88 
89  it = contributorAtoms.constBegin();
90  end = contributorAtoms.constEnd();
91 
92  for (; it != end; ++it) {
93  PersonImplPtr ptr(new PersonImpl((*it).name(), (*it).uri(), (*it).email()));
94  list.append(ptr);
95  }
96 
97  return list;
98 }
99 
101 {
102  time_t pub = m_entry.published();
103  if (pub == 0) {
104  return m_entry.updated();
105  } else {
106  return pub;
107  }
108 }
109 
111 {
112  time_t upd = m_entry.updated();
113  if (upd == 0) {
114  return m_entry.published();
115  } else {
116  return upd;
117  }
118 }
119 
121 {
122  return m_entry.xmlLang();
123 }
124 
126 {
127  const QString id = m_entry.id();
128  if (!id.isEmpty()) {
129  return id;
130  }
131 
132  return QStringLiteral("hash:%1").arg(Syndication::calcMD5Sum(title() + description() + link() + content()));
133 }
134 
136 {
138 
139  QList<Syndication::Atom::Link> links = m_entry.links();
142 
143  for (; it != end; ++it) {
144  if ((*it).rel() == QLatin1String("enclosure")) {
146  }
147  }
148 
149  return list;
150 }
151 
153 {
155 
156  QList<Syndication::Atom::Category> cats = m_entry.categories();
159  list.reserve(cats.count());
160 
161  for (; it != end; ++it) {
162  CategoryAtomImplPtr impl(new CategoryAtomImpl(*it));
163  list.append(impl);
164  }
165 
166  return list;
167 }
168 
170 {
171  QString cstr = m_entry.extractElementTextNS(slashNamespace(), QStringLiteral("comments"));
172  bool ok = false;
173  int comments = cstr.toInt(&ok);
174  return ok ? comments : -1;
175 }
176 
178 {
179  return QString();
180 }
181 
183 {
184  return m_entry.extractElementTextNS(commentApiNamespace(), QStringLiteral("commentRss"));
185 }
186 
188 {
189  return m_entry.extractElementTextNS(commentApiNamespace(), QStringLiteral("comment"));
190 }
191 
192 Syndication::SpecificItemPtr ItemAtomImpl::specificItem() const
193 {
194  return Syndication::SpecificItemPtr(new Syndication::Atom::Entry(m_entry));
195 }
196 
198 {
200  const auto unhandledElements = m_entry.unhandledElements();
201  for (const QDomElement &i : unhandledElements) {
202  ret.insert(i.namespaceURI() + i.localName(), i);
203  }
204 
205  return ret;
206 }
207 
208 } // namespace Syndication
int commentsCount() const override
The number of comments posted for this item.
QString link() const override
returns a link to the (web) resource described by this item.
The content element either contains or links the content of an entry.
Definition: content.h:30
SpecificItemPtr specificItem() const override
returns the format-specific item this object abstracts from.
QString title() const
The item&#39;s title (required).
Definition: rdf/item.cpp:69
void reserve(int alloc)
QString commentPostUri() const override
URI that can be used to post comments via an HTTP POST request using the Comment API.
QString commentsFeed() const override
URL of feed syndicating comments belonging to this item.
QString asString() const
returns the content as string.
Definition: content.cpp:157
QList< PersonPtr > authors() const override
returns a list of persons who created the item content.
int count(const T &value) const const
void append(const T &value)
QString slashNamespace()
"slash" namespace http://purl.org/rss/1.0/modules/slash/
Definition: constants.cpp:44
QList< CategoryPtr > categories() const override
returns a list of categories this item is filed in.
int toInt(bool *ok, int base) const const
typename QMap< Key, T >::iterator insert(const Key &key, const T &value)
time_t datePublished() const override
returns the date when the item was initially published.
QString title() const override
The title of the item.
QList< EnclosurePtr > enclosures() const override
returns a list of enclosures describing files available on the net.
bool isNull() const
returns whether the wrapped element is a null element
QString description() const override
returns the description of the item.
QString link() const
The item&#39;s URL, usually pointing to a website containing the full content (news article, blog entry etc.).
Definition: rdf/item.cpp:93
QString content() const override
returns the content of the item.
QString commentApiNamespace()
wellformedweb.org&#39;s RSS namespace for comment functionality "http://wellformedweb.org/CommentAPI/"
Definition: constants.cpp:39
QString commentsLink() const override
Link to an HTML site which contains the comments belonging to this item.
QString language() const override
returns the language used in the item&#39;s content
an Atom entry, equivalent to the "items" in the RSS world.
Definition: entry.h:38
QString id() const override
returns an identifier that identifies the item within its feed.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QMultiMap< QString, QDomElement > additionalProperties() const override
returns a list of item metadata not covered by this class.
describes a person, with name and optional URI and e-mail address.
Definition: atom/person.h:26
QList::const_iterator constEnd() const const
Definition: feed.h:20
QList::const_iterator constBegin() const const
time_t dateUpdated() const override
returns the date when the item was modified the last time.
QString description() const
A brief description/abstract of the item.
Definition: rdf/item.cpp:81
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Dec 6 2021 22:54:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.