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  protected:
28  // helper methods
29 
34  bool readNextStartElement();
35 
40  QString readElementText();
41 
47  void assertMandatoryElement(const QString& pValue, const char* const pElementName);
48 
55  template<typename T> bool assertMandatoryList(const QVector<T>& pList, const char* const pElementName);
56 
62  bool assertNoDuplicateElement(bool pNotYetSeen);
63 
74  bool readUniqueElementText(QString& pText);
75 
76  QSharedPointer<QXmlStreamReader> mXmlReader;
78 };
79 
80 
81 template<typename T> bool ElementParser::assertMandatoryList(const QVector<T>& pList, const char* const pElementName)
82 {
83  if (pList.isEmpty())
84  {
85  qCWarning(paos) << "Mandatory list is empty:" << pElementName;
86  mParseError = true;
87  return false;
88  }
89 
90  return true;
91 }
92 
93 
94 } // namespace governikus
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:61
bool readUniqueElementText(QString &pText)
Returns the text (simplified()) between the current start element and the corresponding end element...
Definition: ElementParser.cpp:71
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:81
bool assertNoDuplicateElement(bool pNotYetSeen)
Issues a log warning and sets the error when a duplicate element has been encountered.
Definition: ElementParser.cpp:49
QString readElementText()
Returns the text (simplified()) between the current start element and the corresponding end element...
Definition: ElementParser.cpp:27
Implementation of ActivationContext for Intent based activation on Android systems.
Definition: ActivationContext.h:14
QSharedPointer< QXmlStreamReader > mXmlReader
Definition: ElementParser.h:76
virtual ~ElementParser()
Definition: ElementParser.cpp:16
ElementParser(QSharedPointer< QXmlStreamReader > pXmlReader)
Definition: ElementParser.cpp:9
bool mParseError
Definition: ElementParser.h:77
Definition: ElementParser.h:21
bool readNextStartElement()
Like QXmlStreamReader::readNextStartElement(), but also checks mParseError.
Definition: ElementParser.cpp:21