Debian Codegraph @

cds/savot/sax/SavotSAXEngine.java

raw symbols SCIP
1 package cds.savot.sax;
2
3 //Copyright 2002-2014 - UDS/CNRS
4 //The SAVOT library is distributed under the terms
5 //of the GNU General Public License version 3.
6 //
7 //This file is part of SAVOT.
8 //
9 //SAVOT is free software: you can redistribute it and/or modify
10 //it under the terms of the GNU General Public License as published by
11 //the Free Software Foundation, version 3 of the License.
12 //
13 //SAVOT is distributed in the hope that it will be useful,
14 //but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 //GNU General Public License for more details.
17 //
18 //The GNU General Public License is available in COPYING file
19 //along with SAVOT.
20 //
21 //SAVOT - Simple Access to VOTable - Parser
22 //
23 //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC)
24 import java.io.BufferedInputStream;
25 import java.io.DataInputStream;
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.net.URL;
31 import java.util.ArrayList;
32
33 import org.kxml2.io.KXmlParser;
34 import org.xmlpull.v1.XmlPullParser;
35
36 /**
37 * <p>
38 * It has been tested with kXML Pull parser implementation
39 * </p>
40 *
41 * @author Andre Schaaff
42 */
43 @SuppressWarnings({"deprecation", "UseOfSystemOutOrSystemErr"})
44 public final class SavotSAXEngine implements cds.savot.common.Markups {
45
46 // use for debug
47 private boolean trace = false;
48
49 // needed for sequential parsing
50 private XmlPullParser parser = null;
51
52 // SAVOT SAX consumer
53 SavotSAXConsumer consumer;
54
55 // father of a markup
56 ArrayList<String> father = new ArrayList<String>();
57
58 /**
59 *
60 */
61 public SavotSAXEngine() {
62 try {
63 jbInit();
64 } catch (Exception ex) {
65 ex.printStackTrace();
66 }
67 }
68
69 /**
70 * Constructor
71 *
72 * @param consumer
73 * SavotSAXConsumer
74 * @param parser
75 * XmlPullParser
76 * @param file
77 * a file to parse
78 * @param debug
79 * boolean
80 */
81 public SavotSAXEngine(SavotSAXConsumer consumer, XmlPullParser parser,
82 String file, boolean debug) {
83
84 try {
85 this.setParser(parser);
86 this.consumer = consumer;
87 enableDebug(debug);
88
89 // set the input of the parser
90 FileInputStream inStream = new FileInputStream(new File(file));
91 BufferedInputStream dataBuffInStream = new BufferedInputStream(inStream);
92
93 parser.setInput(dataBuffInStream, "UTF-8");
94
95 // parse the stream
96 parse(parser);
97
98 } catch (IOException e) {
99 System.err.println("Exception SavotSAXEngine : " + e);
100 } catch (Exception f) {
101 System.err.println("Exception SavotSAXEngine : " + f);
102 }
103 }
104
105 /**
106 * Constructor
107 *
108 * @param consumer
109 * SavotSAXConsumer
110 * @param parser
111 * XmlPullParser
112 * @param url
113 * url to parse
114 * @param enc
115 * encoding (example : UTF-8)
116 * @param debug
117 * boolean
118 */
119 public SavotSAXEngine(SavotSAXConsumer consumer, XmlPullParser parser,
120 URL url, String enc, boolean debug) {
121
122 try {
123 this.setParser(parser);
124 this.consumer = consumer;
125 enableDebug(debug);
126 // set the input of the parser (with the given encoding)
127 parser.setInput(new DataInputStream(url.openStream()), enc);
128
129 // parse the stream
130 parse(parser);
131
132 } catch (IOException e) {
133 System.err.println("Exception SavotSAXEngine : " + e);
134 } catch (Exception f) {
135 System.err.println("Exception SavotSAXEngine : " + f);
136 }
137 }
138
139 /**
140 * Constructor
141 *
142 * @param consumer
143 * SavotSAXConsumer
144 * @param parser
145 * XmlPullParser
146 * @param instream
147 * stream to parse
148 * @param enc
149 * encoding (example : UTF-8)
150 * @param debug
151 * boolean
152 */
153 public SavotSAXEngine(SavotSAXConsumer consumer, XmlPullParser parser,
154 InputStream instream, String enc, boolean debug) {
155 // public SavotSAXEngine(XmlPullParser parser, InputStream instream, int
156 // mode, String enc) {
157 try {
158 this.setParser(parser);
159 this.consumer = consumer;
160 enableDebug(debug);
161
162 // DataInputStream dataInStream = new DataInputStream(instream);
163 BufferedInputStream dataBuffInStream = new BufferedInputStream(instream);
164
165 // set the input of the parser (with the given encoding)
166 // parser.setInput(new DataInputStream(instream), enc);
167 parser.setInput(dataBuffInStream, enc);
168
169 // parser the stream
170 parse(parser);
171
172 } catch (IOException e) {
173 System.err.println("Exception SavotSAXEngine : " + e);
174 } catch (Exception f) {
175 System.err.println("Exception SavotSAXEngine : " + f);
176 }
177 }
178
179 /**
180 * Parsing engine
181 *
182 * @param parser
183 * an XML pull parser (example : kXML)
184 *
185 * @throws IOException
186 */
187 @SuppressWarnings({"unchecked", "deprecation"})
188 public void parse(XmlPullParser parser) throws IOException {
189
190 String currentMarkup = "XML";
191
192 try {
193
194 // envent type
195 int eventType = parser.getEventType();
196 father.add((parser.getName()));
197
198 // while the end of the document is not reach
199 while (eventType != XmlPullParser.END_DOCUMENT) {
200 // treatment depending on event type
201 switch (eventType) {
202 // if a start tag is reach
203 case KXmlParser.START_TAG:
204 try {
205 // the name of the current tag
206 currentMarkup = parser.getName();
207 father.add((parser.getName()));
208
209 // trace mode
210 if (trace) {
211 System.err.println("Name ---> " + parser.getName());
212 }
213 if (currentMarkup != null) {
214
215 // VOTABLE
216 if (currentMarkup.equalsIgnoreCase(VOTABLE)) {
217
218 ArrayList attributes = new ArrayList();
219 if (parser.getAttributeCount() != 0) {
220 if (parser.getAttributeValue(null, VERSION) != null) {
221 attributes.add(VERSION);
222 attributes.add(parser.getAttributeValue(null, VERSION));
223 }
224 if (parser.getAttributeValue(null, ID) != null) {
225 attributes.add(ID);
226 attributes.add(parser.getAttributeValue(null, ID));
227 }
228 consumer.startVotable(attributes);
229 }
230
231 // trace mode
232 if (trace) {
233 System.err.println("VOTABLE begin");
234 }
235 } else // DESCRIPTION
236 if (currentMarkup.equalsIgnoreCase(DESCRIPTION)) {
237 consumer.startDescription();
238
239 // trace mode
240 if (trace) {
241 System.err.println("DESCRIPTION begin");
242 }
243 } // RESOURCE
244 else if (currentMarkup.equalsIgnoreCase(RESOURCE)) {
245 ArrayList attributes = new ArrayList();
246
247 if (parser.getAttributeCount() != 0) {
248
249 if (parser.getAttributeValue(null, NAME) != null) {
250 attributes.add(NAME);
251 attributes.add(parser.getAttributeValue(null, NAME));
252 }
253
254 if (parser.getAttributeValue(null, TYPE) != null) {
255 attributes.add(TYPE);
256 attributes.add(parser.getAttributeValue(null, TYPE));
257 }
258
259 // new since VOTable 1.1
260 if (parser.getAttributeValue(null, UTYPE) != null) {
261 attributes.add(UTYPE);
262 attributes.add(parser.getAttributeValue(null, UTYPE));
263 }
264
265 if (parser.getAttributeValue(null, ID) != null) {
266 attributes.add(ID);
267 attributes.add(parser.getAttributeValue(null, ID));
268 }
269 }
270 consumer.startResource(attributes);
271 // trace mode
272 if (trace) {
273 System.err.println("RESOURCE");
274 }
275 } // TABLE
276 else if (currentMarkup.equalsIgnoreCase(TABLE)) {
277 ArrayList attributes = new ArrayList();
278 if (parser.getAttributeCount() != 0) {
279
280 if (parser.getAttributeValue(null, NAME) != null) {
281 attributes.add(NAME);
282 attributes.add(parser.getAttributeValue(null, NAME));
283 }
284
285 // new since VOTable 1.1
286 if (parser.getAttributeValue(null, UCD) != null) {
287 attributes.add(UCD);
288 attributes.add(parser.getAttributeValue(null, UCD));
289 }
290
291 // new since VOTable 1.1
292 if (parser.getAttributeValue(null, UTYPE) != null) {
293 attributes.add(UTYPE);
294 attributes.add(parser.getAttributeValue(null, UTYPE));
295 }
296
297 if (parser.getAttributeValue(null, REF) != null) {
298 attributes.add(REF);
299 attributes.add(parser.getAttributeValue(null, REF));
300 }
301
302 if (parser.getAttributeValue(null, ID) != null) {
303 attributes.add(ID);
304 attributes.add(parser.getAttributeValue(null, ID));
305 }
306
307 // new since VOTable 1.1
308 if (parser.getAttributeValue(null, NROWS) != null) {
309 attributes.add(NROWS);
310 attributes.add(parser.getAttributeValue(null, NROWS));
311 }
312 }
313 consumer.startTable(attributes);
314
315 // trace mode
316 if (trace) {
317 System.err.println("TABLE begin");
318 }
319 } // FIELD
320 else if (currentMarkup.equalsIgnoreCase(FIELD)) {
321 ArrayList attributes = new ArrayList();
322 if (parser.getAttributeCount() != 0) {
323
324 if (parser.getAttributeValue(null, UNIT) != null) {
325 attributes.add(UNIT);
326 attributes.add(parser.getAttributeValue(null, UNIT));
327 }
328
329 if (parser.getAttributeValue(null, DATATYPE) != null) {
330 attributes.add(DATATYPE);
331 attributes.add(parser.getAttributeValue(null, DATATYPE));
332 }
333
334 if (parser.getAttributeValue(null,
335 PRECISION) != null) {
336 attributes.add(PRECISION);
337 attributes.add(parser.getAttributeValue(null, PRECISION));
338 }
339
340 if (parser.getAttributeValue(null, WIDTH) != null) {
341 attributes.add(WIDTH);
342 attributes.add(parser.getAttributeValue(null, WIDTH));
343 }
344
345 // since VOTable 1.2
346 if (parser.getAttributeValue(null, XTYPE) != null) {
347 attributes.add(XTYPE);
348 attributes.add(parser.getAttributeValue(null, XTYPE));
349 }
350
351 if (parser.getAttributeValue(null, REF) != null) {
352 attributes.add(REF);
353 attributes.add(parser.getAttributeValue(null, REF));
354 }
355
356 if (parser.getAttributeValue(null, NAME) != null) {
357 attributes.add(NAME);
358 attributes.add(parser.getAttributeValue(null, NAME));
359 }
360
361 if (parser.getAttributeValue(null, UCD) != null) {
362 attributes.add(UCD);
363 attributes.add(parser.getAttributeValue(null, UCD));
364 }
365
366 if (parser.getAttributeValue(null,
367 ARRAYSIZE) != null) {
368 attributes.add(ARRAYSIZE);
369 attributes.add(parser.getAttributeValue(null, ARRAYSIZE));
370 }
371
372 if (parser.getAttributeValue(null, TYPE) != null) { // deprecated
373 // since
374 // VOTable
375 // 1.1
376 attributes.add(TYPE);
377 attributes.add(parser.getAttributeValue(null, TYPE));
378 }
379
380 if (parser.getAttributeValue(null, UTYPE) != null) {
381 attributes.add(UTYPE);
382 attributes.add(parser.getAttributeValue(null, UTYPE));
383 }
384
385 if (parser.getAttributeValue(null, ID) != null) {
386 attributes.add(ID);
387 attributes.add(parser.getAttributeValue(null, ID));
388 }
389 }
390 consumer.startField(attributes);
391
392 // trace mode
393 if (trace) {
394 System.err.println("FIELD begin");
395 }
396 } // FIELDREF
397 else if (currentMarkup.equalsIgnoreCase(FIELDREF)) {
398 ArrayList attributes = new ArrayList();
399 if (parser.getAttributeCount() != 0) {
400 if (parser.getAttributeValue(null, REF) != null) {
401 attributes.add(REF);
402 }
403 attributes.add(parser.getAttributeValue(null, REF));
404 }
405 consumer.startFieldref(attributes);
406
407 // trace mode
408 if (trace) {
409 System.err.println("FIELDREF begin");
410 }
411 } // VALUES
412 else if (currentMarkup.equalsIgnoreCase(VALUES)) {
413 ArrayList attributes = new ArrayList();
414 if (parser.getAttributeCount() != 0) {
415 if (parser.getAttributeValue(null, TYPE) != null) {
416 attributes.add(TYPE);
417 attributes.add(parser.getAttributeValue(null, TYPE));
418 }
419
420 if (parser.getAttributeValue(null, NULL) != null) {
421 attributes.add(NULL);
422 attributes.add(parser.getAttributeValue(null, NULL));
423 }
424
425 if (parser.getAttributeValue(null, INVALID) != null) { // deprecated
426 // since
427 // VOTable
428 // 1.1
429 attributes.add(INVALID);
430 attributes.add(parser.getAttributeValue(null, INVALID));
431 }
432
433 if (parser.getAttributeValue(null, REF) != null) {
434 attributes.add(REF);
435 attributes.add(parser.getAttributeValue(null, REF));
436 }
437
438 if (parser.getAttributeValue(null, ID) != null) {
439 attributes.add(ID);
440 attributes.add(parser.getAttributeValue(null, ID));
441 }
442 }
443 consumer.startValues(attributes);
444
445 // trace mode
446 if (trace) {
447 System.err.println("VALUES begin");
448 }
449 } // STREAM
450 else if (currentMarkup.equalsIgnoreCase(STREAM)) {
451 ArrayList attributes = new ArrayList();
452 if (parser.getAttributeCount() != 0) {
453
454 if (parser.getAttributeValue(null, TYPE) != null) {
455 attributes.add(TYPE);
456 attributes.add(parser.getAttributeValue(null, TYPE));
457 }
458 if (parser.getAttributeValue(null, HREF) != null) {
459 attributes.add(HREF);
460 attributes.add(parser.getAttributeValue(null, HREF));
461 }
462 if (parser.getAttributeValue(null, ACTUATE) != null) {
463 attributes.add(ACTUATE);
464 attributes.add(parser.getAttributeValue(null, ACTUATE));
465 }
466 if (parser
467 .getAttributeValue(null, ENCODING) != null) {
468 attributes.add(ENCODING);
469 attributes.add(parser.getAttributeValue(null, ENCODING));
470 }
471 if (parser.getAttributeValue(null, EXPIRES) != null) {
472 attributes.add(EXPIRES);
473 attributes.add(parser.getAttributeValue(null, EXPIRES));
474 }
475 if (parser.getAttributeValue(null, RIGHTS) != null) {
476 attributes.add(RIGHTS);
477 attributes.add(parser.getAttributeValue(null, RIGHTS));
478 }
479 }
480 consumer.startStream(attributes);
481
482 // trace mode
483 if (trace) {
484 System.err.println("STREAM begin");
485 }
486 } // TR
487 else if (currentMarkup.equalsIgnoreCase(TR)) {
488 consumer.startTR();
489
490 // trace mode
491 if (trace) {
492 System.err.println("TR begin");
493 }
494 } // TD
495 else if (currentMarkup.equalsIgnoreCase(TD)) {
496 ArrayList attributes = new ArrayList();
497
498 if (parser.getAttributeCount() != 0) {
499 if (parser
500 .getAttributeValue(null, ENCODING) != null) {
501 attributes.add(ENCODING);
502 attributes.add(parser
503 .getAttributeValue(null,
504 ENCODING));
505 }
506 }
507 consumer.startTD(attributes);
508
509 // trace mode
510 if (trace) {
511 System.err.println("TD begin");
512 }
513 } // DATA
514 else if (currentMarkup.equalsIgnoreCase(DATA)) {
515 consumer.startData();
516
517 // trace mode
518 if (trace) {
519 System.err.println("DATA begin");
520 }
521 } // BINARY
522 else if (currentMarkup.equalsIgnoreCase(BINARY)) {
523 consumer.startBinary();
524
525 // trace mode
526 if (trace) {
527 System.err.println("BINARY begin");
528 }
529 } // FITS
530 else if (currentMarkup.equalsIgnoreCase(FITS)) {
531 ArrayList attributes = new ArrayList();
532 if (parser.getAttributeCount() != 0) {
533 if (parser.getAttributeValue(null, EXTNUM) != null) {
534 attributes.add(EXTNUM);
535 attributes.add(parser.getAttributeValue(null, EXTNUM));
536 }
537 }
538 consumer.startFits(attributes);
539
540 // trace mode
541 if (trace) {
542 System.err.println("FITS begin");
543 }
544 } // TABLEDATA
545 else if (currentMarkup.equalsIgnoreCase(TABLEDATA)) {
546 consumer.startTableData();
547
548 // trace mode
549 if (trace) {
550 System.err.println("TABLEDATA begin");
551 }
552 } // PARAM
553 else if (currentMarkup.equalsIgnoreCase(PARAM)) {
554 ArrayList attributes = new ArrayList();
555 if (parser.getAttributeCount() != 0) {
556 if (parser.getAttributeValue(null, UNIT) != null) {
557 attributes.add(UNIT);
558 attributes.add(parser.getAttributeValue(null, UNIT));
559 }
560 if (parser
561 .getAttributeValue(null, DATATYPE) != null) {
562 attributes.add(DATATYPE);
563 attributes.add(parser.getAttributeValue(null, DATATYPE));
564 }
565 if (parser.getAttributeValue(null,
566 PRECISION) != null) {
567 attributes.add(PRECISION);
568 attributes.add(parser.getAttributeValue(null, PRECISION));
569 }
570 if (parser.getAttributeValue(null, WIDTH) != null) {
571 attributes.add(WIDTH);
572 attributes.add(parser.getAttributeValue(null, WIDTH));
573 }
574 // since VOTable 1.2
575 if (parser.getAttributeValue(null, XTYPE) != null) {
576 attributes.add(XTYPE);
577 attributes.add(parser.getAttributeValue(null, XTYPE));
578 }
579 if (parser.getAttributeValue(null, REF) != null) {
580 attributes.add(REF);
581 attributes.add(parser.getAttributeValue(null, REF));
582 }
583 if (parser.getAttributeValue(null, NAME) != null) {
584 attributes.add(NAME);
585 attributes.add(parser.getAttributeValue(null, NAME));
586 }
587 if (parser.getAttributeValue(null, UCD) != null) {
588 attributes.add(UCD);
589 attributes.add(parser.getAttributeValue(null, UCD));
590 }
591 if (parser.getAttributeValue(null, UTYPE) != null) { // new
592 // since
593 // VOTable
594 // 1.1
595 attributes.add(UTYPE);
596 attributes.add(parser.getAttributeValue(null, UTYPE));
597 }
598 if (parser.getAttributeValue(null, VALUE) != null) {
599 attributes.add(VALUE);
600 attributes.add(parser.getAttributeValue(null, VALUE));
601 }
602 if (parser.getAttributeValue(null,
603 ARRAYSIZE) != null) {
604 attributes.add(ARRAYSIZE);
605 attributes.add(parser.getAttributeValue(null, ARRAYSIZE));
606 }
607 if (parser.getAttributeValue(null, ID) != null) {
608 attributes.add(ID);
609 attributes.add(parser.getAttributeValue(null, ID));
610 }
611 }
612 consumer.startParam(attributes);
613
614 // trace mode
615 if (trace) {
616 System.err.println("PARAM begin");
617 }
618 } // PARAMREF
619 else if (currentMarkup.equalsIgnoreCase(PARAMREF)) { // new
620 // since
621 // VOTable
622 // 1.1
623 ArrayList attributes = new ArrayList();
624 if (parser.getAttributeCount() != 0) {
625 if (parser.getAttributeValue(null, REF) != null) {
626 attributes.add(REF);
627 attributes.add(parser.getAttributeValue(null, REF));
628 }
629 }
630 consumer.startParamRef(attributes);
631
632 // trace mode
633 if (trace) {
634 System.err.println("PARAMref begin");
635 }
636 } // LINK
637 else if (currentMarkup.equalsIgnoreCase(LINK)) {
638 ArrayList attributes = new ArrayList();
639 if (parser.getAttributeCount() != 0) {
640 if (parser.getAttributeValue(null,
641 CONTENTROLE) != null) {
642 attributes.add(CONTENTROLE);
643 attributes.add(parser.getAttributeValue(null, CONTENTROLE));
644 }
645 if (parser.getAttributeValue(null,
646 CONTENTTYPE) != null) {
647 attributes.add(CONTENTTYPE);
648 attributes.add(parser.getAttributeValue(null, CONTENTTYPE));
649 }
650 if (parser.getAttributeValue(null, TITLE) != null) {
651 attributes.add(TITLE);
652 attributes.add(parser.getAttributeValue(null, TITLE));
653 }
654 if (parser.getAttributeValue(null, VALUE) != null) {
655 attributes.add(VALUE);
656 attributes.add(parser.getAttributeValue(null, VALUE));
657 }
658 if (parser.getAttributeValue(null, HREF) != null) {
659 attributes.add(HREF);
660 attributes.add(parser.getAttributeValue(null, HREF));
661 }
662 if (parser.getAttributeValue(null, GREF) != null) { // deprecated
663 // since
664 // VOTable
665 // 1.1
666 attributes.add(GREF);
667 attributes.add(parser.getAttributeValue(null, GREF));
668 }
669 if (parser.getAttributeValue(null, ACTION) != null) {
670 attributes.add(ACTION);
671 attributes.add(parser.getAttributeValue(null, ACTION));
672 }
673 if (parser.getAttributeValue(null, ID) != null) {
674 attributes.add(ID);
675 attributes.add(parser.getAttributeValue(null, ID));
676 }
677 }
678 consumer.startLink(attributes);
679
680 if (trace) {
681 System.err.println("LINK begin");
682 }
683 } // INFO
684 else if (currentMarkup.equalsIgnoreCase(INFO)) {
685 ArrayList attributes = new ArrayList();
686 if (parser.getAttributeCount() != 0) {
687 if (parser.getAttributeValue(null, NAME) != null) {
688 attributes.add(NAME);
689 attributes.add(parser.getAttributeValue(null, NAME));
690 }
691 if (parser.getAttributeValue(null, VALUE) != null) {
692 attributes.add(VALUE);
693 attributes.add(parser.getAttributeValue(null, VALUE));
694 }
695 if (parser.getAttributeValue(null, ID) != null) {
696 attributes.add(ID);
697 attributes.add(parser.getAttributeValue(null, ID));
698 }
699 // since VOTable 1.2
700 if (parser.getAttributeValue(null, XTYPE) != null) {
701 attributes.add(XTYPE);
702 attributes.add(parser.getAttributeValue(null, XTYPE));
703 }
704 // since VOTable 1.2
705 if (parser.getAttributeValue(null, REF) != null) {
706 attributes.add(REF);
707 attributes.add(parser.getAttributeValue(null, REF));
708 }
709 // since VOTable 1.2
710 if (parser.getAttributeValue(null, UNIT) != null) {
711 attributes.add(UNIT);
712 attributes.add(parser.getAttributeValue(null, UNIT));
713 }
714 // since VOTable 1.2
715 if (parser.getAttributeValue(null, UCD) != null) {
716 attributes.add(UCD);
717 attributes.add(parser.getAttributeValue(null, UCD));
718 }
719 // since VOTable 1.2
720 if (parser.getAttributeValue(null, UTYPE) != null) {
721 attributes.add(UTYPE);
722 attributes.add(parser.getAttributeValue(null, UTYPE));
723 }
724 }
725 consumer.startInfo(attributes);
726
727 if (trace) {
728 System.err.println("INFO begin");
729 }
730 } // MIN
731 else if (currentMarkup.equalsIgnoreCase(MIN)) {
732 ArrayList attributes = new ArrayList();
733 if (parser.getAttributeCount() != 0) {
734 if (parser.getAttributeValue(null, VALUE) != null) {
735 attributes.add(VALUE);
736 attributes.add(parser.getAttributeValue(null, VALUE));
737 }
738 if (parser.getAttributeValue(null, INCLUSIVE) != null) {
739 attributes.add(INCLUSIVE);
740 attributes.add(parser.getAttributeValue(null, INCLUSIVE));
741 }
742 }
743 consumer.startMin(attributes);
744
745 // mode trace
746 if (trace) {
747 System.err.println("MIN begin");
748 }
749 } // MAX
750 else if (currentMarkup.equalsIgnoreCase(MAX)) {
751 ArrayList attributes = new ArrayList();
752
753 if (parser.getAttributeCount() != 0) {
754 if (parser.getAttributeValue(null, VALUE) != null) {
755 attributes.add(VALUE);
756 attributes.add(parser.getAttributeValue(null, VALUE));
757 }
758 if (parser.getAttributeValue(null,
759 INCLUSIVE) != null) {
760 attributes.add(INCLUSIVE);
761 attributes.add(parser.getAttributeValue(null, INCLUSIVE));
762 }
763 }
764 consumer.startMax(attributes);
765
766 // mode trace
767 if (trace) {
768 System.err.println("MAX begin ");
769 }
770 } // OPTION
771 else if (currentMarkup.equalsIgnoreCase(OPTION)) {
772 ArrayList attributes = new ArrayList();
773
774 if (parser.getAttributeCount() != 0) {
775 if (parser.getAttributeValue(null, NAME) != null) {
776 attributes.add(NAME);
777 attributes.add(parser.getAttributeValue(null, NAME));
778 }
779 if (parser.getAttributeValue(null, VALUE) != null) {
780 attributes.add(VALUE);
781 attributes.add(parser.getAttributeValue(null, VALUE));
782 }
783 }
784 consumer.startOption(attributes);
785
786 // mode trace
787 if (trace) {
788 System.err.println("OPTION begin - not included");
789 }
790 } // GROUP new 1.1
791 else if (currentMarkup.equalsIgnoreCase(GROUP)) {
792 ArrayList attributes = new ArrayList();
793
794 if (parser.getAttributeCount() != 0) {
795 if (parser.getAttributeValue(null, REF) != null) {
796 attributes.add(REF);
797 attributes.add(parser.getAttributeValue(null, REF));
798 }
799 if (parser.getAttributeValue(null, NAME) != null) {
800 attributes.add(NAME);
801 attributes.add(parser.getAttributeValue(null, NAME));
802 }
803 if (parser.getAttributeValue(null, UCD) != null) {
804 attributes.add(UCD);
805 attributes.add(parser.getAttributeValue(null, UCD));
806 }
807 if (parser.getAttributeValue(null, UTYPE) != null) {
808 attributes.add(UTYPE);
809 attributes.add(parser.getAttributeValue(null, UTYPE));
810 }
811 if (parser.getAttributeValue(null, ID) != null) {
812 attributes.add(ID);
813 attributes.add(parser.getAttributeValue(null, ID));
814 }
815 }
816 consumer.startGroup(attributes);
817
818 // mode trace
819 if (trace) {
820 System.err.println("GROUP begin - not included");
821 }
822 } // COOSYS - deprecated since VOTable 1.2
823 else if (currentMarkup.equalsIgnoreCase(COOSYS)) {
824 ArrayList attributes = new ArrayList();
825
826 if (parser.getAttributeCount() != 0) {
827 if (parser.getAttributeValue(null, EQUINOX) != null) {
828 attributes.add(EQUINOX);
829 attributes.add(parser.getAttributeValue(null, EQUINOX));
830 }
831 if (parser.getAttributeValue(null, EPOCH) != null) {
832 attributes.add(EPOCH);
833 attributes.add(parser.getAttributeValue(null, EPOCH));
834 }
835 if (parser.getAttributeValue(null, SYSTEM) != null) {
836 attributes.add(SYSTEM);
837 attributes.add(parser.getAttributeValue(null, SYSTEM));
838 }
839 if (parser.getAttributeValue(null, ID) != null) {
840 attributes.add(ID);
841 attributes.add(parser.getAttributeValue(null, ID));
842 }
843 }
844 consumer.startCoosys(attributes);
845
846 // mode trace
847 if (trace) {
848 System.err.println("COOSYS begin");
849 }
850 } // DEFINITIONS - deprecated since VOTable 1.1
851 else if (currentMarkup.equalsIgnoreCase(DEFINITIONS)) {
852 consumer.startDefinitions();
853
854 // mode trace
855 if (trace) {
856 System.err.println("DEFINITIONS begin");
857 }
858 } else {
859 System.err.println("VOTable markup error : "
860 + currentMarkup + " at line "
861 + parser.getLineNumber());
862 }
863 } // currentMarkup = name;
864 } catch (Exception e) {
865 System.err.println("Exception START_TAG : " + e
866 + " at line " + parser.getLineNumber());
867 }
868 break;
869
870 // if an end tag is reach
871 case KXmlParser.END_TAG:
872 try {
873 if (trace) {
874 System.err.println("End ---> " + currentMarkup);
875 }
876 // DESCRIPTION
877 if (currentMarkup.equalsIgnoreCase(DESCRIPTION)) {
878 consumer.endDescription();
879
880 // trace mode
881 if (trace) {
882 System.err.println("DESCRIPTION");
883 }
884 } // TABLE
885 else if (currentMarkup.equalsIgnoreCase(TABLE)) {
886 consumer.endTable();
887
888 // trace mode
889 if (trace) {
890 System.err.println("TABLE");
891 }
892 } // FIELD
893 else if (currentMarkup.equalsIgnoreCase(FIELD)) {
894 consumer.endField();
895
896 // trace mode
897 if (trace) {
898 System.err.println("FIELD");
899 }
900 } // FIELDref
901 else if (currentMarkup.equalsIgnoreCase(FIELDREF)) {
902 consumer.endFieldref();
903
904 // trace mode
905 if (trace) {
906 System.err.println("FIELDRef");
907 }
908 } // TR
909 else if (currentMarkup.equalsIgnoreCase(TR)) {
910 consumer.endTR();
911
912 // trace mode
913 if (trace) {
914 System.err.println("TR");
915 }
916 } // DATA
917 else if (currentMarkup.equalsIgnoreCase(DATA)) {
918 consumer.endData();
919
920 // trace mode
921 if (trace) {
922 System.err.println("DATA");
923 }
924 } // TD
925 else if (currentMarkup.equalsIgnoreCase(TD)) {
926 consumer.endTD();
927
928 // trace mode
929 if (trace) {
930 System.err.println("TD");
931 }
932 } // RESOURCE
933 else if (currentMarkup.equalsIgnoreCase(RESOURCE)) {
934 consumer.endResource();
935
936 // trace mode
937 if (trace) {
938 System.err.println("RESOURCE");
939 }
940 } // OPTION
941 else if (currentMarkup.equalsIgnoreCase(OPTION)) {
942 consumer.endOption();
943
944 // trace mode
945 if (trace) {
946 System.err.println("OPTION");
947 }
948 } // GROUP
949 else if (currentMarkup.equalsIgnoreCase(GROUP)) {
950 consumer.endGroup();
951
952 // trace mode
953 if (trace) {
954 System.err.println("GROUP");
955 }
956 } // TABLEDATA
957 else if (currentMarkup.equalsIgnoreCase(TABLEDATA)) {
958 consumer.endTableData();
959
960 // trace mode
961 if (trace) {
962 System.err.println("TABLEDATA");
963 }
964 } // COOSYS - deprecated since VOTable 1.2
965 else if (currentMarkup.equalsIgnoreCase(COOSYS)) {
966 consumer.endCoosys();
967
968 // trace mode
969 if (trace) {
970 System.err.println("COOSYS");
971 }
972 } // PARAM
973 else if (currentMarkup.equalsIgnoreCase(PARAM)) {
974 consumer.endParam();
975
976 // trace mode
977 if (trace) {
978 System.err.println("PARAM");
979 }
980 } // PARAMREF
981 else if (currentMarkup.equalsIgnoreCase(PARAMREF)) {
982 consumer.endParamRef();
983
984 // trace mode
985 if (trace) {
986 System.err.println("PARAMRef");
987 }
988 } // LINK
989 else if (currentMarkup.equalsIgnoreCase(LINK)) {
990 consumer.endLink();
991
992 // trace mode
993 if (trace) {
994 System.err.println("LINK");
995 }
996 } // VALUES
997 else if (currentMarkup.equalsIgnoreCase(VALUES)) {
998 consumer.endValues();
999
1000 // trace mode
1001 if (trace) {
1002 System.err.println("VALUES");
1003 }
1004 } // MIN
1005 else if (currentMarkup.equalsIgnoreCase(MIN)) {
1006 consumer.endMin();
1007
1008 // trace mode
1009 if (trace) {
1010 System.err.println("MIN");
1011 }
1012 } // MAX
1013 else if (currentMarkup.equalsIgnoreCase(MAX)) {
1014 consumer.endMax();
1015
1016 // trace mode
1017 if (trace) {
1018 System.err.println("MAX");
1019 }
1020 } // STREAM
1021 else if (currentMarkup.equalsIgnoreCase(STREAM)) {
1022 consumer.endStream();
1023
1024 // trace mode
1025 if (trace) {
1026 System.err.println("STREAM");
1027 }
1028 } // BINARY
1029 else if (currentMarkup.equalsIgnoreCase(BINARY)) {
1030 consumer.endBinary();
1031
1032 // trace mode
1033 if (trace) {
1034 System.err.println("BINARY");
1035 }
1036 } // FITS
1037 else if (currentMarkup.equalsIgnoreCase(FITS)) {
1038 consumer.endFits();
1039
1040 // trace mode
1041 if (trace) {
1042 System.err.println("FITS");
1043 }
1044 } // INFO
1045 else if (currentMarkup.equalsIgnoreCase(INFO)) {
1046 consumer.endInfo();
1047
1048 // trace mode
1049 if (trace) {
1050 System.err.println("INFO");
1051 }
1052 } // DEFINITIONS - deprecated since VOTable 1.1
1053 else if (currentMarkup.equalsIgnoreCase(DEFINITIONS)) {
1054 consumer.endDefinitions();
1055
1056 // trace mode
1057 if (trace) {
1058 System.err.println("DEFINITIONS");
1059 }
1060 } // VOTABLE
1061 else if (currentMarkup.equalsIgnoreCase(VOTABLE)) {
1062 consumer.endVotable();
1063
1064 // trace mode
1065 if (trace) {
1066 System.err.println("VOTABLE");
1067 }
1068 } else {
1069 System.err.println("VOTable markup error : "
1070 + currentMarkup + " at line "
1071 + parser.getLineNumber());
1072 }
1073
1074 father.remove(father.size() - 1);
1075 currentMarkup = (String) father.get(father.size() - 1);
1076
1077 } catch (Exception e) {
1078 System.err.println("Exception END_TAG : " + e + " at line " + parser.getLineNumber());
1079 }
1080 break;
1081
1082 case KXmlParser.END_DOCUMENT:
1083 try {
1084 consumer.endDocument();
1085
1086 // trace mode
1087 if (trace) {
1088 System.err.println("Document end reached!");
1089 }
1090 } catch (Exception e) {
1091 System.err.println("Exception END_DOCUMENT : " + e + " at line " + parser.getLineNumber());
1092 }
1093 break;
1094
1095 case KXmlParser.TEXT:
1096 try {
1097 // TD
1098 if (currentMarkup.equalsIgnoreCase(TD)) {
1099 consumer.textTD((parser.getText()).trim());
1100
1101 // trace mode
1102 if (trace) {
1103 System.err.println("TD : "
1104 + (parser.getText()).trim());
1105 }
1106 } // STREAM
1107 else if (currentMarkup.equalsIgnoreCase(STREAM)) {
1108 consumer.textStream((parser.getText()).trim());
1109
1110 // trace mode
1111 if (trace) {
1112 System.err.println("STREAM : " + (parser.getText()).trim());
1113 }
1114 } // DESCRIPTION
1115 else if (currentMarkup.equalsIgnoreCase(DESCRIPTION)) {
1116 consumer.textDescription((parser.getText()).trim());
1117
1118 // trace mode
1119 if (trace) {
1120 System.err.println("DESCRIPTION : " + (parser.getText()).trim());
1121 }
1122 } // MIN
1123 else if (currentMarkup.equalsIgnoreCase(MIN)) {
1124 consumer.textMin((parser.getText()).trim());
1125
1126 // trace mode
1127 if (trace) {
1128 System.err.println("MIN : " + (parser.getText()).trim());
1129 }
1130 } // MAX
1131 else if (currentMarkup.equalsIgnoreCase(MAX)) {
1132 consumer.textMax((parser.getText()).trim());
1133
1134 // trace mode
1135 if (trace) {
1136 System.err.println("MAX : " + (parser.getText()).trim());
1137 }
1138 } // COOSYS - deprecated since VOTable 1.2
1139 else if (currentMarkup.equalsIgnoreCase(COOSYS)) {
1140 consumer.textCoosys((parser.getText()).trim());
1141
1142 // trace mode
1143 if (trace) {
1144 System.err.println("COOSYS : " + (parser.getText()).trim());
1145 }
1146 } // LINK
1147 else if (currentMarkup.equalsIgnoreCase(LINK)) {
1148 consumer.textLink((parser.getText()).trim());
1149
1150 // trace mode
1151 if (trace) {
1152 System.err.println("LINK : " + (parser.getText()).trim());
1153 }
1154 } // OPTION
1155 else if (currentMarkup.equalsIgnoreCase(OPTION)) {
1156 consumer.textOption((parser.getText()).trim());
1157
1158 // trace mode
1159 if (trace) {
1160 System.err.println("OPTION : " + (parser.getText()).trim());
1161 }
1162 } // GROUP
1163 else if (currentMarkup.equalsIgnoreCase(GROUP)) {
1164 consumer.textGroup((parser.getText()).trim());
1165
1166 // trace mode
1167 if (trace) {
1168 System.err.println("GROUP : " + (parser.getText()).trim());
1169 }
1170 } // INFO
1171 else if (currentMarkup.equalsIgnoreCase(INFO)) {
1172 consumer.textInfo((parser.getText()).trim());
1173
1174 // trace mode
1175 if (trace) {
1176 System.err.println("INFO : " + (parser.getText()).trim());
1177 }
1178 }
1179 } catch (Exception e) {
1180 System.err.println("Exception TEXT : " + e + " at line " + parser.getLineNumber());
1181 }
1182 break;
1183
1184 case KXmlParser.START_DOCUMENT:
1185 try {
1186 consumer.startDocument();
1187
1188 // trace mode
1189 if (trace) {
1190 System.err.println("Document start reached!");
1191 }
1192 } catch (Exception e) {
1193 System.err.println("Exception START_DOCUMENT : " + e + " at line " + parser.getLineNumber());
1194 }
1195 break;
1196
1197 default:
1198 if (trace) {
1199 System.err.println(" ignoring some other (legacy) event at line : " + parser.getLineNumber());
1200 }
1201 }
1202
1203 // new values
1204 eventType = parser.next();
1205 }
1206 } catch (Exception f) {
1207 System.err.println("Exception parse : " + f + " at line " + parser.getLineNumber());
1208 }
1209 try {
1210 consumer.endDocument();
1211
1212 // trace mode
1213 if (trace) {
1214 System.err.println("Document end reached!");
1215 }
1216 } catch (Exception e) {
1217 System.err.println("Exception END_DOCUMENT : " + e + " at line " + parser.getLineNumber());
1218 }
1219 }
1220
1221 /**
1222 * Enable debug mode
1223 *
1224 * @param debug
1225 * boolean
1226 */
1227 public void enableDebug(boolean debug) {
1228 trace = debug;
1229 }
1230
1231 private void jbInit() throws Exception {
1232 }
1233
1234 public XmlPullParser getParser() {
1235 return parser;
1236 }
1237
1238 public void setParser(XmlPullParser parser) {
1239 this.parser = parser;
1240 }
1241 }