author | mickeyl <mickeyl> | 2004-04-04 13:54:40 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-04-04 13:54:40 (UTC) |
commit | 16cf79e90b5217f8d4bfce2a0fa817ae4b73db36 (patch) (unidiff) | |
tree | 0701eae15aa606a0211a2fccfde0eafdac69357c /noncore/apps/tableviewer/db/xmlsource.cpp | |
parent | 8d2d2664e5f544b8292806e617deb7a0e4170dc0 (diff) | |
download | opie-16cf79e90b5217f8d4bfce2a0fa817ae4b73db36.zip opie-16cf79e90b5217f8d4bfce2a0fa817ae4b73db36.tar.gz opie-16cf79e90b5217f8d4bfce2a0fa817ae4b73db36.tar.bz2 |
convert to Opie Debugging Framework
Diffstat (limited to 'noncore/apps/tableviewer/db/xmlsource.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tableviewer/db/xmlsource.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/noncore/apps/tableviewer/db/xmlsource.cpp b/noncore/apps/tableviewer/db/xmlsource.cpp index 94fec36..4ca6aee 100644 --- a/noncore/apps/tableviewer/db/xmlsource.cpp +++ b/noncore/apps/tableviewer/db/xmlsource.cpp | |||
@@ -1,50 +1,56 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "xmlsource.h" | 20 | #include "xmlsource.h" |
21 | #include <qdict.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <qtextstream.h> | ||
24 | #include "../xmlencodeattr.h" | 21 | #include "../xmlencodeattr.h" |
25 | 22 | ||
23 | /* OPIE */ | ||
24 | #include <opie2/odebug.h> | ||
25 | using namespace Opie::Core; | ||
26 | 26 | ||
27 | /* QT */ | ||
28 | #include <qdict.h> | ||
29 | #include <qtextstream.h> | ||
30 | |||
31 | /* STD */ | ||
32 | #include <stdlib.h> | ||
27 | 33 | ||
28 | DBXml::DBXml(DBStore *d) | 34 | DBXml::DBXml(DBStore *d) |
29 | { | 35 | { |
30 | dstore = d; | 36 | dstore = d; |
31 | } | 37 | } |
32 | 38 | ||
33 | QString DBXml::type() | 39 | QString DBXml::type() |
34 | { | 40 | { |
35 | return "xml"; | 41 | return "xml"; |
36 | } | 42 | } |
37 | 43 | ||
38 | bool DBXml::openSource(QIODevice *inDev) | 44 | bool DBXml::openSource(QIODevice *inDev) |
39 | { | 45 | { |
40 | bool ok; | 46 | bool ok; |
41 | 47 | ||
42 | DBXmlHandler h(dstore); | 48 | DBXmlHandler h(dstore); |
43 | 49 | ||
44 | QTextStream tsIn(inDev); | 50 | QTextStream tsIn(inDev); |
45 | QXmlInputSource source(tsIn); | 51 | QXmlInputSource source(tsIn); |
46 | QXmlSimpleReader reader; | 52 | QXmlSimpleReader reader; |
47 | reader.setContentHandler(&h); | 53 | reader.setContentHandler(&h); |
48 | reader.setErrorHandler(&h); | 54 | reader.setErrorHandler(&h); |
49 | ok = reader.parse(source); | 55 | ok = reader.parse(source); |
50 | 56 | ||
@@ -119,179 +125,179 @@ DBXml::~DBXml() {} | |||
119 | 125 | ||
120 | The format of the xml files can be found at the front of the file | 126 | The format of the xml files can be found at the front of the file |
121 | dataparser.h | 127 | dataparser.h |
122 | */ | 128 | */ |
123 | 129 | ||
124 | /*! | 130 | /*! |
125 | Constructs a new DBXmlHandler, and sets that the table should be | 131 | Constructs a new DBXmlHandler, and sets that the table should be |
126 | constructed in the DBStore pointed to by ds. | 132 | constructed in the DBStore pointed to by ds. |
127 | */ | 133 | */ |
128 | DBXmlHandler::DBXmlHandler(DBStore *ds) | 134 | DBXmlHandler::DBXmlHandler(DBStore *ds) |
129 | { | 135 | { |
130 | data_store = ds; | 136 | data_store = ds; |
131 | current_keyrep = 0; | 137 | current_keyrep = 0; |
132 | } | 138 | } |
133 | 139 | ||
134 | /*! | 140 | /*! |
135 | Destroys the DBXmlHandler | 141 | Destroys the DBXmlHandler |
136 | */ | 142 | */ |
137 | DBXmlHandler::~DBXmlHandler() | 143 | DBXmlHandler::~DBXmlHandler() |
138 | { | 144 | { |
139 | } | 145 | } |
140 | 146 | ||
141 | QString DBXmlHandler::errorProtocol() | 147 | QString DBXmlHandler::errorProtocol() |
142 | { | 148 | { |
143 | qWarning("Error reading file"); | 149 | owarn << "Error reading file" << oendl; |
144 | return errorProt; | 150 | return errorProt; |
145 | } | 151 | } |
146 | 152 | ||
147 | bool DBXmlHandler::startDocument() | 153 | bool DBXmlHandler::startDocument() |
148 | { | 154 | { |
149 | errorProt = ""; | 155 | errorProt = ""; |
150 | state = StateInit; | 156 | state = StateInit; |
151 | return TRUE; | 157 | return TRUE; |
152 | } | 158 | } |
153 | 159 | ||
154 | bool DBXmlHandler::startElement(const QString&, const QString&, | 160 | bool DBXmlHandler::startElement(const QString&, const QString&, |
155 | const QString& qName, const QXmlAttributes& atts) | 161 | const QString& qName, const QXmlAttributes& atts) |
156 | { | 162 | { |
157 | if (state == StateInit && qName == "database") { | 163 | if (state == StateInit && qName == "database") { |
158 | // First thing it expects is a <document name="..."> tag | 164 | // First thing it expects is a <document name="..."> tag |
159 | state = StateDocument; | 165 | state = StateDocument; |
160 | data_store->setName(atts.value("name")); | 166 | data_store->setName(atts.value("name")); |
161 | return TRUE; | 167 | return TRUE; |
162 | } | 168 | } |
163 | if (state == StateDocument && qName == "header") { | 169 | if (state == StateDocument && qName == "header") { |
164 | state = StateHeader; | 170 | state = StateHeader; |
165 | if (current_keyrep) delete current_keyrep; | 171 | if (current_keyrep) delete current_keyrep; |
166 | current_keyrep = new KeyList(); | 172 | current_keyrep = new KeyList(); |
167 | return TRUE; | 173 | return TRUE; |
168 | } | 174 | } |
169 | if (state == StateHeader && qName == "key") { | 175 | if (state == StateHeader && qName == "key") { |
170 | /* Ok, adding a new key to our KeyList TODO */ | 176 | /* Ok, adding a new key to our KeyList TODO */ |
171 | state = StateKey; | 177 | state = StateKey; |
172 | last_key_type = TVVariant::String; | 178 | last_key_type = TVVariant::String; |
173 | key = atts.value("name"); | 179 | key = atts.value("name"); |
174 | if (key.isEmpty()) { | 180 | if (key.isEmpty()) { |
175 | qWarning("empty key name"); | 181 | owarn << "empty key name" << oendl; |
176 | return FALSE; | 182 | return FALSE; |
177 | } | 183 | } |
178 | if(!atts.value("type").isEmpty()) | 184 | if(!atts.value("type").isEmpty()) |
179 | last_key_type = TVVariant::nameToType(atts.value("type")); | 185 | last_key_type = TVVariant::nameToType(atts.value("type")); |
180 | return TRUE; | 186 | return TRUE; |
181 | } | 187 | } |
182 | if (state == StateDocument && qName == "record") { | 188 | if (state == StateDocument && qName == "record") { |
183 | state = StateRecord; | 189 | state = StateRecord; |
184 | current_data = new DataElem(data_store); | 190 | current_data = new DataElem(data_store); |
185 | // Now expecting a <record> tag | 191 | // Now expecting a <record> tag |
186 | return TRUE; | 192 | return TRUE; |
187 | } | 193 | } |
188 | if (state == StateRecord) { | 194 | if (state == StateRecord) { |
189 | state = StateField; | 195 | state = StateField; |
190 | /* the qName is the name of a key */ | 196 | /* the qName is the name of a key */ |
191 | if (!keyIndexList[qName]) { | 197 | if (!keyIndexList[qName]) { |
192 | /* invalid key, we failed */ | 198 | /* invalid key, we failed */ |
193 | qWarning("Invalid key in record"); | 199 | owarn << "Invalid key in record" << oendl; |
194 | return FALSE; | 200 | return FALSE; |
195 | } | 201 | } |
196 | keyIndex = *keyIndexList[qName]; | 202 | keyIndex = *keyIndexList[qName]; |
197 | return TRUE; | 203 | return TRUE; |
198 | } | 204 | } |
199 | qWarning("Unable to determine tag type"); | 205 | owarn << "Unable to determine tag type" << oendl; |
200 | return FALSE; | 206 | return FALSE; |
201 | } | 207 | } |
202 | 208 | ||
203 | bool DBXmlHandler::endElement(const QString&, const QString&, | 209 | bool DBXmlHandler::endElement(const QString&, const QString&, |
204 | const QString& qName) | 210 | const QString& qName) |
205 | { | 211 | { |
206 | switch(state) { | 212 | switch(state) { |
207 | case StateField: | 213 | case StateField: |
208 | // TODO checks 'could' be done of the popped value | 214 | // TODO checks 'could' be done of the popped value |
209 | state = StateRecord; | 215 | state = StateRecord; |
210 | break; | 216 | break; |
211 | case StateKey: | 217 | case StateKey: |
212 | // TODO checks 'could' be done of the popped value | 218 | // TODO checks 'could' be done of the popped value |
213 | state = StateHeader; | 219 | state = StateHeader; |
214 | break; | 220 | break; |
215 | case StateHeader: | 221 | case StateHeader: |
216 | data_store->setKeys(current_keyrep); | 222 | data_store->setKeys(current_keyrep); |
217 | state = StateDocument; | 223 | state = StateDocument; |
218 | break; | 224 | break; |
219 | case StateRecord: | 225 | case StateRecord: |
220 | data_store->addItem(current_data); | 226 | data_store->addItem(current_data); |
221 | state = StateDocument; | 227 | state = StateDocument; |
222 | break; | 228 | break; |
223 | case StateDocument: | 229 | case StateDocument: |
224 | // we are done... | 230 | // we are done... |
225 | break; | 231 | break; |
226 | default: | 232 | default: |
227 | // should only get a 'endElement' from one of the above states. | 233 | // should only get a 'endElement' from one of the above states. |
228 | qWarning("Invalid end tag"); | 234 | owarn << "Invalid end tag" << oendl; |
229 | return FALSE; | 235 | return FALSE; |
230 | break; | 236 | break; |
231 | } | 237 | } |
232 | return TRUE; | 238 | return TRUE; |
233 | } | 239 | } |
234 | 240 | ||
235 | bool DBXmlHandler::characters(const QString& ch) | 241 | bool DBXmlHandler::characters(const QString& ch) |
236 | { | 242 | { |
237 | // this is where the 'between tag' stuff happens. | 243 | // this is where the 'between tag' stuff happens. |
238 | // e.g. the stuff between tags. | 244 | // e.g. the stuff between tags. |
239 | QString ch_simplified = ch.simplifyWhiteSpace(); | 245 | QString ch_simplified = ch.simplifyWhiteSpace(); |
240 | 246 | ||
241 | if (ch_simplified.isEmpty()) | 247 | if (ch_simplified.isEmpty()) |
242 | return TRUE; | 248 | return TRUE; |
243 | 249 | ||
244 | if (state == StateKey) { | 250 | if (state == StateKey) { |
245 | int *tmp_val = new int; | 251 | int *tmp_val = new int; |
246 | /* We just grabbed the display name of a key */ | 252 | /* We just grabbed the display name of a key */ |
247 | *tmp_val = current_keyrep->addKey(ch_simplified, last_key_type); | 253 | *tmp_val = current_keyrep->addKey(ch_simplified, last_key_type); |
248 | keyIndexList.insert(key, tmp_val); | 254 | keyIndexList.insert(key, tmp_val); |
249 | return TRUE; | 255 | return TRUE; |
250 | } | 256 | } |
251 | if (state == StateField) { | 257 | if (state == StateField) { |
252 | /* Ok, need to add data here */ | 258 | /* Ok, need to add data here */ |
253 | current_data->setField(keyIndex, ch_simplified); | 259 | current_data->setField(keyIndex, ch_simplified); |
254 | return TRUE; | 260 | return TRUE; |
255 | } | 261 | } |
256 | 262 | ||
257 | qWarning("Junk characters found... ignored"); | 263 | owarn << "Junk characters found... ignored" << oendl; |
258 | return TRUE; | 264 | return TRUE; |
259 | } | 265 | } |
260 | 266 | ||
261 | QString DBXmlHandler::errorString() | 267 | QString DBXmlHandler::errorString() |
262 | { | 268 | { |
263 | return "the document is not in the expected file format"; | 269 | return "the document is not in the expected file format"; |
264 | } | 270 | } |
265 | 271 | ||
266 | bool DBXmlHandler::warning(const QXmlParseException& exception) | 272 | bool DBXmlHandler::warning(const QXmlParseException& exception) |
267 | { | 273 | { |
268 | errorProt += QString("warning parsing error: %1 in line %2, column %3\n" ) | 274 | errorProt += QString("warning parsing error: %1 in line %2, column %3\n" ) |
269 | .arg(exception.message()) | 275 | .arg(exception.message()) |
270 | .arg(exception.lineNumber()) | 276 | .arg(exception.lineNumber()) |
271 | .arg(exception.columnNumber()); | 277 | .arg(exception.columnNumber()); |
272 | 278 | ||
273 | qWarning(errorProt); | 279 | owarn << errorProt << oendl; |
274 | return QXmlDefaultHandler::fatalError(exception); | 280 | return QXmlDefaultHandler::fatalError(exception); |
275 | } | 281 | } |
276 | 282 | ||
277 | bool DBXmlHandler::error(const QXmlParseException& exception) | 283 | bool DBXmlHandler::error(const QXmlParseException& exception) |
278 | { | 284 | { |
279 | errorProt += QString("error parsing error: %1 in line %2, column %3\n" ) | 285 | errorProt += QString("error parsing error: %1 in line %2, column %3\n" ) |
280 | .arg(exception.message()) | 286 | .arg(exception.message()) |
281 | .arg(exception.lineNumber()) | 287 | .arg(exception.lineNumber()) |
282 | .arg(exception.columnNumber()); | 288 | .arg(exception.columnNumber()); |
283 | 289 | ||
284 | qWarning(errorProt); | 290 | owarn << errorProt << oendl; |
285 | return QXmlDefaultHandler::fatalError(exception); | 291 | return QXmlDefaultHandler::fatalError(exception); |
286 | } | 292 | } |
287 | 293 | ||
288 | bool DBXmlHandler::fatalError(const QXmlParseException& exception) | 294 | bool DBXmlHandler::fatalError(const QXmlParseException& exception) |
289 | { | 295 | { |
290 | errorProt += QString("fatal parsing error: %1 in line %2, column %3\n" ) | 296 | errorProt += QString("fatal parsing error: %1 in line %2, column %3\n" ) |
291 | .arg(exception.message()) | 297 | .arg(exception.message()) |
292 | .arg(exception.lineNumber()) | 298 | .arg(exception.lineNumber()) |
293 | .arg(exception.columnNumber()); | 299 | .arg(exception.columnNumber()); |
294 | 300 | ||
295 | qWarning(errorProt); | 301 | owarn << errorProt << oendl; |
296 | return QXmlDefaultHandler::fatalError(exception); | 302 | return QXmlDefaultHandler::fatalError(exception); |
297 | } | 303 | } |