| 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 "constants.h" |
| 9 | #include "tools.h" |
| 10 | |
| 11 | #include <syndication/elementwrapper.h> |
| 12 | #include <syndication/tools.h> |
| 13 | |
| 14 | #include <QDomElement> |
| 15 | #include <QString> |
| 16 | |
| 17 | namespace Syndication |
| 18 | { |
| 19 | namespace Atom |
| 20 | { |
| 21 | QString extractAtomText(const Syndication::ElementWrapper &parent, const QString &tagname) |
| 22 | { |
| 23 | QString str; |
| 24 | |
| 25 | QDomElement el = parent.firstElementByTagNameNS(nsURI: atom1Namespace(), tagName: tagname); |
| 26 | |
| 27 | bool isCDATA = el.firstChild().isCDATASection(); |
| 28 | |
| 29 | QString type = el.attribute(QStringLiteral("type"), QStringLiteral( "text")); |
| 30 | |
| 31 | if (type == QLatin1String("text")) { |
| 32 | str = parent.extractElementTextNS(namespaceURI: atom1Namespace(), localName: tagname).trimmed(); |
| 33 | if (isCDATA) { |
| 34 | str = resolveEntities(str); |
| 35 | } |
| 36 | |
| 37 | str = escapeSpecialCharacters(str); |
| 38 | } else if (type == QLatin1String("html")) { |
| 39 | str = parent.extractElementTextNS(namespaceURI: atom1Namespace(), localName: tagname).trimmed(); |
| 40 | } else if (type == QLatin1String("xhtml")) { |
| 41 | str = ElementWrapper::childNodesAsXML(parent: el).trimmed(); |
| 42 | } |
| 43 | |
| 44 | return str; |
| 45 | } |
| 46 | |
| 47 | } // namespace Atom |
| 48 | } // namespace Syndication |
| 49 |
