Syndication

feedatomimpl.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 "feedatomimpl.h"
9 #include "categoryatomimpl.h"
10 #include "imageatomimpl.h"
11 #include "itematomimpl.h"
12 #include <atom/category.h>
13 #include <atom/entry.h>
14 #include <atom/link.h>
15 #include <atom/person.h>
16 #include <personimpl.h>
17 
18 #include <QDomElement>
19 #include <QList>
20 #include <QMultiMap>
21 #include <QString>
22 
23 namespace Syndication
24 {
25 FeedAtomImpl::FeedAtomImpl(Syndication::Atom::FeedDocumentPtr doc)
26  : m_doc(doc)
27 {
28 }
29 
30 Syndication::SpecificDocumentPtr FeedAtomImpl::specificDocument() const
31 {
32  return m_doc;
33 }
34 
36 {
38  QList<Syndication::Atom::Entry> entries = m_doc->entries();
41  items.reserve(entries.count());
42 
43  for (; it != end; ++it) {
44  ItemAtomImplPtr item(new ItemAtomImpl(*it));
45  items.append(item);
46  }
47 
48  return items;
49 }
50 
52 {
54  QList<Syndication::Atom::Category> entries = m_doc->categories();
57  categories.reserve(entries.count());
58 
59  for (; it != end; ++it) {
61  categories.append(item);
62  }
63 
64  return categories;
65 }
66 
68 {
69  return m_doc->title();
70 }
71 
73 {
74  QList<Syndication::Atom::Link> links = m_doc->links();
77 
78  // return first link where rel="alternate"
79  // TODO: if there are multiple "alternate" links, find other criteria to choose one of them
80  for (; it != end; ++it) {
81  if ((*it).rel() == QLatin1String("alternate")) {
82  return (*it).href();
83  }
84  }
85 
86  return QString();
87 }
88 
90 {
91  return m_doc->subtitle();
92 }
93 
95 {
96  QList<Syndication::Atom::Person> atomps = m_doc->authors();
97  QList<Syndication::Atom::Person> contributorAtoms = m_doc->contributors();
100 
101  QList<PersonPtr> list;
102  list.reserve(atomps.count() + contributorAtoms.count());
103 
104  for (; it != end; ++it) {
105  PersonImplPtr ptr(new PersonImpl((*it).name(), (*it).uri(), (*it).email()));
106  list.append(ptr);
107  }
108 
109  it = contributorAtoms.constBegin();
110  end = contributorAtoms.constEnd();
111 
112  for (; it != end; ++it) {
113  PersonImplPtr ptr(new PersonImpl((*it).name(), (*it).uri(), (*it).email()));
114  list.append(ptr);
115  }
116 
117  return list;
118 }
119 
121 {
122  return m_doc->xmlLang();
123 }
124 
126 {
127  return m_doc->rights();
128 }
129 
131 {
132  return ImageAtomImplPtr(new ImageAtomImpl(m_doc->logo()));
133 }
134 
136 {
137  return ImageAtomImplPtr(new ImageAtomImpl(m_doc->icon()));
138 }
139 
141 {
143  const auto unhandledElements = m_doc->unhandledElements();
144  for (const QDomElement &i : unhandledElements) {
145  ret.insert(i.namespaceURI() + i.localName(), i);
146  }
147 
148  return ret;
149 }
150 
151 } // namespace Syndication
QMultiMap< QString, QDomElement > additionalProperties() const override
returns a list of feed metadata not covered by this class.
ImagePtr icon() const override
returns an icon associated with this item.
void reserve(int alloc)
ImagePtr image() const override
returns an image associated with this item.
QList< PersonPtr > authors() const override
returns a list of persons who created the feed content.
QString copyright() const override
returns copyright information about the feed
QString description() const override
A description of the feed.
int count(const T &value) const const
void append(const T &value)
virtual QList< ItemPtr > items() const =0
A list of items, in the order they were parsed from the feed source.
typename QMap< Key, T >::iterator insert(const Key &key, const T &value)
Syndication::SpecificDocumentPtr specificDocument() const override
returns the format-specific document this abstraction wraps.
QString title() const override
The title of the feed.
virtual QList< CategoryPtr > categories() const =0
returns a list of categories this feed is associated with.
QList::const_iterator constEnd() const const
Definition: feed.h:20
QList::const_iterator constBegin() const const
QList< Syndication::ItemPtr > items() const override
A list of items, in the order they were parsed from the feed source.
QString language() const override
The language used in the feed.
QString link() const override
returns a link pointing to a website associated with this channel.
QList< CategoryPtr > categories() const override
returns a list of categories this feed is associated with.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Dec 6 2021 22:54:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.