1 | /* |
---|---|
2 | This file is part of the syndication library |
3 | SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #include "global.h" |
9 | #include "documentsource.h" |
10 | #include "parsercollectionimpl.h" |
11 | |
12 | #include "atom/parser.h" |
13 | #include "mapper/mapperatomimpl.h" |
14 | #include "mapper/mapperrdfimpl.h" |
15 | #include "mapper/mapperrss2impl.h" |
16 | #include "rdf/parser.h" |
17 | #include "rss2/parser.h" |
18 | |
19 | #include <QCoreApplication> |
20 | |
21 | namespace |
22 | { |
23 | static bool collectionIsInitialized = false; |
24 | } |
25 | |
26 | namespace Syndication |
27 | { |
28 | static ParserCollectionImpl<Syndication::Feed> *parserColl = nullptr; |
29 | |
30 | namespace |
31 | { |
32 | // only executed when then was a QCoreApplication |
33 | static void cleanupParserCollection() |
34 | { |
35 | delete parserColl; |
36 | parserColl = nullptr; |
37 | } |
38 | |
39 | } // namespace |
40 | |
41 | ParserCollection<Feed> *parserCollection() |
42 | { |
43 | if (!collectionIsInitialized) { |
44 | parserColl = new ParserCollectionImpl<Syndication::Feed>; |
45 | qAddPostRoutine(cleanupParserCollection); |
46 | parserColl->registerParser(new RSS2::Parser, new RSS2Mapper); |
47 | parserColl->registerParser(new Atom::Parser, new AtomMapper); |
48 | parserColl->registerParser(new RDF::Parser, new RDFMapper); |
49 | collectionIsInitialized = true; |
50 | } |
51 | return parserColl; |
52 | } |
53 | |
54 | FeedPtr parse(const DocumentSource &src, const QString &formatHint) |
55 | { |
56 | return parserCollection()->parse(src, formatHint); |
57 | } |
58 | |
59 | } // namespace Syndication |
60 |