File indexing completed on 2024-04-21 15:07:25

0001 /*
0002     This file is part of the syndication library
0003     SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "feedrss2impl.h"
0009 #include "categoryrss2impl.h"
0010 #include "imagerss2impl.h"
0011 #include "itemrss2impl.h"
0012 #include <personimpl.h>
0013 #include <rss2/category.h>
0014 #include <rss2/item.h>
0015 
0016 #include <QDomElement>
0017 #include <QList>
0018 #include <QMultiMap>
0019 #include <QString>
0020 
0021 namespace Syndication
0022 {
0023 FeedRSS2Impl::FeedRSS2Impl(Syndication::RSS2::DocumentPtr doc)
0024     : m_doc(doc)
0025 {
0026 }
0027 
0028 Syndication::SpecificDocumentPtr FeedRSS2Impl::specificDocument() const
0029 {
0030     return m_doc;
0031 }
0032 
0033 QList<Syndication::ItemPtr> FeedRSS2Impl::items() const
0034 {
0035     const QList<Syndication::RSS2::Item> entries = m_doc->items();
0036 
0037     QList<ItemPtr> items;
0038     items.reserve(entries.count());
0039 
0040     std::transform(entries.cbegin(), entries.cend(), std::back_inserter(items), [](const Syndication::RSS2::Item &entry) {
0041         return ItemRSS2ImplPtr(new ItemRSS2Impl(entry));
0042     });
0043 
0044     return items;
0045 }
0046 
0047 QList<Syndication::CategoryPtr> FeedRSS2Impl::categories() const
0048 {
0049     const QList<Syndication::RSS2::Category> entries = m_doc->categories();
0050 
0051     QList<CategoryPtr> categories;
0052     categories.reserve(entries.count());
0053 
0054     std::transform(entries.cbegin(), entries.cend(), std::back_inserter(categories), [](const Syndication::RSS2::Category &entry) {
0055         return CategoryRSS2ImplPtr(new CategoryRSS2Impl(entry));
0056     });
0057 
0058     return categories;
0059 }
0060 
0061 QString FeedRSS2Impl::title() const
0062 {
0063     return m_doc->title();
0064 }
0065 
0066 QString FeedRSS2Impl::link() const
0067 {
0068     return m_doc->link();
0069 }
0070 
0071 QString FeedRSS2Impl::description() const
0072 {
0073     return m_doc->description();
0074 }
0075 
0076 QList<PersonPtr> FeedRSS2Impl::authors() const
0077 {
0078     return QList<PersonPtr>();
0079 }
0080 
0081 QString FeedRSS2Impl::language() const
0082 {
0083     return m_doc->language();
0084 }
0085 
0086 QString FeedRSS2Impl::copyright() const
0087 {
0088     return m_doc->copyright();
0089 }
0090 
0091 ImagePtr FeedRSS2Impl::image() const
0092 {
0093     ImageRSS2ImplPtr ptr(new ImageRSS2Impl(m_doc->image()));
0094     return ptr;
0095 }
0096 
0097 QMultiMap<QString, QDomElement> FeedRSS2Impl::additionalProperties() const
0098 {
0099     QMultiMap<QString, QDomElement> ret;
0100 
0101     const auto unhandledElements = m_doc->unhandledElements();
0102     for (const QDomElement &i : unhandledElements) {
0103         ret.insert(i.namespaceURI() + i.localName(), i);
0104     }
0105 
0106     return ret;
0107 }
0108 
0109 ImagePtr FeedRSS2Impl::icon() const
0110 {
0111     ImageRSS2ImplPtr ptr(new ImageRSS2Impl({}));
0112     return ptr;
0113 }
0114 
0115 } // namespace Syndication