File indexing completed on 2024-04-28 07:50:15

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 "feedrdfimpl.h"
0009 #include "imagerdfimpl.h"
0010 #include "itemrdfimpl.h"
0011 
0012 #include <category.h>
0013 #include <personimpl.h>
0014 #include <rdf/dublincore.h>
0015 #include <rdf/item.h>
0016 #include <tools.h>
0017 
0018 #include <QDomElement>
0019 #include <QList>
0020 #include <QMultiMap>
0021 #include <QString>
0022 #include <QStringList>
0023 
0024 namespace Syndication
0025 {
0026 FeedRDFImpl::FeedRDFImpl(Syndication::RDF::DocumentPtr doc)
0027     : m_doc(doc)
0028 {
0029 }
0030 
0031 Syndication::SpecificDocumentPtr FeedRDFImpl::specificDocument() const
0032 {
0033     return m_doc;
0034 }
0035 
0036 QList<Syndication::ItemPtr> FeedRDFImpl::items() const
0037 {
0038     const QList<Syndication::RDF::Item> entries = m_doc->items();
0039 
0040     QList<ItemPtr> items;
0041     items.reserve(entries.count());
0042 
0043     std::transform(entries.cbegin(), entries.cend(), std::back_inserter(items), [](const Syndication::RDF::Item &entry) {
0044         return ItemRDFImplPtr(new ItemRDFImpl(entry));
0045     });
0046 
0047     return items;
0048 }
0049 
0050 QList<Syndication::CategoryPtr> FeedRDFImpl::categories() const
0051 {
0052     // TODO: check if it makes sense to map dc:subject to categories
0053     return QList<Syndication::CategoryPtr>();
0054 }
0055 
0056 QString FeedRDFImpl::title() const
0057 {
0058     return m_doc->title();
0059 }
0060 
0061 QString FeedRDFImpl::link() const
0062 {
0063     return m_doc->link();
0064 }
0065 
0066 QString FeedRDFImpl::description() const
0067 {
0068     return m_doc->description();
0069 }
0070 
0071 QList<PersonPtr> FeedRDFImpl::authors() const
0072 {
0073     const QStringList people = m_doc->dc().creators() + m_doc->dc().contributors();
0074 
0075     QList<PersonPtr> list;
0076     list.reserve(people.size());
0077 
0078     for (const auto &person : people) {
0079         PersonPtr ptr = personFromString(person);
0080         if (!ptr->isNull()) {
0081             list.append(ptr);
0082         }
0083     }
0084 
0085     return list;
0086 }
0087 
0088 QString FeedRDFImpl::language() const
0089 {
0090     return m_doc->dc().language();
0091 }
0092 
0093 QString FeedRDFImpl::copyright() const
0094 {
0095     return m_doc->dc().rights();
0096 }
0097 
0098 ImagePtr FeedRDFImpl::image() const
0099 {
0100     ImageRDFImplPtr ptr(new ImageRDFImpl(m_doc->image()));
0101     return ptr;
0102 }
0103 
0104 ImagePtr FeedRDFImpl::icon() const
0105 {
0106     ImageRDFImplPtr ptr(new ImageRDFImpl({}));
0107     return ptr;
0108 }
0109 
0110 QMultiMap<QString, QDomElement> FeedRDFImpl::additionalProperties() const
0111 {
0112     return QMultiMap<QString, QDomElement>();
0113 }
0114 
0115 } // namespace Syndication