AusweisApp2
ElementParser.h
gehe zur Dokumentation dieser Datei
1 
7 #pragma once
8 
9 #include <QLoggingCategory>
10 #include <QSharedPointer>
11 #include <QVector>
12 #include <QXmlStreamReader>
13 
14 
15 Q_DECLARE_LOGGING_CATEGORY(paos)
16 
17 
18 namespace governikus
19 {
20 
22 {
23  public:
24  explicit ElementParser(QSharedPointer<QXmlStreamReader> pXmlReader);
25  virtual ~ElementParser();
26 
27  [[nodiscard]] bool parserFailed() const;
28 
29  protected:
30  // helper methods
31 
36  bool readNextStartElement();
37 
42  QString readElementText();
43 
49  void assertMandatoryElement(const QString& pValue, const char* const pElementName);
50 
57  template<typename T> bool assertMandatoryList(const QVector<T>& pList, const char* const pElementName);
58 
64  bool assertNoDuplicateElement(bool pNotYetSeen);
65 
76  bool readUniqueElementText(QString& pText);
77 
78  QSharedPointer<QXmlStreamReader> mXmlReader;
80 };
81 
82 
83 template<typename T> bool ElementParser::assertMandatoryList(const QVector<T>& pList, const char* const pElementName)
84 {
85  if (pList.isEmpty())
86  {
87  qCWarning(paos) << "Mandatory list is empty:" << pElementName;
88  mParseError = true;
89  return false;
90  }
91 
92  return true;
93 }
94 
95 
96 } // namespace governikus
governikus::ElementParser::readUniqueElementText
bool readUniqueElementText(QString &pText)
Returns the text (simplified()) between the current start element and the corresponding end element,...
Definition: ElementParser.cpp:77
governikus::ElementParser::mXmlReader
QSharedPointer< QXmlStreamReader > mXmlReader
Definition: ElementParser.h:78
governikus::ElementParser::~ElementParser
virtual ~ElementParser()
Definition: ElementParser.cpp:16
governikus::ElementParser::readNextStartElement
bool readNextStartElement()
Like QXmlStreamReader::readNextStartElement(), but also checks mParseError.
Definition: ElementParser.cpp:27
governikus::ElementParser::ElementParser
ElementParser(QSharedPointer< QXmlStreamReader > pXmlReader)
Definition: ElementParser.cpp:9
ElementParser.h
governikus::ElementParser::assertNoDuplicateElement
bool assertNoDuplicateElement(bool pNotYetSeen)
Issues a log warning and sets the error when a duplicate element has been encountered.
Definition: ElementParser.cpp:55
governikus
Implementation of ActivationContext for Intent based activation on Android systems.
Definition: ActivationContext.h:15
governikus::ElementParser::parserFailed
bool parserFailed() const
Definition: ElementParser.cpp:21
governikus::ElementParser::readElementText
QString readElementText()
Returns the text (simplified()) between the current start element and the corresponding end element.
Definition: ElementParser.cpp:33
governikus::ElementParser::mParseError
bool mParseError
Definition: ElementParser.h:79
governikus::ElementParser::assertMandatoryList
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:83
governikus::ElementParser
Definition: ElementParser.h:22
governikus::ElementParser::assertMandatoryElement
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