| 1 | /* |
| 2 | This file is part of the syndication library |
| 3 | SPDX-FileCopyrightText: 2005 Frank Osterfeld <osterfeld@kde.org> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #ifndef SYNDICATION_ABSTRACTPARSER_H |
| 9 | #define SYNDICATION_ABSTRACTPARSER_H |
| 10 | |
| 11 | #include "specificdocument.h" |
| 12 | |
| 13 | #include "syndication_export.h" |
| 14 | |
| 15 | class QString; |
| 16 | |
| 17 | namespace Syndication |
| 18 | { |
| 19 | class DocumentSource; |
| 20 | |
| 21 | /*! |
| 22 | * \class Syndication::AbstractParser |
| 23 | * \inmodule Syndication |
| 24 | * \inheaderfile Syndication/AbstractParser |
| 25 | * |
| 26 | * \brief Interface for all parsers. |
| 27 | * |
| 28 | * The parsers for the various formats must |
| 29 | * implement this interface and register themselves at the ParserRegistry. |
| 30 | */ |
| 31 | class SYNDICATION_EXPORT AbstractParser |
| 32 | { |
| 33 | public: |
| 34 | virtual ~AbstractParser(); |
| 35 | |
| 36 | /*! |
| 37 | * Lets the parser check if it can parse the passed source. |
| 38 | * |
| 39 | * Parser implementations should do a _quick_ check for the file |
| 40 | * format (i.e. check for feed format and version number in the root |
| 41 | * element) to find out if the source is in a supported format. They |
| 42 | * should _not_ completely parse the document to test for full |
| 43 | * compliance to the format specification. |
| 44 | * |
| 45 | * \a source the document source to be checked |
| 46 | * |
| 47 | * Returns whether \a source seems to be in a format supported by the |
| 48 | * parser |
| 49 | */ |
| 50 | virtual bool accept(const DocumentSource &source) const = 0; |
| 51 | |
| 52 | /*! |
| 53 | * Lets the parser parse a document source. |
| 54 | * |
| 55 | * The parser returns a |
| 56 | * valid document instance if successful, or an invalid one if |
| 57 | * not. |
| 58 | * |
| 59 | * \sa SpecificDocument::isValid() |
| 60 | * |
| 61 | * \a source The document source to be parsed |
| 62 | * |
| 63 | * Returns a newly created document parsed from \a source |
| 64 | */ |
| 65 | virtual SpecificDocumentPtr parse(const DocumentSource &source) const = 0; |
| 66 | |
| 67 | /*! |
| 68 | * Returns the name of the format supported by this |
| 69 | * parser. |
| 70 | * |
| 71 | * Returns a string like "rss2", "atom" or "rdf" |
| 72 | */ |
| 73 | virtual QString format() const = 0; |
| 74 | }; |
| 75 | |
| 76 | } // namespace Syndication |
| 77 | |
| 78 | #endif // SYNDICATION_ABSTRACTPARSER_H |
| 79 | |