Syndication

global.cpp
1 /*
2  * This file is part of the syndication library
3  *
4  * Copyright (C) 2006 Frank Osterfeld <[email protected]>
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 #include "global.h"
24 #include "documentsource.h"
25 #include "parsercollectionimpl.h"
26 
27 #include "mapper/mapperatomimpl.h"
28 #include "mapper/mapperrdfimpl.h"
29 #include "mapper/mapperrss2impl.h"
30 #include "atom/parser.h"
31 #include "rdf/parser.h"
32 #include "rss2/parser.h"
33 
34 #include <QCoreApplication>
35 
36 namespace
37 {
38 static bool collectionIsInitialized = false;
39 }
40 
41 namespace Syndication
42 {
43 
44 static ParserCollectionImpl<Syndication::Feed> *parserColl = nullptr;
45 
46 namespace
47 {
48 
49 // only executed when then was a QCoreApplication
50 static void cleanupParserCollection()
51 {
52  delete parserColl;
53  parserColl = nullptr;
54 }
55 
56 } // namespace
57 
59 {
60  if (!collectionIsInitialized) {
61  parserColl = new ParserCollectionImpl<Syndication::Feed>;
62  qAddPostRoutine(cleanupParserCollection);
63  parserColl->registerParser(new RSS2::Parser, new RSS2Mapper);
64  parserColl->registerParser(new Atom::Parser, new AtomMapper);
65  parserColl->registerParser(new RDF::Parser, new RDFMapper);
66  collectionIsInitialized = true;
67  }
68  return parserColl;
69 }
70 
71 FeedPtr parse(const DocumentSource &src, const QString &formatHint)
72 {
73  return parserCollection()->parse(src, formatHint);
74 }
75 
76 } // namespace Syndication
77 
Parser implementation for RDF-based RSS 0.9 and RSS 1.0 feeds.
Definition: rdf/parser.h:41
FeedPtr parse(const DocumentSource &src, const QString &formatHint)
parses a document from a source and returns a new Feed object wrapping the feed content.
Definition: global.cpp:71
Represents the source of a syndication document, as read from the downloaded file.
A collection of format-specific parser implementations.
Definition: global.h:35
ParserCollection< Feed > * parserCollection()
The default ParserCollection instance parsing a DocumentSource into a Feed object.
Definition: global.cpp:58
Parser implementation for the RSS 0.9x/2.0 format family.
Definition: rss2/parser.h:44
parser implementation for Atom 1.0 and 0.3.
Definition: atom/parser.h:45
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Jun 2 2020 22:53:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.