| 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 "dublincore.h" |
| 9 | #include "dublincorevocab.h" |
| 10 | #include "property.h" |
| 11 | #include "statement.h" |
| 12 | |
| 13 | #include <tools.h> |
| 14 | |
| 15 | #include <QList> |
| 16 | #include <QString> |
| 17 | |
| 18 | namespace Syndication |
| 19 | { |
| 20 | namespace RDF |
| 21 | { |
| 22 | DublinCore::DublinCore(ResourcePtr resource) |
| 23 | : ResourceWrapper(resource) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | DublinCore::~DublinCore() |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | QString DublinCore::contributor() const |
| 32 | { |
| 33 | return resource()->property(property: DublinCoreVocab::self()->contributor())->asString(); |
| 34 | } |
| 35 | |
| 36 | QStringList DublinCore::contributors() const |
| 37 | { |
| 38 | QStringList res; |
| 39 | QList<StatementPtr> list = resource()->properties(property: DublinCoreVocab::self()->contributor()); |
| 40 | QList<StatementPtr>::ConstIterator it = list.constBegin(); |
| 41 | QList<StatementPtr>::ConstIterator end = list.constEnd(); |
| 42 | for (; it != end; ++it) { |
| 43 | const QString str = (*it)->asString(); |
| 44 | if (!str.isNull()) { |
| 45 | res.append(t: str); |
| 46 | } |
| 47 | } |
| 48 | return res; |
| 49 | } |
| 50 | |
| 51 | QString DublinCore::coverage() const |
| 52 | { |
| 53 | return resource()->property(property: DublinCoreVocab::self()->coverage())->asString(); |
| 54 | } |
| 55 | |
| 56 | QString DublinCore::creator() const |
| 57 | { |
| 58 | return resource()->property(property: DublinCoreVocab::self()->creator())->asString(); |
| 59 | } |
| 60 | |
| 61 | QStringList DublinCore::creators() const |
| 62 | { |
| 63 | QStringList res; |
| 64 | QList<StatementPtr> list = resource()->properties(property: DublinCoreVocab::self()->creator()); |
| 65 | QList<StatementPtr>::ConstIterator it = list.constBegin(); |
| 66 | QList<StatementPtr>::ConstIterator end = list.constEnd(); |
| 67 | for (; it != end; ++it) { |
| 68 | const QString str = (*it)->asString(); |
| 69 | if (!str.isNull()) { |
| 70 | res.append(t: str); |
| 71 | } |
| 72 | } |
| 73 | return res; |
| 74 | } |
| 75 | |
| 76 | time_t DublinCore::date() const |
| 77 | { |
| 78 | QString str = resource()->property(property: DublinCoreVocab::self()->date())->asString(); |
| 79 | return parseDate(str, hint: ISODate); |
| 80 | } |
| 81 | |
| 82 | QString DublinCore::description() const |
| 83 | { |
| 84 | return resource()->property(property: DublinCoreVocab::self()->description())->asString(); |
| 85 | } |
| 86 | |
| 87 | QString DublinCore::format() const |
| 88 | { |
| 89 | return resource()->property(property: DublinCoreVocab::self()->format())->asString(); |
| 90 | } |
| 91 | |
| 92 | QString DublinCore::identifier() const |
| 93 | { |
| 94 | return resource()->property(property: DublinCoreVocab::self()->identifier())->asString(); |
| 95 | } |
| 96 | |
| 97 | QString DublinCore::language() const |
| 98 | { |
| 99 | return resource()->property(property: DublinCoreVocab::self()->language())->asString(); |
| 100 | } |
| 101 | |
| 102 | QString DublinCore::publisher() const |
| 103 | { |
| 104 | return resource()->property(property: DublinCoreVocab::self()->publisher())->asString(); |
| 105 | } |
| 106 | |
| 107 | QString DublinCore::relation() const |
| 108 | { |
| 109 | return resource()->property(property: DublinCoreVocab::self()->relation())->asString(); |
| 110 | } |
| 111 | |
| 112 | QString DublinCore::rights() const |
| 113 | { |
| 114 | return resource()->property(property: DublinCoreVocab::self()->rights())->asString(); |
| 115 | } |
| 116 | |
| 117 | QString DublinCore::source() const |
| 118 | { |
| 119 | return resource()->property(property: DublinCoreVocab::self()->source())->asString(); |
| 120 | } |
| 121 | |
| 122 | QString DublinCore::subject() const |
| 123 | { |
| 124 | return resource()->property(property: DublinCoreVocab::self()->subject())->asString(); |
| 125 | } |
| 126 | |
| 127 | QStringList DublinCore::subjects() const |
| 128 | { |
| 129 | QStringList res; |
| 130 | QList<StatementPtr> list = resource()->properties(property: DublinCoreVocab::self()->subject()); |
| 131 | QList<StatementPtr>::ConstIterator it = list.constBegin(); |
| 132 | QList<StatementPtr>::ConstIterator end = list.constEnd(); |
| 133 | for (; it != end; ++it) { |
| 134 | QString str = (*it)->asString(); |
| 135 | if (!str.isNull()) { |
| 136 | res.append(t: str); |
| 137 | } |
| 138 | } |
| 139 | return res; |
| 140 | } |
| 141 | |
| 142 | QString DublinCore::title() const |
| 143 | { |
| 144 | return resource()->property(property: DublinCoreVocab::self()->title())->asString(); |
| 145 | } |
| 146 | |
| 147 | QString DublinCore::type() const |
| 148 | { |
| 149 | return resource()->property(property: DublinCoreVocab::self()->type())->asString(); |
| 150 | } |
| 151 | |
| 152 | QString DublinCore::debugInfo() const |
| 153 | { |
| 154 | QString info; |
| 155 | if (!contributor().isNull()) { |
| 156 | info += QStringLiteral("dc:contributor: #%1#\n").arg(a: contributor()); |
| 157 | } |
| 158 | if (!coverage().isNull()) { |
| 159 | info += QStringLiteral("dc:coverage: #%1#\n").arg(a: coverage()); |
| 160 | } |
| 161 | if (!creator().isNull()) { |
| 162 | info += QStringLiteral("dc:creator: #%1#\n").arg(a: creator()); |
| 163 | } |
| 164 | |
| 165 | const QString ddate = dateTimeToString(date: date()); |
| 166 | if (!ddate.isNull()) { |
| 167 | info += QStringLiteral("dc:date: #%1#\n").arg(a: ddate); |
| 168 | } |
| 169 | |
| 170 | if (!description().isNull()) { |
| 171 | info += QStringLiteral("dc:description: #%1#\n").arg(a: description()); |
| 172 | } |
| 173 | if (!format().isNull()) { |
| 174 | info += QStringLiteral("dc:format: #%1#\n").arg(a: format()); |
| 175 | } |
| 176 | if (!identifier().isNull()) { |
| 177 | info += QStringLiteral("dc:identifier: #%1#\n").arg(a: identifier()); |
| 178 | } |
| 179 | if (!language().isNull()) { |
| 180 | info += QStringLiteral("dc:language: #%1#\n").arg(a: language()); |
| 181 | } |
| 182 | if (!publisher().isNull()) { |
| 183 | info += QStringLiteral("dc:publisher: #%1#\n").arg(a: publisher()); |
| 184 | } |
| 185 | if (!relation().isNull()) { |
| 186 | info += QStringLiteral("dc:relation: #%1#\n").arg(a: relation()); |
| 187 | } |
| 188 | if (!rights().isNull()) { |
| 189 | info += QStringLiteral("dc:rights: #%1#\n").arg(a: rights()); |
| 190 | } |
| 191 | if (!source().isNull()) { |
| 192 | info += QStringLiteral("dc:source: #%1#\n").arg(a: source()); |
| 193 | } |
| 194 | if (!subject().isNull()) { |
| 195 | info += QStringLiteral("dc:subject: #%1#\n").arg(a: subject()); |
| 196 | } |
| 197 | if (!title().isNull()) { |
| 198 | info += QStringLiteral("dc:title: #%1#\n").arg(a: title()); |
| 199 | } |
| 200 | if (!type().isNull()) { |
| 201 | info += QStringLiteral("dc:type: #%1#\n").arg(a: type()); |
| 202 | } |
| 203 | return info; |
| 204 | } |
| 205 | |
| 206 | } // namespace RDF |
| 207 | } // namespace Syndication |
| 208 |
