File indexing completed on 2024-12-08 09:46:40
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 #ifndef SYNDICATION_ABSTRACTPARSER_H 0009 #define SYNDICATION_ABSTRACTPARSER_H 0010 0011 #include <syndication/specificdocument.h> 0012 0013 #include "syndication_export.h" 0014 0015 class QString; 0016 0017 namespace Syndication 0018 { 0019 class DocumentSource; 0020 0021 /** 0022 * Interface for all parsers. The parsers for the various formats must 0023 * implement this interface and register themselves at the ParserRegistry. 0024 * 0025 * @author Frank Osterfeld 0026 */ 0027 class SYNDICATION_EXPORT AbstractParser 0028 { 0029 public: 0030 /** 0031 * virtual destructor 0032 */ 0033 virtual ~AbstractParser(); 0034 0035 /** 0036 * Lets the parser check if it can parse the passed source. 0037 * Parser implementations should do a _quick_ check for the file 0038 * format (i.e. check for feed format and version number in the root 0039 * element) to find out if the source is in a supported format. They 0040 * should _not_ completely parse the document to test for full 0041 * compliance to the format specification. 0042 * 0043 * @param source the document source to be checked 0044 * @return whether @c source seems to be in a format supported by the 0045 * parser 0046 */ 0047 virtual bool accept(const DocumentSource &source) const = 0; 0048 0049 /** 0050 * Lets the parser parse a document source. The parser returns a 0051 * valid document instance if successful, or an invalid one if 0052 * not. 0053 * 0054 * @see SpecificDocument::isValid() 0055 * @param source The document source to be parsed 0056 * @return a newly created document parsed from @c source 0057 */ 0058 virtual SpecificDocumentPtr parse(const DocumentSource &source) const = 0; 0059 0060 /** 0061 * Returns the name of the format supported by this 0062 * parser. 0063 * 0064 * @return a string like "rss2", "atom" or "rdf" 0065 */ 0066 virtual QString format() const = 0; 0067 }; 0068 0069 } // namespace Syndication 0070 0071 #endif // SYNDICATION_ABSTRACTPARSER_H