Syndication

itemrss2impl.cpp
1 /*
2  This file is part of the syndication library
3  SPDX-FileCopyrightText: 2006 Frank Osterfeld <[email protected]>
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "itemrss2impl.h"
8 #include "categoryrss2impl.h"
9 #include "enclosurerss2impl.h"
10 #include <atom/constants.h>
11 #include <constants.h>
12 #include <personimpl.h>
13 #include <rss2/category.h>
14 #include <rss2/enclosure.h>
15 #include <tools.h>
16 
17 #include <QDomElement>
18 #include <QList>
19 #include <QMultiMap>
20 #include <QString>
21 
22 namespace Syndication
23 {
24 ItemRSS2Impl::ItemRSS2Impl(const Syndication::RSS2::Item &item)
25  : m_item(item)
26 {
27 }
28 
30 {
31  return m_item.title();
32 }
33 
35 {
36  const QString link = m_item.link();
37  if (!link.isEmpty()) {
38  return link;
39  }
40 
41  const QString guid = m_item.guid();
42  if (m_item.guidIsPermaLink()) {
43  return guid;
44  }
45 
46  return QString();
47 }
48 
50 {
51  return m_item.description();
52 }
53 
55 {
56  return m_item.content();
57 }
58 
60 {
61  QList<PersonPtr> list;
62 
63  PersonPtr ptr = personFromString(m_item.author());
64 
65  if (!ptr->isNull()) {
66  list.append(ptr);
67  }
68 
69  return list;
70 }
71 
73 {
74  return QString();
75 }
76 
78 {
79  QString guid = m_item.guid();
80  if (!guid.isEmpty()) {
81  return guid;
82  }
83 
84  return QStringLiteral("hash:%1").arg(calcMD5Sum(title() + description() + link() + content()));
85 }
86 
88 {
89  return m_item.pubDate();
90 }
91 
93 {
94  // Some RSS feeds contain atom elements - return atom:dateUpdated if present
95  const QString updstr = m_item.extractElementTextNS(Atom::atom1Namespace(), QStringLiteral("updated"));
96  if (!updstr.isEmpty()) {
97  return parseDate(updstr, ISODate);
98  } else {
99  return datePublished();
100  }
101 }
102 
104 {
106 
107  const QList<Syndication::RSS2::Enclosure> encs = m_item.enclosures();
108  list.reserve(encs.size());
109 
110  for (auto it = encs.cbegin(); it != encs.cend(); ++it) {
111  EnclosureRSS2ImplPtr impl(new EnclosureRSS2Impl(m_item, *it));
112  list.append(impl);
113  }
114 
115  return list;
116 }
117 
119 {
121 
122  const QList<Syndication::RSS2::Category> cats = m_item.categories();
123  list.reserve(cats.size());
124 
125  for (auto it = cats.cbegin(), end = cats.cend(); it != end; ++it) {
126  CategoryRSS2ImplPtr impl(new CategoryRSS2Impl(*it));
127  list.append(impl);
128  }
129 
130  return list;
131 }
132 
134 {
135  const QString cstr = m_item.extractElementTextNS(slashNamespace(), QStringLiteral("comments"));
136  bool ok = false;
137  int comments = cstr.toInt(&ok);
138  return ok ? comments : -1;
139 }
140 
142 {
143  return m_item.comments();
144 }
145 
147 {
148  QString t = m_item.extractElementTextNS(commentApiNamespace(), QStringLiteral("commentRss"));
149  if (t.isNull()) {
150  t = m_item.extractElementTextNS(commentApiNamespace(), QStringLiteral("commentRSS"));
151  }
152  return t;
153 }
154 
156 {
157  return m_item.extractElementTextNS(commentApiNamespace(), QStringLiteral("comment"));
158 }
159 
160 Syndication::SpecificItemPtr ItemRSS2Impl::specificItem() const
161 {
162  return Syndication::SpecificItemPtr(new Syndication::RSS2::Item(m_item));
163 }
164 
166 {
168 
169  const auto unhandledElements = m_item.unhandledElements();
170  for (const QDomElement &i : unhandledElements) {
171  ret.insert(i.namespaceURI() + i.localName(), i);
172  }
173 
174  return ret;
175 }
176 
177 } // namespace Syndication
QString commentsFeed() const override
URL of feed syndicating comments belonging to this item.
QString id() const override
returns an identifier that identifies the item within its feed.
QString title() const
The item&#39;s title (required).
Definition: rdf/item.cpp:69
void reserve(int alloc)
QList< CategoryPtr > categories() const override
returns a list of categories this item is filed in.
SpecificItemPtr specificItem() const override
returns the format-specific item this object abstracts from.
QMultiMap< QString, QDomElement > additionalProperties() const override
returns a list of item metadata not covered by this class.
QString commentPostUri() const override
URI that can be used to post comments via an HTTP POST request using the Comment API.
int commentsCount() const override
The number of comments posted for this item.
int size() const const
bool isNull() const const
QString description() const override
returns the description of the item.
Definition: itemrdfimpl.cpp:46
QString link() const override
returns a link to the (web) resource described by this item.
Definition: itemrdfimpl.cpp:41
QString title() const override
The title of the item.
Definition: itemrdfimpl.cpp:36
void append(const T &value)
QString title() const override
The title of the item.
QString slashNamespace()
"slash" namespace http://purl.org/rss/1.0/modules/slash/
Definition: constants.cpp:44
int toInt(bool *ok, int base) const const
bool isEmpty() const const
time_t dateUpdated() const override
returns the date when the item was modified the last time.
QString content() const override
returns the content of the item.
Definition: itemrdfimpl.cpp:51
typename QMap< Key, T >::iterator insert(const Key &key, const T &value)
QString atom1Namespace()
namespace used by Atom 1.0 elements
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 commentApiNamespace()
wellformedweb.org&#39;s RSS namespace for comment functionality "http://wellformedweb.org/CommentAPI/"
Definition: constants.cpp:39
QString language() const override
returns the language used in the item&#39;s content
QString content() const override
returns the content of the item.
QList::const_iterator cend() const const
QList::const_iterator cbegin() const const
QList< EnclosurePtr > enclosures() const override
returns a list of enclosures describing files available on the net.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString commentsLink() const override
Link to an HTML site which contains the comments belonging to this item.
QString link() const override
returns a link to the (web) resource described by this item.
QString description() const override
returns the description of the item.
Definition: feed.h:20
QList< PersonPtr > authors() const override
returns a list of persons who created the item content.
time_t datePublished() const override
returns the date when the item was initially published.
time_t datePublished() const override
returns the date when the item was initially published.
Definition: itemrdfimpl.cpp:89
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 Sun Dec 5 2021 22:54:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.