Attica

commentparser.cpp
1/*
2 This file is part of KDE.
3
4 SPDX-FileCopyrightText: 2010 Intel Corporation
5 SPDX-FileContributor: Mateu Batle Sastre <mbatle@collabora.co.uk>
6
7 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
8*/
9
10#include "commentparser.h"
11#include "atticautils.h"
12#include <QDebug>
13
14using namespace Attica;
15
16Comment Comment::Parser::parseXml(QXmlStreamReader &xml)
17{
18 Comment comment;
19
20 while (!xml.atEnd()) {
21 xml.readNext();
22
23 if (xml.isStartElement()) {
24 if (xml.name() == QLatin1String("id")) {
25 comment.setId(xml.readElementText());
26 } else if (xml.name() == QLatin1String("subject")) {
27 comment.setSubject(xml.readElementText());
28 } else if (xml.name() == QLatin1String("text")) {
29 comment.setText(xml.readElementText());
30 } else if (xml.name() == QLatin1String("childcount")) {
31 comment.setChildCount(xml.readElementText().toInt());
32 } else if (xml.name() == QLatin1String("user")) {
33 comment.setUser(xml.readElementText());
34 } else if (xml.name() == QLatin1String("date")) {
35 comment.setDate(Utils::parseQtDateTimeIso8601(xml.readElementText()));
36 } else if (xml.name() == QLatin1String("score")) {
37 comment.setScore(xml.readElementText().toInt());
38 } else if (xml.name() == QLatin1String("children")) {
39 // This may seem strange, however we are dealing with a situation where we may
40 // receive multiple children subsections (the standard accepts this, and certain
41 // server implementations do do this)
42 QList<Comment> children = comment.children();
43 children += parseXmlChildren(xml);
44 comment.setChildren(children);
45 }
46 } else if (xml.isEndElement() && xml.name() == QLatin1String("comment")) {
47 break;
48 }
49 }
50
51 return comment;
52}
53
54QList<Comment> Comment::Parser::parseXmlChildren(QXmlStreamReader &xml)
55{
56 QList<Comment> children;
57
58 while (!xml.atEnd()) {
59 xml.readNext();
60
61 if (xml.isStartElement()) {
62 if (xml.name() == QLatin1String("comment")) {
63 Comment comment = parseXml(xml);
64 children.append(comment);
65 }
66 } else if (xml.isEndElement() && xml.name() == QLatin1String("children")) {
67 break;
68 }
69 }
70
71 return children;
72}
73
74QStringList Comment::Parser::xmlElement() const
75{
76 return QStringList(QStringLiteral("comment"));
77}
Represents a comment.
Definition comment.h:29
void setScore(const int score)
This is for internal usage,.
Definition comment.cpp:132
The Attica namespace,.
void append(QList< T > &&value)
int toInt(bool *ok, int base) const const
bool atEnd() const const
bool isEndElement() const const
bool isStartElement() const const
QStringView name() const const
QString readElementText(ReadElementTextBehaviour behaviour)
TokenType readNext()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 13 2024 11:54:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.