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
29QString ItemRSS2Impl::title() const
30{
31 return m_item.title();
32}
33
34QString ItemRSS2Impl::link() const
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
49QString ItemRSS2Impl::description() const
50{
51 return m_item.description();
52}
53
54QString ItemRSS2Impl::content() const
55{
56 return m_item.content();
57}
58
59QList<PersonPtr> ItemRSS2Impl::authors() const
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
72QString ItemRSS2Impl::language() const
73{
74 return QString();
75}
76
77QString ItemRSS2Impl::id() const
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
87time_t ItemRSS2Impl::datePublished() const
88{
89 return m_item.pubDate();
90}
91
92time_t ItemRSS2Impl::dateUpdated() const
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
103QList<Syndication::EnclosurePtr> ItemRSS2Impl::enclosures() const
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
117QList<Syndication::CategoryPtr> ItemRSS2Impl::categories() const
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
131int ItemRSS2Impl::commentsCount() const
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
139QString ItemRSS2Impl::commentsLink() const
140{
141 return m_item.comments();
142}
143
144QString ItemRSS2Impl::commentsFeed() const
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
153QString ItemRSS2Impl::commentPostUri() const
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
163QMultiMap<QString, QDomElement> ItemRSS2Impl::additionalProperties() const
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
A category which can be assigned to items or whole feeds.
Describes a media object that is "attached" to the item.
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-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:02:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.