File indexing completed on 2024-04-14 03:58:26

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 "itemrdfimpl.h"
0009 
0010 #include <category.h>
0011 #include <constants.h>
0012 #include <enclosure.h>
0013 #include <personimpl.h>
0014 #include <rdf/dublincore.h>
0015 #include <rdf/property.h>
0016 #include <rdf/resource.h>
0017 #include <rdf/resourcewrapper.h>
0018 #include <rdf/statement.h>
0019 #include <tools.h>
0020 
0021 #include <QDomElement>
0022 #include <QList>
0023 #include <QMultiMap>
0024 #include <QStringList>
0025 
0026 using Syndication::RDF::Property;
0027 using Syndication::RDF::PropertyPtr;
0028 
0029 namespace Syndication
0030 {
0031 ItemRDFImpl::ItemRDFImpl(const Syndication::RDF::Item &item)
0032     : m_item(item)
0033 {
0034 }
0035 
0036 QString ItemRDFImpl::title() const
0037 {
0038     return m_item.title();
0039 }
0040 
0041 QString ItemRDFImpl::link() const
0042 {
0043     return m_item.link();
0044 }
0045 
0046 QString ItemRDFImpl::description() const
0047 {
0048     return m_item.description();
0049 }
0050 
0051 QString ItemRDFImpl::content() const
0052 {
0053     return m_item.encodedContent();
0054 }
0055 
0056 QList<PersonPtr> ItemRDFImpl::authors() const
0057 {
0058     QList<PersonPtr> list;
0059 
0060     const QStringList people = m_item.dc().creators() + m_item.dc().contributors();
0061 
0062     for (const auto &person : people) {
0063         PersonPtr ptr = personFromString(person);
0064         if (!ptr->isNull()) {
0065             list.append(ptr);
0066         }
0067     }
0068 
0069     return list;
0070 }
0071 
0072 QString ItemRDFImpl::language() const
0073 {
0074     return m_item.dc().language();
0075 }
0076 
0077 QString ItemRDFImpl::id() const
0078 {
0079     if (!m_item.resource()->isAnon()) {
0080         return m_item.resource()->uri();
0081     } else {
0082         return QLatin1String("hash:") + calcMD5Sum(title() + description() + link() + content());
0083     }
0084 }
0085 
0086 time_t ItemRDFImpl::datePublished() const
0087 {
0088     return m_item.dc().date();
0089 }
0090 
0091 time_t ItemRDFImpl::dateUpdated() const
0092 {
0093     return m_item.dc().date();
0094 }
0095 
0096 QList<Syndication::EnclosurePtr> ItemRDFImpl::enclosures() const
0097 {
0098     // return empty list
0099     return QList<Syndication::EnclosurePtr>();
0100 }
0101 
0102 QList<Syndication::CategoryPtr> ItemRDFImpl::categories() const
0103 {
0104     // return empty list
0105     return QList<Syndication::CategoryPtr>();
0106 }
0107 
0108 int ItemRDFImpl::commentsCount() const
0109 {
0110     PropertyPtr prop(new Property(slashNamespace() + QLatin1String("comments")));
0111     QString cstr = m_item.resource()->property(prop)->asString();
0112     bool ok = false;
0113     int comments = cstr.toInt(&ok);
0114     return ok ? comments : -1;
0115     return -1;
0116 }
0117 
0118 QString ItemRDFImpl::commentsLink() const
0119 {
0120     return QString();
0121 }
0122 
0123 QString ItemRDFImpl::commentsFeed() const
0124 {
0125     PropertyPtr prop(new Property(commentApiNamespace() + QLatin1String("commentRss")));
0126     return m_item.resource()->property(prop)->asString();
0127 }
0128 
0129 QString ItemRDFImpl::commentPostUri() const
0130 {
0131     PropertyPtr prop(new Property(commentApiNamespace() + QLatin1String("comment")));
0132     return m_item.resource()->property(prop)->asString();
0133 }
0134 
0135 Syndication::SpecificItemPtr ItemRDFImpl::specificItem() const
0136 {
0137     return Syndication::SpecificItemPtr(new Syndication::RDF::Item(m_item));
0138 }
0139 
0140 QMultiMap<QString, QDomElement> ItemRDFImpl::additionalProperties() const
0141 {
0142     return QMultiMap<QString, QDomElement>();
0143 }
0144 
0145 } // namespace Syndication