summaryrefslogtreecommitdiff
path: root/noncore/apps/tableviewer/db/xmlsource.h
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /noncore/apps/tableviewer/db/xmlsource.h
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'noncore/apps/tableviewer/db/xmlsource.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tableviewer/db/xmlsource.h119
1 files changed, 119 insertions, 0 deletions
diff --git a/noncore/apps/tableviewer/db/xmlsource.h b/noncore/apps/tableviewer/db/xmlsource.h
new file mode 100644
index 0000000..ec267a6
--- a/dev/null
+++ b/noncore/apps/tableviewer/db/xmlsource.h
@@ -0,0 +1,119 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21/* A Class to parse an xml docment of the form
22 * <database name="...">
23 * <header>
24 * <key name=key_name type=String>Displayed Name</key>
25 * <key name=key2name>key2name</key>
26 * <key name=key3name type=Date>Key 3</key>
27 * <key name=key4name type=Int>key 4</key>
28 * </header>
29 * <record>
30 * <key_name>string</key_name>
31 * <key4name>int</key4name>
32 * <key2name>string</key2name>
33 * </record>
34 * <record>
35 * ....
36 * </record>
37 * ....
38 * </database>
39 *
40 * There is some room for improvment mostly around using better checking
41 * and the use of more advanced xml features.
42 */
43
44#ifndef __XMLSOURCE_H__
45#define __XMLSOURCE_H__
46
47#include <qxml.h>
48#include <qstring.h>
49#include <qstringlist.h>
50#include <qstack.h>
51#include <qdict.h>
52#include "datacache.h"
53#include "common.h"
54
55
56class DBXml : public DBAccess
57{
58public:
59 /* create connection and either open or initialize */
60 DBXml(DBStore *d);
61 QString type();
62 bool openSource(QIODevice *);
63 bool saveSource(QIODevice *);
64 /* does a db write */
65 ~DBXml();
66};
67
68
69class DBXmlHandler : public QXmlDefaultHandler
70{
71
72public:
73 DBXmlHandler(DBStore *ds);
74 virtual ~DBXmlHandler();
75
76 // return the error protocol if parsing failed
77 QString errorProtocol();
78
79 // overloaded handler functions
80 bool startDocument();
81 bool startElement(const QString& namespaceURI, const QString& localName,
82 const QString& qName, const QXmlAttributes& atts);
83 bool endElement(const QString& namespaceURI, const QString& localName,
84 const QString& qName);
85 bool characters(const QString& ch);
86
87 QString errorString();
88
89 bool warning(const QXmlParseException& exception);
90 bool error(const QXmlParseException& exception);
91 bool fatalError(const QXmlParseException& exception);
92
93private:
94
95 QStack<QString> stack;
96 KeyList *current_keyrep;
97 DataElem *current_data;
98 TVVariant::KeyType last_key_type;
99
100 QString errorProt;
101 DBStore *data_store;
102
103 enum State {
104 StateInit,
105 StateHeader,
106 StateKey,
107 StateDocument,
108 StateRecord,
109 StateField
110 };
111
112 State state;
113
114 QDict<int> keyIndexList;
115 int keyIndex;
116 QString key;
117};
118
119#endif