Syndication

itematomimpl.cpp
1/*
2 This file is part of the syndication library
3 SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org>
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
31namespace Syndication
32{
33ItemAtomImpl::ItemAtomImpl(const Syndication::Atom::Entry &entry)
34 : m_entry(entry)
35{
36}
37
39{
40 return m_entry.title();
41}
42
44{
45 const QList<Syndication::Atom::Link> links = m_entry.links();
46
47 // return first link where rel="alternate"
48 auto it = std::find_if(links.cbegin(), links.cend(), [](const Syndication::Atom::Link &link) {
49 return link.rel() == QLatin1String("alternate");
50 });
51 return it != links.cend() ? it->href() : QString{};
52}
53
55{
56 return m_entry.summary();
57}
58
60{
61 Content content = m_entry.content();
62 if (content.isNull()) {
63 return QString();
64 }
65
66 return content.asString();
67}
68
70{
71 const QList<Syndication::Atom::Person> people = m_entry.authors() + m_entry.contributors();
72
74 list.reserve(people.size());
75
76 std::transform(people.cbegin(), people.cend(), std::back_inserter(list), [](const Syndication::Atom::Person &person) {
77 return PersonImplPtr(new PersonImpl(person.name(), person.uri(), person.email()));
78 });
79
80 return list;
81}
82
84{
85 time_t pub = m_entry.published();
86 if (pub == 0) {
87 return m_entry.updated();
88 } else {
89 return pub;
90 }
91}
92
94{
95 time_t upd = m_entry.updated();
96 if (upd == 0) {
97 return m_entry.published();
98 } else {
99 return upd;
100 }
101}
102
104{
105 return m_entry.xmlLang();
106}
107
109{
110 const QString id = m_entry.id();
111 if (!id.isEmpty()) {
112 return id;
113 }
114
115 return QStringLiteral("hash:%1").arg(Syndication::calcMD5Sum(title() + description() + link() + content()));
116}
117
119{
121
122 const QList<Syndication::Atom::Link> links = m_entry.links();
123
124 for (const auto &link : links) {
125 if (link.rel() == QLatin1String("enclosure")) {
126 list.append(EnclosureAtomImplPtr(new EnclosureAtomImpl(link)));
127 }
128 }
129
130 return list;
131}
132
134{
135 const QList<Syndication::Atom::Category> cats = m_entry.categories();
136
138 list.reserve(cats.count());
139
140 std::transform(cats.cbegin(), cats.cend(), std::back_inserter(list), [](const Syndication::Atom::Category &c) {
141 return CategoryAtomImplPtr(new CategoryAtomImpl(c));
142 });
143
144 return list;
145}
146
148{
149 QString cstr = m_entry.extractElementTextNS(slashNamespace(), QStringLiteral("comments"));
150 bool ok = false;
151 int comments = cstr.toInt(&ok);
152 return ok ? comments : -1;
153}
154
156{
157 return QString();
158}
159
161{
162 return m_entry.extractElementTextNS(commentApiNamespace(), QStringLiteral("commentRss"));
163}
164
166{
167 return m_entry.extractElementTextNS(commentApiNamespace(), QStringLiteral("comment"));
168}
169
170Syndication::SpecificItemPtr ItemAtomImpl::specificItem() const
171{
172 return Syndication::SpecificItemPtr(new Syndication::Atom::Entry(m_entry));
173}
174
176{
178 const auto unhandledElements = m_entry.unhandledElements();
179 for (const QDomElement &i : unhandledElements) {
180 ret.insert(i.namespaceURI() + i.localName(), i);
181 }
182
183 return ret;
184}
185
186} // namespace Syndication
A category for categorizing items or whole feeds.
The content element either contains or links the content of an entry.
Definition content.h:31
an Atom entry, equivalent to the "items" in the RSS world.
Definition entry.h:39
describes a person, with name and optional URI and e-mail address.
Definition atom/person.h:27
QString commentsFeed() const override
URL of feed syndicating comments belonging to this item.
QString commentsLink() const override
Link to an HTML site which contains the comments belonging to this item.
SpecificItemPtr specificItem() const override
returns the format-specific item this object abstracts from.
QList< EnclosurePtr > enclosures() const override
returns a list of enclosures describing files available on the net.
int commentsCount() const override
The number of comments posted for this item.
QString commentPostUri() const override
URI that can be used to post comments via an HTTP POST request using the Comment API.
QList< PersonPtr > authors() const override
returns a list of persons who created the item content.
time_t dateUpdated() const override
returns the date when the item was modified the last time.
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 id() const override
returns an identifier that identifies the item within its feed.
QString content() const override
returns the content of the item.
QString description() const override
returns the description of the item.
QString title() const override
The title of the item.
QString language() const override
returns the language used in the item's content
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
qsizetype count() const const
void reserve(qsizetype size)
qsizetype size() const const
iterator insert(const Key &key, const T &value)
QString arg(Args &&... args) 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.