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>
33class 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;
46 ErrorCode lastError()
const override;
49 ParserCollectionImpl(
const ParserCollectionImpl &);
50 ParserCollectionImpl &operator=(
const ParserCollectionImpl &);
55 ErrorCode m_lastError;
64ParserCollectionImpl<T>::ParserCollectionImpl()
69ParserCollectionImpl<T>::~ParserCollectionImpl()
72 qDeleteAll(m_parsers);
73 qDeleteAll(m_mappers);
77bool 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);
89void 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()) {
138ParserCollectionImpl<T>::ParserCollectionImpl(
const ParserCollectionImpl &)
143ParserCollectionImpl<T> &ParserCollectionImpl<T>::operator=(
const ParserCollectionImpl &)
KHEALTHCERTIFICATE_EXPORT QVariant parse(const QByteArray &data)
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