23 #ifndef SYNDICATION_PARSERCOLLECTIONIMPL_H
24 #define SYNDICATION_PARSERCOLLECTIONIMPL_H
26 #include <syndication/specificdocument.h>
27 #include <syndication/abstractparser.h>
28 #include <syndication/documentsource.h>
29 #include <syndication/parsercollection.h>
30 #include <syndication/feed.h>
31 #include <syndication/global.h>
32 #include <syndication/mapper.h>
34 #include <QtXml/QDomDocument>
35 #include <QtCore/QHash>
36 #include <QtCore/QString>
38 namespace Syndication {
48 class SYNDICATION_EXPORT ParserCollectionImpl :
public ParserCollection<T>
52 ParserCollectionImpl();
54 virtual ~ParserCollectionImpl();
56 boost::shared_ptr<T>
parse(
const DocumentSource& source,
60 bool registerParser(AbstractParser* parser, Mapper<T>* mapper);
62 void changeMapper(
const QString& format, Mapper<T>* mapper);
68 ParserCollectionImpl(
const ParserCollectionImpl&);
69 ParserCollectionImpl& operator=(
const ParserCollectionImpl&);
83 ParserCollectionImpl<T>::ParserCollectionImpl()
88 ParserCollectionImpl<T>::~ParserCollectionImpl()
94 for ( ; it != end; ++it)
101 for ( ; itm != endm; ++itm)
102 delete m_mappers[*itm];
107 bool ParserCollectionImpl<T>::registerParser(AbstractParser* parser, Mapper<T>* mapper)
109 if (m_parsers.contains(parser->format()))
112 m_parserList.append(parser);
113 m_parsers.insert(parser->format(), parser);
114 m_mappers.insert(parser->format(), mapper);
118 void ParserCollectionImpl<T>::changeMapper(
const QString& format, Mapper<T>* mapper)
120 m_mappers[format] = mapper;
124 boost::shared_ptr<T> ParserCollectionImpl<T>::parse(
const DocumentSource& source,
const QString& formatHint)
128 if (!formatHint.
isNull() && m_parsers.contains(formatHint))
130 if (m_parsers[formatHint]->accept(source))
132 SpecificDocumentPtr doc = m_parsers[formatHint]->parse(source);
139 return m_mappers[formatHint]->map(doc);
143 Q_FOREACH (AbstractParser* i, m_parserList)
145 if (i->accept(source))
147 SpecificDocumentPtr doc = i->parse(source);
154 return m_mappers[i->format()]->map(doc);
157 if (source.asDomDocument().isNull())
172 ParserCollectionImpl<T>::ParserCollectionImpl(
const ParserCollectionImpl&)
177 ParserCollectionImpl<T>& ParserCollectionImpl<T>::operator=(
const ParserCollectionImpl&)
184 #endif // SYNDICATION_PARSERCOLLECTIONIMPL_H
the source was accepted by a parser, but the actual parsing failed.
FeedPtr parse(const DocumentSource &src, const QString &formatHint)
parses a document from a source and returns a new Feed object wrapping the feed content.
The source is valid XML, but no parser accepted it.
No error occurred, feed was fetched and parsed successfully.
ErrorCode
error code indicating fetching or parsing errors
const_iterator constEnd() const
const_iterator constBegin() const