1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the qmake application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
28
#ifndef __XMLOUTPUT_H__
29
#define __XMLOUTPUT_H__
31
#include <qtextstream.h>
37
enum ConverstionType {
38
NoConversion, // No change
39
EscapeConversion, // Use '\"'
40
XMLConversion // Use "
43
NoNewLine, // No new lines, unless added manually
44
NewLine // All properties & tags indented on new lines
47
Bare, // Not in tag or attribute
48
Tag, // <tagname attribute1="value"
49
Attribute // attribute2="value">
52
tNothing, // No XML output, and not state change
53
tRaw, // Raw text (no formating)
54
tDeclaration, // <?xml version="x.x" encoding="xxx"?>
55
tTag, // <tagname attribute1="value"
56
tCloseTag, // Closes an open tag
57
tAttribute, // attribute2="value">
58
tData, // Tag data (formating done)
59
tComment, // <!-- Comment -->
60
tCDATA // <![CDATA[ ... ]]>
63
XmlOutput(QTextStream &file, ConverstionType type = XMLConversion);
67
void setIndentString(const QString &indentString);
68
QString indentString();
69
void setIndentLevel(int level);
71
void setState(XMLState state);
76
XMLType xo_type; // Type of struct instance
77
QString xo_text; // Tag/Attribute name/xml version
78
QString xo_value; // Value of attributes/xml encoding
80
xml_output(XMLType type, const QString &text, const QString &value)
81
: xo_type(type), xo_text(text), xo_value(value) {}
82
xml_output(const xml_output &xo)
83
: xo_type(xo.xo_type), xo_text(xo.xo_text), xo_value(xo.xo_value) {}
87
XmlOutput& operator<<(const QString& o);
88
XmlOutput& operator<<(const xml_output& o);
91
void increaseIndent();
92
void decreaseIndent();
95
QString doConversion(const QString &text);
98
void newTag(const QString &tag);
99
void newTagOpen(const QString &tag);
102
void closeTo(const QString &tag);
105
void addDeclaration(const QString &version, const QString &encoding);
106
void addRaw(const QString &rawText);
107
void addAttribute(const QString &attribute, const QString &value);
108
void addData(const QString &data);
111
QTextStream &xmlFile;
114
QString currentIndent;
116
XMLState currentState;
119
ConverstionType conversion;
120
QStack<QString> tagStack;
123
inline XmlOutput::xml_output noxml()
125
return XmlOutput::xml_output(XmlOutput::tNothing, QString(), QString());
128
inline XmlOutput::xml_output raw(const QString &rawText)
130
return XmlOutput::xml_output(XmlOutput::tRaw, rawText, QString());
133
inline XmlOutput::xml_output declaration(const QString &version = QString("1.0"),
134
const QString &encoding = QString())
136
return XmlOutput::xml_output(XmlOutput::tDeclaration, version, encoding);
139
inline XmlOutput::xml_output decl(const QString &version = QString("1.0"),
140
const QString &encoding = QString())
142
return declaration(version, encoding);
145
inline XmlOutput::xml_output tag(const QString &name)
147
return XmlOutput::xml_output(XmlOutput::tTag, name, QString());
150
inline XmlOutput::xml_output closetag()
152
return XmlOutput::xml_output(XmlOutput::tCloseTag, QString(), QString());
155
inline XmlOutput::xml_output closetag(const QString &toTag)
157
return XmlOutput::xml_output(XmlOutput::tCloseTag, toTag, QString());
160
inline XmlOutput::xml_output closeall()
162
return XmlOutput::xml_output(XmlOutput::tCloseTag, QString(), QString("all"));
165
inline XmlOutput::xml_output attribute(const QString &name,
166
const QString &value)
168
return XmlOutput::xml_output(XmlOutput::tAttribute, name, value);
171
inline XmlOutput::xml_output attr(const QString &name,
172
const QString &value)
174
return attribute(name, value);
177
inline XmlOutput::xml_output data(const QString &text = QString())
179
return XmlOutput::xml_output(XmlOutput::tData, text, QString());
182
inline XmlOutput::xml_output comment(const QString &text)
184
return XmlOutput::xml_output(XmlOutput::tComment, text, QString());
187
inline XmlOutput::xml_output cdata(const QString &text)
189
return XmlOutput::xml_output(XmlOutput::tCDATA, text, QString());
192
#endif // __XMLOUTPUT_H__