| 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 "item.h" |
| 9 | #include "contentvocab.h" |
| 10 | #include "document.h" |
| 11 | #include "dublincore.h" |
| 12 | #include "model.h" |
| 13 | #include "rssvocab.h" |
| 14 | #include "statement.h" |
| 15 | |
| 16 | #include <specificitemvisitor.h> |
| 17 | #include <tools.h> |
| 18 | |
| 19 | #include <QString> |
| 20 | |
| 21 | namespace Syndication |
| 22 | { |
| 23 | namespace RDF |
| 24 | { |
| 25 | class SYNDICATION_NO_EXPORT Item::Private |
| 26 | { |
| 27 | public: |
| 28 | DocumentPtr doc; |
| 29 | }; |
| 30 | |
| 31 | Item::Item() |
| 32 | : ResourceWrapper() |
| 33 | , d(new Private) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | Item::Item(ResourcePtr resource, DocumentPtr doc) |
| 38 | : ResourceWrapper(resource) |
| 39 | , d(new Private) |
| 40 | { |
| 41 | d->doc = doc; |
| 42 | } |
| 43 | |
| 44 | Item::Item(const Item &other) |
| 45 | : ResourceWrapper(other) |
| 46 | , SpecificItem(other) |
| 47 | , d(new Private) |
| 48 | { |
| 49 | *d = *(other.d); |
| 50 | } |
| 51 | |
| 52 | Item::~Item() = default; |
| 53 | |
| 54 | Item &Item::operator=(const Item &other) |
| 55 | { |
| 56 | ResourceWrapper::operator=(other); |
| 57 | *d = *(other.d); |
| 58 | return *this; |
| 59 | } |
| 60 | |
| 61 | bool Item::operator==(const Item &other) const |
| 62 | { |
| 63 | return ResourceWrapper::operator==(other); |
| 64 | } |
| 65 | |
| 66 | QString Item::title() const |
| 67 | { |
| 68 | if (!d->doc) { |
| 69 | return originalTitle(); |
| 70 | } |
| 71 | |
| 72 | bool containsMarkup = false; |
| 73 | d->doc->getItemTitleFormatInfo(containsMarkup: &containsMarkup); |
| 74 | |
| 75 | return normalize(str: originalTitle(), isCDATA: false, containsMarkup); |
| 76 | } |
| 77 | |
| 78 | QString Item::description() const |
| 79 | { |
| 80 | if (!d->doc) { |
| 81 | return originalDescription(); |
| 82 | } |
| 83 | |
| 84 | bool containsMarkup = false; |
| 85 | d->doc->getItemDescriptionFormatInfo(containsMarkup: &containsMarkup); |
| 86 | |
| 87 | return normalize(str: originalDescription(), isCDATA: false, containsMarkup); |
| 88 | } |
| 89 | |
| 90 | QString Item::link() const |
| 91 | { |
| 92 | return resource()->property(property: RSSVocab::self()->link())->asString(); |
| 93 | } |
| 94 | |
| 95 | DublinCore Item::dc() const |
| 96 | { |
| 97 | return DublinCore(resource()); |
| 98 | } |
| 99 | |
| 100 | QString Item::encodedContent() const |
| 101 | { |
| 102 | return resource()->property(property: ContentVocab::self()->encoded())->asString(); |
| 103 | } |
| 104 | |
| 105 | QString Item::originalTitle() const |
| 106 | { |
| 107 | return resource()->property(property: RSSVocab::self()->title())->asString(); |
| 108 | } |
| 109 | |
| 110 | QString Item::originalDescription() const |
| 111 | { |
| 112 | return resource()->property(property: RSSVocab::self()->description())->asString(); |
| 113 | } |
| 114 | |
| 115 | QString Item::debugInfo() const |
| 116 | { |
| 117 | QString info = QLatin1String("### Item: ###################\n"); |
| 118 | info += QLatin1String("title: #") + title() + QLatin1String( "#\n"); |
| 119 | info += QLatin1String("link: #") + link() + QLatin1String( "#\n"); |
| 120 | info += QLatin1String("description: #") + description() + QLatin1String( "#\n"); |
| 121 | info += QLatin1String("content:encoded: #") + encodedContent() + QLatin1String( "#\n"); |
| 122 | info += dc().debugInfo(); |
| 123 | info += QLatin1String("### Item end ################\n"); |
| 124 | return info; |
| 125 | } |
| 126 | |
| 127 | bool Item::accept(SpecificItemVisitor *visitor) |
| 128 | { |
| 129 | return visitor->visitRDFItem(item: this); |
| 130 | } |
| 131 | |
| 132 | } // namespace RDF |
| 133 | } // namespace Syndication |
| 134 |
