Syndication

itemrss2impl.cpp
1/*
2 This file is part of the syndication library
3 SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org>
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
22namespace Syndication
23{
24ItemRSS2Impl::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{
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{
105 const QList<Syndication::RSS2::Enclosure> encs = m_item.enclosures();
106
108 list.reserve(encs.size());
109
110 std::transform(encs.cbegin(), encs.cend(), std::back_inserter(list), [this](const Syndication::RSS2::Enclosure &e) {
111 return EnclosureRSS2ImplPtr(new EnclosureRSS2Impl(m_item, e));
112 });
113
114 return list;
115}
116
118{
119 const QList<Syndication::RSS2::Category> cats = m_item.categories();
120
122 list.reserve(cats.size());
123
124 std::transform(cats.cbegin(), cats.cend(), std::back_inserter(list), [](const Syndication::RSS2::Category &c) {
125 return CategoryRSS2ImplPtr(new CategoryRSS2Impl(c));
126 });
127
128 return list;
129}
130
132{
133 const QString cstr = m_item.extractElementTextNS(slashNamespace(), QStringLiteral("comments"));
134 bool ok = false;
135 int comments = cstr.toInt(&ok);
136 return ok ? comments : -1;
137}
138
140{
141 return m_item.comments();
142}
143
145{
146 QString t = m_item.extractElementTextNS(commentApiNamespace(), QStringLiteral("commentRss"));
147 if (t.isNull()) {
148 t = m_item.extractElementTextNS(commentApiNamespace(), QStringLiteral("commentRSS"));
149 }
150 return t;
151}
152
154{
155 return m_item.extractElementTextNS(commentApiNamespace(), QStringLiteral("comment"));
156}
157
158Syndication::SpecificItemPtr ItemRSS2Impl::specificItem() const
159{
160 return Syndication::SpecificItemPtr(new Syndication::RSS2::Item(m_item));
161}
162
164{
166
167 const auto unhandledElements = m_item.unhandledElements();
168 for (const QDomElement &i : unhandledElements) {
169 ret.insert(i.namespaceURI() + i.localName(), i);
170 }
171
172 return ret;
173}
174
175} // namespace Syndication
QString title() const override
The title of the item.
QString content() const override
returns the content of the item.
QString commentPostUri() const override
URI that can be used to post comments via an HTTP POST request using the Comment API.
SpecificItemPtr specificItem() const override
returns the format-specific item this object abstracts from.
time_t dateUpdated() const override
returns the date when the item was modified the last time.
QString description() const override
returns the description of the item.
QList< PersonPtr > authors() const override
returns a list of persons who created the item content.
QString id() const override
returns an identifier that identifies the item within its feed.
int commentsCount() const override
The number of comments posted for this item.
QString commentsLink() const override
Link to an HTML site which contains the comments belonging to this item.
time_t datePublished() const override
returns the date when the item was initially published.
QString link() const override
returns a link to the (web) resource described by this item.
QList< CategoryPtr > categories() const override
returns a list of categories this item is filed in.
QMultiMap< QString, QDomElement > additionalProperties() const override
returns a list of item metadata not covered by this class.
QString language() const override
returns the language used in the item's content
QString commentsFeed() const override
URL of feed syndicating comments belonging to this item.
QList< EnclosurePtr > enclosures() const override
returns a list of enclosures describing files available on the net.
A category which can be assigned to items or whole feeds.
Describes a media object that is "attached" to the item.
QString atom1Namespace()
namespace used by Atom 1.0 elements
QString slashNamespace()
"slash" namespace http://purl.org/rss/1.0/modules/slash/
Definition constants.cpp:44
QString commentApiNamespace()
wellformedweb.org's RSS namespace for comment functionality "http://wellformedweb....
Definition constants.cpp:39
void append(QList< T > &&value)
const_iterator cbegin() const const
const_iterator cend() const const
void reserve(qsizetype size)
qsizetype size() const const
iterator insert(const Key &key, const T &value)
QString arg(Args &&... args) const const
bool isEmpty() const const
bool isNull() const const
int toInt(bool *ok, int base) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Thu Jan 23 2025 19:01:16 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.