| 1 | /* |
|---|---|
| 2 | This file is part of the syndication library |
| 3 | SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #include "itemrdfimpl.h" |
| 9 | |
| 10 | #include <category.h> |
| 11 | #include <constants.h> |
| 12 | #include <enclosure.h> |
| 13 | #include <personimpl.h> |
| 14 | #include <rdf/dublincore.h> |
| 15 | #include <rdf/property.h> |
| 16 | #include <rdf/resource.h> |
| 17 | #include <rdf/resourcewrapper.h> |
| 18 | #include <rdf/statement.h> |
| 19 | #include <tools.h> |
| 20 | |
| 21 | #include <QDomElement> |
| 22 | #include <QList> |
| 23 | #include <QMultiMap> |
| 24 | #include <QStringList> |
| 25 | |
| 26 | using Syndication::RDF::Property; |
| 27 | using Syndication::RDF::PropertyPtr; |
| 28 | |
| 29 | namespace Syndication |
| 30 | { |
| 31 | ItemRDFImpl::ItemRDFImpl(const Syndication::RDF::Item &item) |
| 32 | : m_item(item) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | QString ItemRDFImpl::title() const |
| 37 | { |
| 38 | return m_item.title(); |
| 39 | } |
| 40 | |
| 41 | QString ItemRDFImpl::link() const |
| 42 | { |
| 43 | return m_item.link(); |
| 44 | } |
| 45 | |
| 46 | QString ItemRDFImpl::description() const |
| 47 | { |
| 48 | return m_item.description(); |
| 49 | } |
| 50 | |
| 51 | QString ItemRDFImpl::content() const |
| 52 | { |
| 53 | return m_item.encodedContent(); |
| 54 | } |
| 55 | |
| 56 | QList<PersonPtr> ItemRDFImpl::authors() const |
| 57 | { |
| 58 | QList<PersonPtr> list; |
| 59 | |
| 60 | const QStringList people = m_item.dc().creators() + m_item.dc().contributors(); |
| 61 | |
| 62 | for (const auto &person : people) { |
| 63 | PersonPtr ptr = personFromString(str: person); |
| 64 | if (!ptr->isNull()) { |
| 65 | list.append(t: ptr); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return list; |
| 70 | } |
| 71 | |
| 72 | QString ItemRDFImpl::language() const |
| 73 | { |
| 74 | return m_item.dc().language(); |
| 75 | } |
| 76 | |
| 77 | QString ItemRDFImpl::id() const |
| 78 | { |
| 79 | if (!m_item.resource()->isAnon()) { |
| 80 | return m_item.resource()->uri(); |
| 81 | } else { |
| 82 | return QLatin1String("hash:") + calcMD5Sum(str: title() + description() + link() + content()); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | time_t ItemRDFImpl::datePublished() const |
| 87 | { |
| 88 | return m_item.dc().date(); |
| 89 | } |
| 90 | |
| 91 | time_t ItemRDFImpl::dateUpdated() const |
| 92 | { |
| 93 | return m_item.dc().date(); |
| 94 | } |
| 95 | |
| 96 | QList<Syndication::EnclosurePtr> ItemRDFImpl::enclosures() const |
| 97 | { |
| 98 | // return empty list |
| 99 | return QList<Syndication::EnclosurePtr>(); |
| 100 | } |
| 101 | |
| 102 | QList<Syndication::CategoryPtr> ItemRDFImpl::categories() const |
| 103 | { |
| 104 | // return empty list |
| 105 | return QList<Syndication::CategoryPtr>(); |
| 106 | } |
| 107 | |
| 108 | int ItemRDFImpl::commentsCount() const |
| 109 | { |
| 110 | PropertyPtr prop(new Property(slashNamespace() + QLatin1String("comments"))); |
| 111 | QString cstr = m_item.resource()->property(property: prop)->asString(); |
| 112 | bool ok = false; |
| 113 | int comments = cstr.toInt(ok: &ok); |
| 114 | return ok ? comments : -1; |
| 115 | return -1; |
| 116 | } |
| 117 | |
| 118 | QString ItemRDFImpl::commentsLink() const |
| 119 | { |
| 120 | return QString(); |
| 121 | } |
| 122 | |
| 123 | QString ItemRDFImpl::commentsFeed() const |
| 124 | { |
| 125 | PropertyPtr prop(new Property(commentApiNamespace() + QLatin1String("commentRss"))); |
| 126 | return m_item.resource()->property(property: prop)->asString(); |
| 127 | } |
| 128 | |
| 129 | QString ItemRDFImpl::commentPostUri() const |
| 130 | { |
| 131 | PropertyPtr prop(new Property(commentApiNamespace() + QLatin1String("comment"))); |
| 132 | return m_item.resource()->property(property: prop)->asString(); |
| 133 | } |
| 134 | |
| 135 | Syndication::SpecificItemPtr ItemRDFImpl::specificItem() const |
| 136 | { |
| 137 | return Syndication::SpecificItemPtr(new Syndication::RDF::Item(m_item)); |
| 138 | } |
| 139 | |
| 140 | QMultiMap<QString, QDomElement> ItemRDFImpl::additionalProperties() const |
| 141 | { |
| 142 | return QMultiMap<QString, QDomElement>(); |
| 143 | } |
| 144 | |
| 145 | } // namespace Syndication |
| 146 |
