File indexing completed on 2024-11-10 12:29:10

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 "constants.h"
0009 #include "tools.h"
0010 
0011 #include <syndication/elementwrapper.h>
0012 #include <syndication/tools.h>
0013 
0014 #include <QDomElement>
0015 #include <QString>
0016 
0017 namespace Syndication
0018 {
0019 namespace Atom
0020 {
0021 QString extractAtomText(const Syndication::ElementWrapper &parent, const QString &tagname)
0022 {
0023     QString str;
0024 
0025     QDomElement el = parent.firstElementByTagNameNS(atom1Namespace(), tagname);
0026 
0027     bool isCDATA = el.firstChild().isCDATASection();
0028 
0029     QString type = el.attribute(QStringLiteral("type"), QStringLiteral("text"));
0030 
0031     if (type == QLatin1String("text")) {
0032         str = parent.extractElementTextNS(atom1Namespace(), tagname).trimmed();
0033         if (isCDATA) {
0034             str = resolveEntities(str);
0035         }
0036 
0037         str = escapeSpecialCharacters(str);
0038     } else if (type == QLatin1String("html")) {
0039         str = parent.extractElementTextNS(atom1Namespace(), tagname).trimmed();
0040     } else if (type == QLatin1String("xhtml")) {
0041         str = ElementWrapper::childNodesAsXML(el).trimmed();
0042     }
0043 
0044     return str;
0045 }
0046 
0047 } // namespace Atom
0048 } // namespace Syndication