AusweisApp2
Lade ...
Suche ...
Keine Treffer
ElementParser.h
gehe zur Dokumentation dieser Datei
1
7#pragma once
8
10
11#include <QLoggingCategory>
12#include <QSharedPointer>
13#include <QVector>
14#include <QXmlStreamReader>
15
16
17Q_DECLARE_LOGGING_CATEGORY(paos)
18
19class test_ElementParser;
20
21namespace governikus
22{
23
25{
26 friend class ::test_ElementParser;
27
28 public:
29 explicit ElementParser(QSharedPointer<QXmlStreamReader> pXmlReader);
30 virtual ~ElementParser();
31
32 [[nodiscard]] bool parserFailed() const;
33
34 protected:
35 // helper methods
37
43
48 QString readElementText();
49
55 void assertMandatoryElement(const QString& pValue, const char* const pElementName);
56
63 template<typename T> bool assertMandatoryList(const QVector<T>& pList, const char* const pElementName);
64
70 bool assertNoDuplicateElement(bool pNotYetSeen);
71
82 bool readUniqueElementText(QString& pText);
83
88 void skipCurrentElement() const;
89
94 [[nodiscard]] QStringView getElementName() const;
95
96 void setParserFailed();
97
98 void initData(const QByteArray& pXmlData);
99
100 [[nodiscard]] QStringView getElementTypeByNamespace(const QString& pNamespace) const;
101
102 private:
103 QSharedPointer<QXmlStreamReader> mXmlReader;
104 bool mParseError;
105};
106
107
108template<typename T> bool ElementParser::assertMandatoryList(const QVector<T>& pList, const char* const pElementName)
109{
110 if (pList.isEmpty())
111 {
112 qCWarning(paos) << "Mandatory list is empty:" << pElementName;
113 mParseError = true;
114 return false;
115 }
116
117 return true;
118}
119
120
121} // namespace governikus
Definition: ConnectionHandle.h:15
Definition: ElementParser.h:25
ConnectionHandle parseConnectionHandle()
Definition: ElementParser.cpp:123
QStringView getElementTypeByNamespace(const QString &pNamespace) const
Definition: ElementParser.cpp:103
bool parserFailed() const
Definition: ElementParser.cpp:21
bool readNextStartElement()
Like QXmlStreamReader::readNextStartElement(), but also checks mParseError.
Definition: ElementParser.cpp:27
void assertMandatoryElement(const QString &pValue, const char *const pElementName)
Issues a log warning and sets the error when the element has not been set, i.e.
Definition: ElementParser.cpp:67
QString readElementText()
Returns the text (simplified()) between the current start element and the corresponding end element.
Definition: ElementParser.cpp:33
bool assertMandatoryList(const QVector< T > &pList, const char *const pElementName)
Issues a log warning and sets the error when the list is empty.
Definition: ElementParser.h:108
QStringView getElementName() const
Returns the name of the current element and issues a log message with it.
Definition: ElementParser.cpp:95
bool assertNoDuplicateElement(bool pNotYetSeen)
Issues a log warning and sets the error when a duplicate element has been encountered.
Definition: ElementParser.cpp:55
void initData(const QByteArray &pXmlData)
Definition: ElementParser.cpp:109
void skipCurrentElement() const
Skips parsing of the current element Used to ignore unknown or unrecognized elements while parsing.
Definition: ElementParser.cpp:89
bool readUniqueElementText(QString &pText)
Returns the text (simplified()) between the current start element and the corresponding end element,...
Definition: ElementParser.cpp:77
void setParserFailed()
Definition: ElementParser.cpp:117
Implementation of GeneralAuthenticate response APDUs.
Definition: CommandApdu.h:16