summaryrefslogtreecommitdiffstats
path: root/src/translators/xmlstatehandler.h
blob: 8b5c1376ff8ed59031c383db3a0aea6679af279a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/***************************************************************************
    copyright            : (C) 2008 by Robby Stephenson
    email                : robby@periapsis.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of version 2 of the GNU General Public License as  *
 *   published by the Free Software Foundation;                            *
 *                                                                         *
 ***************************************************************************/

#ifndef TELLICO_IMPORT_XMLSTATEHANDLER_H
#define TELLICO_IMPORT_XMLSTATEHANDLER_H

#ifdef QT_NO_CAST_ASCII
#define HAD_QT_NO_CAST_ASCII
#undef QT_NO_CAST_ASCII
#endif

#include <tqxml.h>

#ifdef HAD_QT_NO_CAST_ASCII
#define QT_NO_CAST_ASCII
#undef HAD_QT_NO_CAST_ASCII
#endif

#include "../datavectors.h"

namespace Tellico {
  namespace Import {
    namespace SAX {

class StateData {
public:
  TQString text;
  TQString error;
  TQString ns; // namespace
  TQString textBuffer;
  uint syntaxVersion;
  TQString collTitle;
  int collType;
  TQString entryName;
  Data::CollPtr coll;
  Data::FieldVec fields;
  Data::FieldPtr currentField;
  Data::EntryVec entries;
  FilterPtr filter;
  Data::BorrowerPtr borrower;
  bool defaultFields;
  bool loadImages;
  bool hasImages;
};

class StateHandler {
public:
  StateHandler(StateData* data) : d(data) {}
  virtual ~StateHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&) = 0;
  virtual bool   end(const TQString&, const TQString&, const TQString&) = 0;

  StateHandler* nextHandler(const TQString&, const TQString&, const TQString&);
protected:
  StateData* d;
private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&)  { return 0; }
};

class NullHandler : public StateHandler {
public:
  NullHandler(StateData* data) : StateHandler(data) {}
  virtual ~NullHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&) { return true; }
  virtual bool   end(const TQString&, const TQString&, const TQString&) { return true; }
};

class RootHandler : public StateHandler {
public:
  RootHandler(StateData* data) : StateHandler(data) {}
  virtual ~RootHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&) { return true; }
  virtual bool   end(const TQString&, const TQString&, const TQString&) { return true; }

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
};

class DocumentHandler : public StateHandler {
public:
  DocumentHandler(StateData* data) : StateHandler(data) {}
  virtual ~DocumentHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
};

class CollectionHandler : public StateHandler {
public:
  CollectionHandler(StateData* data) : StateHandler(data) {}
  virtual ~CollectionHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
};

class FieldsHandler : public StateHandler {
public:
  FieldsHandler(StateData* data) : StateHandler(data) {}
  virtual ~FieldsHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
};

class FieldHandler : public StateHandler {
public:
  FieldHandler(StateData* data) : StateHandler(data) {}
  virtual ~FieldHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
};

class FieldPropertyHandler : public StateHandler {
public:
  FieldPropertyHandler(StateData* data) : StateHandler(data) {}
  virtual ~FieldPropertyHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  TQString m_propertyName;
};

class BibtexPreambleHandler : public StateHandler {
public:
  BibtexPreambleHandler(StateData* data) : StateHandler(data) {}
  virtual ~BibtexPreambleHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);
};

class BibtexMacrosHandler : public StateHandler {
public:
  BibtexMacrosHandler(StateData* data) : StateHandler(data) {}
  virtual ~BibtexMacrosHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
};

class BibtexMacroHandler : public StateHandler {
public:
  BibtexMacroHandler(StateData* data) : StateHandler(data) {}
  virtual ~BibtexMacroHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  TQString m_macroName;
};

class EntryHandler : public StateHandler {
public:
  EntryHandler(StateData* data) : StateHandler(data) {}
  virtual ~EntryHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
};

class FieldValueContainerHandler : public StateHandler {
public:
  FieldValueContainerHandler(StateData* data) : StateHandler(data) {}
  virtual ~FieldValueContainerHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
};

class FieldValueHandler : public StateHandler {
public:
  FieldValueHandler(StateData* data) : StateHandler(data) {}
  virtual ~FieldValueHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
  bool m_i18n;
  bool m_validateISBN;
};

class DateValueHandler : public StateHandler {
public:
  DateValueHandler(StateData* data) : StateHandler(data) {}
  virtual ~DateValueHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);
};

class TableColumnHandler : public StateHandler {
public:
  TableColumnHandler(StateData* data) : StateHandler(data) {}
  virtual ~TableColumnHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);
};

class ImagesHandler : public StateHandler {
public:
  ImagesHandler(StateData* data) : StateHandler(data) {}
  virtual ~ImagesHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
};

class ImageHandler : public StateHandler {
public:
  ImageHandler(StateData* data) : StateHandler(data) {}
  virtual ~ImageHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  TQString m_format;
  bool m_link;
  TQString m_imageId;
  int m_width;
  int m_height;
};

class FiltersHandler : public StateHandler {
public:
  FiltersHandler(StateData* data) : StateHandler(data) {}
  virtual ~FiltersHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
};

class FilterHandler : public StateHandler {
public:
  FilterHandler(StateData* data) : StateHandler(data) {}
  virtual ~FilterHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
};

class FilterRuleHandler : public StateHandler {
public:
  FilterRuleHandler(StateData* data) : StateHandler(data) {}
  virtual ~FilterRuleHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);
};

class BorrowersHandler : public StateHandler {
public:
  BorrowersHandler(StateData* data) : StateHandler(data) {}
  virtual ~BorrowersHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
};

class BorrowerHandler : public StateHandler {
public:
  BorrowerHandler(StateData* data) : StateHandler(data) {}
  virtual ~BorrowerHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  virtual StateHandler* nextHandlerImpl(const TQString&, const TQString&, const TQString&);
};

class LoanHandler : public StateHandler {
public:
  LoanHandler(StateData* data) : StateHandler(data) {}
  virtual ~LoanHandler() {}

  virtual bool start(const TQString&, const TQString&, const TQString&, const TQXmlAttributes&);
  virtual bool   end(const TQString&, const TQString&, const TQString&);

private:
  int m_id;
  TQString m_uid;
  TQString m_loanDate;
  TQString m_dueDate;
  bool m_inCalendar;
};

    }
  }
}
#endif