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 
27 using Syndication::Atom::Content;
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  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 
73  QList<PersonPtr> list;
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")) {
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 
170 Syndication::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
void append(const T &value)
Definition: feed.h:20
bool isNull() const const
QString commentPostUri() const override
URI that can be used to post comments via an HTTP POST request using the Comment API.
QList< EnclosurePtr > enclosures() const override
returns a list of enclosures describing files available on the net.
int count(const T &value) const const
QString commentApiNamespace()
wellformedweb.org's RSS namespace for comment functionality "http://wellformedweb....
Definition: constants.cpp:39
QString link() const override
returns a link to the (web) resource described by this item.
time_t dateUpdated() const override
returns the date when the item was modified the last time.
void reserve(int alloc)
QString commentsFeed() const override
URL of feed syndicating comments belonging to this item.
int size() const const
A category for categorizing items or whole feeds.
Definition: atom/category.h:31
an Atom entry, equivalent to the "items" in the RSS world.
Definition: entry.h:38
SpecificItemPtr specificItem() const override
returns the format-specific item this object abstracts from.
QString title() const
title of the entry (required).
Definition: entry.cpp:133
QString language() const override
returns the language used in the item's content
time_t published() const
The datetime of the publication of this entry (optional).
Definition: entry.cpp:116
Content content() const
content of the entry (optional) See Content for details
Definition: entry.cpp:138
QString slashNamespace()
"slash" namespace http://purl.org/rss/1.0/modules/slash/
Definition: constants.cpp:44
int toInt(bool *ok, int base) const const
QMultiMap< QString, QDomElement > additionalProperties() const override
returns a list of item metadata not covered by this class.
QList::const_iterator cend() const const
QList< PersonPtr > authors() const override
returns a list of persons who created the item content.
QList< Category > categories() const
a list of categories this entry is filed to (optional)
Definition: entry.cpp:75
QString content() const override
returns the content of the item.
typename QMap< Key, T >::iterator insert(const Key &key, const T &value)
QString id() const override
returns an identifier that identifies the item within its feed.
QList< Person > authors() const
list of persons who are authors of this entry.
Definition: entry.cpp:44
QString commentsLink() const override
Link to an HTML site which contains the comments belonging to this item.
int commentsCount() const override
The number of comments posted for this item.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QList< QDomElement > unhandledElements() const
returns all child elements of this entry not covered by this class.
Definition: entry.cpp:143
QString summary() const
a short summary, abstract or excerpt of an entry.
Definition: entry.cpp:128
QList::const_iterator cbegin() const const
QString description() const override
returns the description of the item.
QList< Person > contributors() const
list of persons contributing to this entry (optional)
Definition: entry.cpp:62
QString title() const override
The title of the item.
QList< Link > links() const
links pointing to associated web sites and other resources.
Definition: entry.cpp:93
time_t datePublished() const override
returns the date when the item was initially published.
QList< CategoryPtr > categories() const override
returns a list of categories this item is filed in.
time_t updated() const
The datetime of the last modification of this entry (required).
Definition: entry.cpp:122
describes a person, with name and optional URI and e-mail address.
Definition: atom/person.h:26
QString id() const
ID of the article.
Definition: entry.cpp:88
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Jun 6 2023 03:56:27 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.