Attica

publisherparser.cpp
1 /*
2  This file is part of KDE.
3 
4  SPDX-FileCopyrightText: 2010 Sebastian K├╝gler <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8 
9 #include "publisherparser.h"
10 #include <qdebug.h>
11 
12 using namespace Attica;
13 
14 Publisher Publisher::Parser::parseXml(QXmlStreamReader &xml)
15 {
16  // For specs about the XML provided, see here:
17  // http://www.freedesktop.org/wiki/Specifications/open-collaboration-services-draft
18 
19  Publisher publisher;
20  QStringList fields;
21 
22  while (!xml.atEnd()) {
23  //qCDebug(ATTICA) << "XML returned:" << xml.text().toString();
24  xml.readNext();
25 
26  if (xml.isStartElement()) {
27 
28  if (xml.name() == QLatin1String("id")) {
29  publisher.setId(xml.readElementText());
30  } else if (xml.name() == QLatin1String("name")) {
31  publisher.setName(xml.readElementText());
32  } else if (xml.name() == QLatin1String("registrationurl")) {
33  publisher.setUrl(xml.readElementText());
34  } else if (xml.name() == QLatin1String("fields")) {
35  while (!xml.atEnd()) {
37  if (xml.isStartElement()) {
38  if (xml.name() == QLatin1String("field")) {
39  Field t;
40  while (!xml.atEnd()) {
42  if (xml.isStartElement()) {
43  if (xml.name() == QLatin1String("fieldtype")) {
44  t.type = xml.readElementText();
45  } else if (xml.name() == QLatin1String("name")) {
46  t.name = xml.readElementText();
47  } else if (xml.name() == QLatin1String("fieldsize")) {
48  t.fieldsize = xml.readElementText().toInt();
49  } else if (xml.name() == QLatin1String("required")) {
50  t.required = xml.readElementText() == QLatin1String("true");
51  } else if (xml.name() == QLatin1String("options")) {
52  while (!xml.atEnd()) {
54  if (xml.isStartElement()) {
55  if (xml.name() == QLatin1String("option")) {
56  t.options << xml.readElementText();
57  }
58  } else if (xml.isEndElement() && xml.name() == QLatin1String("options")) {
59  xml.readNext();
60  break;
61  }
62  }
63  }
64  } else if (xml.isEndElement() && (xml.name() == QLatin1String("field"))) {
65  xml.readNext();
66  break;
67  }
68  }
69  publisher.addField(t);
70  }
71  } else if (xml.isEndElement() && (xml.name() == QLatin1String("fields"))) {
72  xml.readNext();
73  break;
74  }
75  }
76  } else if (xml.name() == QLatin1String("supportedtargets")) {
77  while (!xml.atEnd()) {
79  if (xml.isStartElement()) {
80  if (xml.name() == QLatin1String("target")) {
81  Target t;
82  t.name = xml.readElementText();
83  publisher.addTarget(t);
84  }
85  } else if (xml.isEndElement() && (xml.name() == QLatin1String("supportedtargets"))) {
86  xml.readNext();
87  break;
88  }
89  }
90  }
91  } else if (xml.isEndElement()
92  && ((xml.name() == QLatin1String("publisher"))
93  || (xml.name() == QLatin1String("user")))) {
94  break;
95  }
96  }
97  return publisher;
98 }
99 
100 QStringList Publisher::Parser::xmlElement() const
101 {
102  return QStringList(QStringLiteral("publisher")) << QStringLiteral("user");
103 }
bool atEnd() const const
bool readNextStartElement()
Publisher
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
int toInt(bool *ok, int base) const const
QXmlStreamReader::TokenType readNext()
bool isStartElement() const const
QStringRef name() const const
bool isEndElement() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jan 23 2021 03:59:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.