| 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 "link.h" |
| 9 | #include "constants.h" |
| 10 | |
| 11 | #include <QString> |
| 12 | |
| 13 | namespace Syndication |
| 14 | { |
| 15 | namespace Atom |
| 16 | { |
| 17 | Link::Link() |
| 18 | : ElementWrapper() |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | Link::Link(const QDomElement &element) |
| 23 | : ElementWrapper(element) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | QString Link::href() const |
| 28 | { |
| 29 | return completeURI(uri: attribute(QStringLiteral("href" ))); |
| 30 | } |
| 31 | |
| 32 | QString Link::rel() const |
| 33 | { |
| 34 | //"alternate" is default |
| 35 | return attribute(QStringLiteral("rel" ), QStringLiteral("alternate" )); |
| 36 | } |
| 37 | |
| 38 | QString Link::type() const |
| 39 | { |
| 40 | return attribute(QStringLiteral("type" )); |
| 41 | } |
| 42 | |
| 43 | QString Link::hrefLanguage() const |
| 44 | { |
| 45 | return attribute(QStringLiteral("hreflang" )); |
| 46 | } |
| 47 | |
| 48 | QString Link::title() const |
| 49 | { |
| 50 | return attribute(QStringLiteral("title" )); |
| 51 | } |
| 52 | |
| 53 | uint Link::length() const |
| 54 | { |
| 55 | QString lengthStr = attribute(QStringLiteral("length" )); |
| 56 | |
| 57 | bool ok; |
| 58 | uint c = lengthStr.toUInt(ok: &ok); |
| 59 | return ok ? c : 0; |
| 60 | } |
| 61 | |
| 62 | QString Link::debugInfo() const |
| 63 | { |
| 64 | QString info = QLatin1String("### Link: ###################\n" ); |
| 65 | if (!title().isEmpty()) { |
| 66 | info += QLatin1String("title: #" ) + title() + QLatin1String("#\n" ); |
| 67 | } |
| 68 | if (!href().isEmpty()) { |
| 69 | info += QLatin1String("href: #" ) + href() + QLatin1String("#\n" ); |
| 70 | } |
| 71 | if (!rel().isEmpty()) { |
| 72 | info += QLatin1String("rel: #" ) + rel() + QLatin1String("#\n" ); |
| 73 | } |
| 74 | if (!type().isEmpty()) { |
| 75 | info += QLatin1String("type: #" ) + type() + QLatin1String("#\n" ); |
| 76 | } |
| 77 | if (length() != 0) { |
| 78 | info += QLatin1String("length: #" ) + QString::number(length()) + QLatin1String("#\n" ); |
| 79 | } |
| 80 | if (!hrefLanguage().isEmpty()) { |
| 81 | info += QLatin1String("hrefLanguage: #" ) + hrefLanguage() + QLatin1String("#\n" ); |
| 82 | } |
| 83 | info += QLatin1String("### Link end ################\n" ); |
| 84 | return info; |
| 85 | } |
| 86 | |
| 87 | } // namespace Atom |
| 88 | } // namespace Syndication |
| 89 | |