File indexing completed on 2024-04-21 04:01:04

0001 /*
0002     This file is part of the syndication library
0003     SPDX-FileCopyrightText: 2005 Frank Osterfeld <osterfeld@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "parser.h"
0009 #include "document.h"
0010 
0011 #include <documentsource.h>
0012 
0013 #include <QDomDocument>
0014 #include <QString>
0015 
0016 namespace Syndication
0017 {
0018 namespace RSS2
0019 {
0020 class SYNDICATION_NO_EXPORT Parser::ParserPrivate
0021 {
0022 };
0023 
0024 bool Parser::accept(const Syndication::DocumentSource &source) const
0025 {
0026     QDomDocument doc = source.asDomDocument();
0027     if (doc.isNull()) {
0028         return false;
0029     }
0030 
0031     QDomNode root = doc.namedItem(QStringLiteral("rss")).toElement();
0032 
0033     return !root.isNull();
0034 }
0035 
0036 Syndication::SpecificDocumentPtr Parser::parse(const DocumentSource &source) const
0037 {
0038     return DocumentPtr(new Document(Document::fromXML(source.asDomDocument())));
0039 }
0040 
0041 QString Parser::format() const
0042 {
0043     return QStringLiteral("rss2");
0044 }
0045 
0046 Parser::Parser()
0047     : d(nullptr)
0048 {
0049     Q_UNUSED(d) // silence -Wunused-private-field
0050 }
0051 
0052 Parser::Parser(const Parser &other)
0053     : AbstractParser(other)
0054     , d(nullptr)
0055 {
0056 }
0057 Parser::~Parser() = default;
0058 
0059 Parser &Parser::operator=(const Parser & /*other*/)
0060 {
0061     return *this;
0062 }
0063 
0064 } // namespace RSS2
0065 } // namespace Syndication