Attica

knowledgebaseentryparser.cpp
1 /*
2  This file is part of KDE.
3 
4  SPDX-FileCopyrightText: 2008 Cornelius Schumacher <[email protected]>
5  SPDX-FileCopyrightText: 2009 Marco Martin <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
8 */
9 
10 #include "knowledgebaseentryparser.h"
11 
12 using namespace Attica;
13 
14 KnowledgeBaseEntry KnowledgeBaseEntry::Parser::parseXml(QXmlStreamReader &xml)
15 {
16  KnowledgeBaseEntry knowledgeBase;
17 
18  while (!xml.atEnd()) {
19  xml.readNext();
20 
21  if (xml.isStartElement()) {
22  if (xml.name() == QLatin1String("id")) {
23  knowledgeBase.setId(xml.readElementText());
24  } else if (xml.name() == QLatin1String("status")) {
25  knowledgeBase.setStatus(xml.readElementText());
26  } else if (xml.name() == QLatin1String("contentId")) {
27  knowledgeBase.setContentId(xml.readElementText().toInt());
28  } else if (xml.name() == QLatin1String("user")) {
29  knowledgeBase.setUser(xml.readElementText());
30  } else if (xml.name() == QLatin1String("changed")) {
31  knowledgeBase.setChanged(QDateTime::fromString(xml.readElementText(), Qt::ISODate));
32  } else if (xml.name() == QLatin1String("description")) {
33  knowledgeBase.setDescription(xml.readElementText());
34  } else if (xml.name() == QLatin1String("answer")) {
35  knowledgeBase.setAnswer(xml.readElementText());
36  } else if (xml.name() == QLatin1String("comments")) {
37  knowledgeBase.setComments(xml.readElementText().toInt());
38  } else if (xml.name() == QLatin1String("detailpage")) {
39  knowledgeBase.setDetailPage(QUrl(xml.readElementText()));
40  } else if (xml.name() == QLatin1String("contentid")) {
41  knowledgeBase.setContentId(xml.readElementText().toInt());
42  } else if (xml.name() == QLatin1String("name")) {
43  knowledgeBase.setName(xml.readElementText());
44  } else {
45  knowledgeBase.addExtendedAttribute(xml.name().toString(), xml.readElementText());
46  }
47  } else if (xml.isEndElement() && xml.name() == QLatin1String("content")) {
48  break;
49  }
50  }
51 
52  return knowledgeBase;
53 }
54 
55 QStringList KnowledgeBaseEntry::Parser::xmlElement() const
56 {
57  return QStringList(QStringLiteral("content"));
58 }
bool atEnd() const const
QString toString() const const
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
int toInt(bool *ok, int base) const const
QXmlStreamReader::TokenType readNext()
QDateTime fromString(const QString &string, Qt::DateFormat format)
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 Mon Jan 25 2021 23:06:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.