1 | /* |
2 | * This file is part of the syndication library |
3 | * |
4 | * Copyright (C) 2005 Frank Osterfeld <osterfeld@kde.org> |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public License |
17 | * along with this library; see the file COPYING.LIB. If not, write to |
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | * Boston, MA 02110-1301, USA. |
20 | * |
21 | */ |
22 | |
23 | #ifndef SYNDICATION_ABSTRACTPARSER_H |
24 | #define SYNDICATION_ABSTRACTPARSER_H |
25 | |
26 | #include <syndication/specificdocument.h> |
27 | |
28 | #include "ksyndication_export.h" |
29 | |
30 | class QString; |
31 | |
32 | namespace Syndication { |
33 | |
34 | class DocumentSource; |
35 | |
36 | /** |
37 | * Interface for all parsers. The parsers for the various formats must |
38 | * implement this interface and register themselves at the ParserRegistry. |
39 | * |
40 | * @author Frank Osterfeld |
41 | */ |
42 | class SYNDICATION_EXPORT AbstractParser |
43 | { |
44 | public: |
45 | |
46 | /** |
47 | * virtual destructor |
48 | */ |
49 | virtual ~AbstractParser(); |
50 | |
51 | /** |
52 | * Lets the parser check if it can parse the passed source. |
53 | * Parser implementations should do a _quick_ check for the file |
54 | * format (i.e. check for feed format and version number in the root |
55 | * element) to find out if the source is in a supported format. They |
56 | * should _not_ completely parse the document to test for full |
57 | * compliance to the format specification. |
58 | * |
59 | * @param source the document source to be checked |
60 | * @return whether @c source seems to be in a format supported by the |
61 | * parser |
62 | */ |
63 | virtual bool accept(const DocumentSource& source) const = 0; |
64 | |
65 | /** |
66 | * Lets the parser parse a document source. The parser returns a |
67 | * valid document instance if successful, or an invalid one if |
68 | * not. |
69 | * |
70 | * @see SpecificDocument::isValid() |
71 | * @param source The document source to be parsed |
72 | * @return a newly created document parsed from @c source |
73 | */ |
74 | virtual SpecificDocumentPtr parse(const DocumentSource& source) const = 0; |
75 | |
76 | /** |
77 | * Returns the name of the format supported by this |
78 | * parser. |
79 | * |
80 | * @return a string like "rss2", "atom" or "rdf" |
81 | */ |
82 | virtual QString format() const = 0; |
83 | }; |
84 | |
85 | } // namespace Syndication |
86 | |
87 | #endif // SYNDICATION_ABSTRACTPARSER_H |
88 | |