File indexing completed on 2024-10-06 03:44:25

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 "link.h"
0009 #include "constants.h"
0010 
0011 #include <QString>
0012 
0013 namespace Syndication
0014 {
0015 namespace Atom
0016 {
0017 Link::Link()
0018     : ElementWrapper()
0019 {
0020 }
0021 
0022 Link::Link(const QDomElement &element)
0023     : ElementWrapper(element)
0024 {
0025 }
0026 
0027 QString Link::href() const
0028 {
0029     return completeURI(attribute(QStringLiteral("href")));
0030 }
0031 
0032 QString Link::rel() const
0033 {
0034     //"alternate" is default
0035     return attribute(QStringLiteral("rel"), QStringLiteral("alternate"));
0036 }
0037 
0038 QString Link::type() const
0039 {
0040     return attribute(QStringLiteral("type"));
0041 }
0042 
0043 QString Link::hrefLanguage() const
0044 {
0045     return attribute(QStringLiteral("hreflang"));
0046 }
0047 
0048 QString Link::title() const
0049 {
0050     return attribute(QStringLiteral("title"));
0051 }
0052 
0053 uint Link::length() const
0054 {
0055     QString lengthStr = attribute(QStringLiteral("length"));
0056 
0057     bool ok;
0058     uint c = lengthStr.toUInt(&ok);
0059     return ok ? c : 0;
0060 }
0061 
0062 QString Link::debugInfo() const
0063 {
0064     QString info = QLatin1String("### Link: ###################\n");
0065     if (!title().isEmpty()) {
0066         info += QLatin1String("title: #") + title() + QLatin1String("#\n");
0067     }
0068     if (!href().isEmpty()) {
0069         info += QLatin1String("href: #") + href() + QLatin1String("#\n");
0070     }
0071     if (!rel().isEmpty()) {
0072         info += QLatin1String("rel: #") + rel() + QLatin1String("#\n");
0073     }
0074     if (!type().isEmpty()) {
0075         info += QLatin1String("type: #") + type() + QLatin1String("#\n");
0076     }
0077     if (length() != 0) {
0078         info += QLatin1String("length: #") + QString::number(length()) + QLatin1String("#\n");
0079     }
0080     if (!hrefLanguage().isEmpty()) {
0081         info += QLatin1String("hrefLanguage: #") + hrefLanguage() + QLatin1String("#\n");
0082     }
0083     info += QLatin1String("### Link end ################\n");
0084     return info;
0085 }
0086 
0087 } // namespace Atom
0088 } // namespace Syndication