File indexing completed on 2024-04-28 15:34:24

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 "item.h"
0009 #include "contentvocab.h"
0010 #include "document.h"
0011 #include "dublincore.h"
0012 #include "model.h"
0013 #include "rssvocab.h"
0014 #include "statement.h"
0015 
0016 #include <specificitemvisitor.h>
0017 #include <tools.h>
0018 
0019 #include <QString>
0020 
0021 namespace Syndication
0022 {
0023 namespace RDF
0024 {
0025 class SYNDICATION_NO_EXPORT Item::Private
0026 {
0027 public:
0028     DocumentPtr doc;
0029 };
0030 
0031 Item::Item()
0032     : ResourceWrapper()
0033     , d(new Private)
0034 {
0035 }
0036 
0037 Item::Item(ResourcePtr resource, DocumentPtr doc)
0038     : ResourceWrapper(resource)
0039     , d(new Private)
0040 {
0041     d->doc = doc;
0042 }
0043 
0044 Item::Item(const Item &other)
0045     : ResourceWrapper(other)
0046     , SpecificItem(other)
0047     , d(new Private)
0048 {
0049     *d = *(other.d);
0050 }
0051 
0052 Item::~Item()
0053 {
0054     delete d;
0055 }
0056 
0057 Item &Item::operator=(const Item &other)
0058 {
0059     ResourceWrapper::operator=(other);
0060     *d = *(other.d);
0061     return *this;
0062 }
0063 
0064 bool Item::operator==(const Item &other) const
0065 {
0066     return ResourceWrapper::operator==(other);
0067 }
0068 
0069 QString Item::title() const
0070 {
0071     if (!d->doc) {
0072         return originalTitle();
0073     }
0074 
0075     bool containsMarkup = false;
0076     d->doc->getItemTitleFormatInfo(&containsMarkup);
0077 
0078     return normalize(originalTitle(), false, containsMarkup);
0079 }
0080 
0081 QString Item::description() const
0082 {
0083     if (!d->doc) {
0084         return originalDescription();
0085     }
0086 
0087     bool containsMarkup = false;
0088     d->doc->getItemDescriptionFormatInfo(&containsMarkup);
0089 
0090     return normalize(originalDescription(), false, containsMarkup);
0091 }
0092 
0093 QString Item::link() const
0094 {
0095     return resource()->property(RSSVocab::self()->link())->asString();
0096 }
0097 
0098 DublinCore Item::dc() const
0099 {
0100     return DublinCore(resource());
0101 }
0102 
0103 QString Item::encodedContent() const
0104 {
0105     return resource()->property(ContentVocab::self()->encoded())->asString();
0106 }
0107 
0108 QString Item::originalTitle() const
0109 {
0110     return resource()->property(RSSVocab::self()->title())->asString();
0111 }
0112 
0113 QString Item::originalDescription() const
0114 {
0115     return resource()->property(RSSVocab::self()->description())->asString();
0116 }
0117 
0118 QString Item::debugInfo() const
0119 {
0120     QString info = QLatin1String("### Item: ###################\n");
0121     info += QLatin1String("title: #") + title() + QLatin1String("#\n");
0122     info += QLatin1String("link: #") + link() + QLatin1String("#\n");
0123     info += QLatin1String("description: #") + description() + QLatin1String("#\n");
0124     info += QLatin1String("content:encoded: #") + encodedContent() + QLatin1String("#\n");
0125     info += dc().debugInfo();
0126     info += QLatin1String("### Item end ################\n");
0127     return info;
0128 }
0129 
0130 bool Item::accept(SpecificItemVisitor *visitor)
0131 {
0132     return visitor->visitRDFItem(this);
0133 }
0134 
0135 } // namespace RDF
0136 } // namespace Syndication