AusweisApp
 
Lade ...
Suche ...
Keine Treffer
ElementParser.h
gehe zur Dokumentation dieser Datei
1
4
5#pragma once
6
8
9#include <QList>
10#include <QLoggingCategory>
11#include <QSharedPointer>
12#include <QXmlStreamReader>
13
14
15Q_DECLARE_LOGGING_CATEGORY(paos)
16
17class test_ElementParser;
18
19namespace governikus
20{
21
23{
24 friend class ::test_ElementParser;
25
26 public:
27 explicit ElementParser(QSharedPointer<QXmlStreamReader> pXmlReader);
28 virtual ~ElementParser();
29
30 [[nodiscard]] bool parserFailed() const;
31
32 protected:
33 // helper methods
35
41
46 QString readElementText();
47
53 void assertMandatoryElement(const QString& pValue, const char* const pElementName);
54
61 template<typename T> bool assertMandatoryList(const QList<T>& pList, const char* const pElementName);
62
68 bool assertNoDuplicateElement(bool pNotYetSeen);
69
80 bool readUniqueElementText(QString& pText);
81
86 void skipCurrentElement() const;
87
92 [[nodiscard]] QStringView getElementName() const;
93
94 void setParserFailed();
95
96 void initData(const QByteArray& pXmlData);
97
98 [[nodiscard]] QStringView getElementTypeByNamespace(const QString& pNamespace) const;
99
100 private:
101 QSharedPointer<QXmlStreamReader> mXmlReader;
102 bool mParseError;
103};
104
105
106template<typename T> bool ElementParser::assertMandatoryList(const QList<T>& pList, const char* const pElementName)
107{
108 if (pList.isEmpty())
109 {
110 qCWarning(paos) << "Mandatory list is empty:" << pElementName;
111 mParseError = true;
112 return false;
113 }
114
115 return true;
116}
117
118
119} // namespace governikus
Definition ConnectionHandle.h:13
bool assertMandatoryList(const QList< T > &pList, const char *const pElementName)
Issues a log warning and sets the error when the list is empty.
Definition ElementParser.h:106
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
ElementParser(QSharedPointer< QXmlStreamReader > pXmlReader)
Definition ElementParser.cpp:11
QString readElementText()
Returns the text (simplified()) between the current start element and the corresponding end element.
Definition ElementParser.cpp:33
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
Defines the AccessRight and AccessRole enum.
Definition CommandApdu.h:17