9#include <rss2/category.h>
10#include <rss2/enclosure.h>
12#include <rss2/source.h>
13#include <rss2/tools_p.h>
14#include <specificitem.h>
15#include <specificitemvisitor.h>
28class SYNDICATION_NO_EXPORT Item::ItemPrivate
31 QSharedPointer<Document> doc;
34Item::Item(QSharedPointer<Document> doc)
42 : ElementWrapper(element)
52Item::Item(
const Item &other)
53 : ElementWrapper(other)
59Item &Item::operator=(
const Item &other)
61 ElementWrapper::operator=(other);
62 SpecificItem::operator=(other);
70 return originalTitle();
74 bool containsMarkup =
false;
75 d->doc->getItemTitleFormatInfo(&isCDATA, &containsMarkup);
77 return normalize(originalTitle(), isCDATA, containsMarkup);
80QString Item::originalDescription()
const
82 return extractElementTextNS(QString(), QStringLiteral(
"description"));
85QString Item::originalTitle()
const
87 return extractElementTextNS(QString(), QStringLiteral(
"title"));
92 QString url = extractElementTextNS(QString(), QStringLiteral(
"link"));
99 if (d->doc->link().isEmpty()) {
104 QString baseUrl = d->doc->link();
106 return baseUrl + url;
108 return baseUrl + QLatin1Char(
'/') + url;
112QString Item::description()
const
115 return originalDescription();
118 bool isCDATA =
false;
119 bool containsMarkup =
false;
120 d->doc->getItemDescriptionFormatInfo(&isCDATA, &containsMarkup);
122 return normalize(originalDescription(), isCDATA, containsMarkup);
128 return extractContent(*
this);
133 const QList<QDomElement> cats = elementsByTagNameNS(QString(), QStringLiteral(
"category"));
135 QList<Category> categories;
138 std::transform(cats.
cbegin(), cats.
cend(), std::back_inserter(categories), [](
const QDomElement &element) {
139 return Category(element);
147 return extractElementTextNS(QString(), QStringLiteral(
"comments"));
152 QString a = extractElementTextNS(QString(), QStringLiteral(
"author"));
157 return extractElementTextNS(dublinCoreNamespace(), QStringLiteral(
"creator"));
163 const QList<QDomElement> encs = elementsByTagNameNS(QString(), QStringLiteral(
"enclosure"));
165 QList<Enclosure> enclosures;
168 std::transform(encs.
cbegin(), encs.
cend(), std::back_inserter(enclosures), [](
const QDomElement &element) {
169 return Enclosure(element);
177 return extractElementTextNS(QString(), QStringLiteral(
"guid"));
180bool Item::guidIsPermaLink()
const
182 bool guidIsPermaLink =
true;
184 QDomElement guidNode = firstElementByTagNameNS(QString(), QStringLiteral(
"guid"));
186 if (guidNode.
attribute(QStringLiteral(
"isPermaLink")) == QLatin1String(
"false")) {
187 guidIsPermaLink =
false;
191 return guidIsPermaLink;
194time_t Item::pubDate()
const
196 QString str = extractElementTextNS(QString(), QStringLiteral(
"pubDate"));
199 return parseDate(str, RFCDate);
203 str = extractElementTextNS(dublinCoreNamespace(), QStringLiteral(
"date"));
204 return parseDate(str, ISODate);
207time_t Item::expirationDate()
const
209 QString str = extractElementTextNS(QString(), QStringLiteral(
"expirationDate"));
210 return parseDate(str, RFCDate);
213Source Item::source()
const
215 return Source(firstElementByTagNameNS(QString(), QStringLiteral(
"source")));
220 return extractElementTextNS(QString(), QStringLiteral(
"rating"));
225 QString info = QLatin1String(
"### Item: ###################\n");
226 if (!title().isNull()) {
227 info += QLatin1String(
"title: #") + title() + QLatin1String(
"#\n");
229 if (!
link().isNull()) {
230 info += QLatin1String(
"link: #") +
link() + QLatin1String(
"#\n");
232 if (!description().isNull()) {
233 info += QLatin1String(
"description: #") + description() + QLatin1String(
"#\n");
235 if (!content().isNull()) {
236 info += QLatin1String(
"content: #") + content() + QLatin1String(
"#\n");
238 if (!author().isNull()) {
239 info += QLatin1String(
"author: #") + author() + QLatin1String(
"#\n");
242 info += QLatin1String(
"comments: #") +
comments() + QLatin1String(
"#\n");
246 info += QLatin1String(
"pubDate: #") + dpubdate + QLatin1String(
"#\n");
248 if (!guid().isNull()) {
249 info += QLatin1String(
"guid: #") + guid() + QLatin1String(
"#\n");
251 if (guidIsPermaLink()) {
252 info += QLatin1String(
"guid is PL: #true#\n");
254 if (!source().isNull()) {
255 info += source().debugInfo();
258 const QList<Category> cats = categories();
259 for (
const auto &c : cats) {
260 info += c.debugInfo();
263 const QList<Enclosure> encs = enclosures();
264 for (
const auto &e : encs) {
265 info += e.debugInfo();
268 info += QLatin1String(
"### Item end ################\n");
275 static std::vector<ElementType> handled;
276 if (handled.empty()) {
278 handled.push_back(ElementType(QStringLiteral(
"title")));
279 handled.push_back(ElementType(QStringLiteral(
"link")));
280 handled.push_back(ElementType(QStringLiteral(
"description")));
281 handled.push_back(ElementType(QStringLiteral(
"pubDate")));
282 handled.push_back(ElementType(QStringLiteral(
"expirationDate")));
283 handled.push_back(ElementType(QStringLiteral(
"rating")));
284 handled.push_back(ElementType(QStringLiteral(
"source")));
285 handled.push_back(ElementType(QStringLiteral(
"guid")));
286 handled.push_back(ElementType(QStringLiteral(
"comments")));
287 handled.push_back(ElementType(QStringLiteral(
"author")));
288 handled.push_back(ElementType(QStringLiteral(
"date"), dublinCoreNamespace()));
291 QList<QDomElement> notHandled;
293 QDomNodeList
children = element().childNodes();
294 const int numChildren =
children.size();
295 for (
int i = 0; i < numChildren; ++i) {
296 QDomElement el =
children.at(i).toElement();
298 && std::find(handled.cbegin(), handled.cend(), ElementType(el.
localName(), el.
namespaceURI())) == handled.cend()) {
306bool Item::accept(SpecificItemVisitor *visitor)
308 return visitor->visitRSS2Item(
this);
KIOCORE_EXPORT CopyJob * link(const QList< QUrl > &src, const QUrl &destDir, JobFlags flags=DefaultFlags)
QString normalize(QStringView str)
KEDUVOCDOCUMENT_EXPORT QStringList comments(const QString &language=QString())
QString attribute(const QString &name, const QString &defValue) const const
bool isNull() const const
QString localName() const const
QString namespaceURI() const const
void append(QList< T > &&value)
const_iterator cbegin() const const
const_iterator cend() const const
qsizetype count() const const
void reserve(qsizetype size)
const QObjectList & children() const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
bool isNull() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const