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  if (xml.name() == QLatin1String("id")) {
28  publisher.setId(xml.readElementText());
29  } else if (xml.name() == QLatin1String("name")) {
30  publisher.setName(xml.readElementText());
31  } else if (xml.name() == QLatin1String("registrationurl")) {
32  publisher.setUrl(xml.readElementText());
33  } else if (xml.name() == QLatin1String("fields")) {
34  while (!xml.atEnd()) {
36  if (xml.isStartElement()) {
37  if (xml.name() == QLatin1String("field")) {
38  Field t;
39  while (!xml.atEnd()) {
41  if (xml.isStartElement()) {
42  if (xml.name() == QLatin1String("fieldtype")) {
43  t.type = xml.readElementText();
44  } else if (xml.name() == QLatin1String("name")) {
45  t.name = xml.readElementText();
46  } else if (xml.name() == QLatin1String("fieldsize")) {
47  t.fieldsize = xml.readElementText().toInt();
48  } else if (xml.name() == QLatin1String("required")) {
49  t.required = xml.readElementText() == QLatin1String("true");
50  } else if (xml.name() == QLatin1String("options")) {
51  while (!xml.atEnd()) {
53  if (xml.isStartElement()) {
54  if (xml.name() == QLatin1String("option")) {
55  t.options << xml.readElementText();
56  }
57  } else if (xml.isEndElement() && xml.name() == QLatin1String("options")) {
58  xml.readNext();
59  break;
60  }
61  }
62  }
63  } else if (xml.isEndElement() && (xml.name() == QLatin1String("field"))) {
64  xml.readNext();
65  break;
66  }
67  }
68  publisher.addField(t);
69  }
70  } else if (xml.isEndElement() && (xml.name() == QLatin1String("fields"))) {
71  xml.readNext();
72  break;
73  }
74  }
75  } else if (xml.name() == QLatin1String("supportedtargets")) {
76  while (!xml.atEnd()) {
78  if (xml.isStartElement()) {
79  if (xml.name() == QLatin1String("target")) {
80  Target t;
81  t.name = xml.readElementText();
82  publisher.addTarget(t);
83  }
84  } else if (xml.isEndElement() && (xml.name() == QLatin1String("supportedtargets"))) {
85  xml.readNext();
86  break;
87  }
88  }
89  }
90  } else if (xml.isEndElement() //
91  && (xml.name() == QLatin1String("publisher") || xml.name() == QLatin1String("user"))) {
92  break;
93  }
94  }
95  return publisher;
96 }
97 
98 QStringList Publisher::Parser::xmlElement() const
99 {
100  return QStringList(QStringLiteral("publisher")) << QStringLiteral("user");
101 }
bool readNextStartElement()
bool isEndElement() const const
QStringRef name() const const
QXmlStreamReader::TokenType readNext()
int toInt(bool *ok, int base) const const
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
The Attica namespace,.
bool isStartElement() const const
bool atEnd() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Dec 3 2023 04:08:16 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.