Syndication

link.cpp
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
13namespace Syndication
14{
15namespace Atom
16{
19{
20}
21
22Link::Link(const QDomElement &element)
23 : ElementWrapper(element)
24{
25}
26
28{
29 return completeURI(attribute(QStringLiteral("href")));
30}
31
33{
34 //"alternate" is default
35 return attribute(QStringLiteral("rel"), QStringLiteral("alternate"));
36}
37
39{
40 return attribute(QStringLiteral("type"));
41}
42
44{
45 return attribute(QStringLiteral("hreflang"));
46}
47
49{
50 return attribute(QStringLiteral("title"));
51}
52
53uint Link::length() const
54{
55 QString lengthStr = attribute(QStringLiteral("length"));
56
57 bool ok;
58 uint c = lengthStr.toUInt(&ok);
59 return ok ? c : 0;
60}
61
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
A wrapper for XML elements.
QString completeURI(const QString &uri) const
completes relative URIs with a prefix specified via xml:base.
QString attribute(const QString &name, const QString &defValue=QString()) const
Returns the attribute called name.
QString number(double n, char format, int precision)
uint toUInt(bool *ok, int base) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:09:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.