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>
36 ParserCollectionImpl();
38 ~ParserCollectionImpl()
override;
40 QSharedPointer<T>
parse(
const DocumentSource &source,
const QString &formatHint = QString())
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 &);
51 QHash<QString, AbstractParser *> m_parsers;
52 QHash<QString, Mapper<T> *> m_mappers;
53 QList<AbstractParser *> m_parserList;
64ParserCollectionImpl<T>::ParserCollectionImpl()
69ParserCollectionImpl<T>::~ParserCollectionImpl()
72 qDeleteAll(m_parsers);
73 qDeleteAll(m_mappers);
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);
89void ParserCollectionImpl<T>::changeMapper(
const QString &format,
Mapper<T> *mapper)
91 m_mappers[format] = mapper;
95QSharedPointer<T> ParserCollectionImpl<T>::parse(
const DocumentSource &source,
const QString &formatHint)
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);
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()) {
138ParserCollectionImpl<T>::ParserCollectionImpl(
const ParserCollectionImpl &)
143ParserCollectionImpl<T> &ParserCollectionImpl<T>::operator=(
const ParserCollectionImpl &)
Interface for all parsers.
Represents the source of a syndication document, as read from the downloaded file.
A mapper maps an SpecificDocument to something else.
A collection of format-specific parser implementations.
QList< QVariant > parse(const QString &message, const QDateTime &externalIssueDateTime=QDateTime())
ErrorCode
error code indicating fetching or parsing errors
@ InvalidXml
The XML is invalid.
@ XmlNotAccepted
The source is valid XML, but no parser accepted it.
@ InvalidFormat
the source was accepted by a parser, but the actual parsing failed.
@ Success
No error occurred, feed was fetched and parsed successfully.
bool isNull() const const