Syndication
8 #ifndef SYNDICATION_PARSERCOLLECTIONIMPL_H
9 #define SYNDICATION_PARSERCOLLECTIONIMPL_H
11 #include <syndication/abstractparser.h>
12 #include <syndication/documentsource.h>
13 #include <syndication/feed.h>
14 #include <syndication/global.h>
15 #include <syndication/mapper.h>
16 #include <syndication/parsercollection.h>
17 #include <syndication/specificdocument.h>
19 #include <QDomDocument>
33 class SYNDICATION_EXPORT ParserCollectionImpl :
public ParserCollection<T>
36 ParserCollectionImpl();
38 ~ParserCollectionImpl()
override;
42 bool registerParser(AbstractParser *parser, Mapper<T> *mapper)
override;
44 void changeMapper(
const QString &format, Mapper<T> *mapper)
override;
49 ParserCollectionImpl(
const ParserCollectionImpl &);
50 ParserCollectionImpl &operator=(
const ParserCollectionImpl &);
64 ParserCollectionImpl<T>::ParserCollectionImpl()
69 ParserCollectionImpl<T>::~ParserCollectionImpl()
72 qDeleteAll(m_parsers);
73 qDeleteAll(m_mappers);
77 bool ParserCollectionImpl<T>::registerParser(AbstractParser *parser, Mapper<T> *mapper)
79 if (m_parsers.contains(parser->format())) {
83 m_parserList.append(parser);
84 m_parsers.insert(parser->format(), parser);
85 m_mappers.insert(parser->format(), mapper);
89 void ParserCollectionImpl<T>::changeMapper(
const QString &format, Mapper<T> *mapper)
91 m_mappers[format] = mapper;
99 if (!formatHint.
isNull() && m_parsers.contains(formatHint)) {
100 if (m_parsers[formatHint]->accept(source)) {
101 SpecificDocumentPtr doc = m_parsers[formatHint]->parse(source);
102 if (!doc->isValid()) {
107 return m_mappers[formatHint]->map(doc);
111 for (AbstractParser *i : std::as_const(m_parserList)) {
112 if (i->accept(source)) {
113 SpecificDocumentPtr doc = i->parse(source);
114 if (!doc->isValid()) {
119 return m_mappers[i->format()]->map(doc);
122 if (source.asDomDocument().isNull()) {
138 ParserCollectionImpl<T>::ParserCollectionImpl(
const ParserCollectionImpl &)
143 ParserCollectionImpl<T> &ParserCollectionImpl<T>::operator=(
const ParserCollectionImpl &)
150 #endif // SYNDICATION_PARSERCOLLECTIONIMPL_H
bool isNull() const const
@ InvalidXml
The XML is invalid.
FeedPtr parse(const DocumentSource &src, const QString &formatHint)
parses a document from a source and returns a new Feed object wrapping the feed content.
@ XmlNotAccepted
The source is valid XML, but no parser accepted it.
@ InvalidFormat
the source was accepted by a parser, but the actual parsing failed.
ErrorCode
error code indicating fetching or parsing errors
@ Success
No error occurred, feed was fetched and parsed successfully.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Jun 6 2023 03:56:27 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.