File indexing completed on 2023-09-24 08:12:52
0001 /* 0002 This file is part of the syndication library 0003 SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "global.h" 0009 #include "documentsource.h" 0010 #include "parsercollectionimpl.h" 0011 0012 #include "atom/parser.h" 0013 #include "mapper/mapperatomimpl.h" 0014 #include "mapper/mapperrdfimpl.h" 0015 #include "mapper/mapperrss2impl.h" 0016 #include "rdf/parser.h" 0017 #include "rss2/parser.h" 0018 0019 #include <QCoreApplication> 0020 0021 namespace 0022 { 0023 static bool collectionIsInitialized = false; 0024 } 0025 0026 namespace Syndication 0027 { 0028 static ParserCollectionImpl<Syndication::Feed> *parserColl = nullptr; 0029 0030 namespace 0031 { 0032 // only executed when then was a QCoreApplication 0033 static void cleanupParserCollection() 0034 { 0035 delete parserColl; 0036 parserColl = nullptr; 0037 } 0038 0039 } // namespace 0040 0041 ParserCollection<Feed> *parserCollection() 0042 { 0043 if (!collectionIsInitialized) { 0044 parserColl = new ParserCollectionImpl<Syndication::Feed>; 0045 qAddPostRoutine(cleanupParserCollection); 0046 parserColl->registerParser(new RSS2::Parser, new RSS2Mapper); 0047 parserColl->registerParser(new Atom::Parser, new AtomMapper); 0048 parserColl->registerParser(new RDF::Parser, new RDFMapper); 0049 collectionIsInitialized = true; 0050 } 0051 return parserColl; 0052 } 0053 0054 FeedPtr parse(const DocumentSource &src, const QString &formatHint) 0055 { 0056 return parserCollection()->parse(src, formatHint); 0057 } 0058 0059 } // namespace Syndication