Debian Codegraph @

cds/astrores/sax/AstroresSAXParser.java

raw symbols SCIP
1 package cds.astrores.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.IOException;
25 import java.io.InputStream;
26 import java.net.URL;
27
28 // pull parser
29 import org.kxml2.io.KXmlParser;
30 import org.xmlpull.v1.XmlPullParser;
31
32 /**
33 * <p>
34 * Savot Pull Parser, t has been tested with kXML Pull parser implementation
35 * </p>
36 * <p>
37 * but it is possible to use other pull parsers
38 * </p>
39 * <p>
40 * Designed to use with Pull parsers complient with Standard Pull Implementation
41 * v1
42 * </p>
43 *
44 * @author Andre Schaaff
45 */
46 @SuppressWarnings({"deprecation", "UseOfSystemOutOrSystemErr"})
47 public class AstroresSAXParser {
48
49 // the pull parser engine
50 private AstroresSAXEngine engine = null;
51
52 /**
53 * Constructor
54 *
55 * @param consumer
56 * AstroresSAXConsumer
57 * @param file
58 * a file to parse
59 */
60 public AstroresSAXParser(AstroresSAXConsumer consumer, String file) {
61 this(consumer, file, false);
62 }
63
64 /**
65 * Constructor
66 *
67 * @param consumer
68 * AstroresSAXConsumer
69 * @param file
70 * a file to parse
71 * @param debug
72 * boolean
73 */
74 public AstroresSAXParser(AstroresSAXConsumer consumer, String file,
75 boolean debug) {
76
77 try {
78 // new parser
79 XmlPullParser parser = new KXmlParser();
80
81 engine = new AstroresSAXEngine(consumer, parser, file, debug);
82
83 engine.parse(parser);
84
85 } catch (IOException e) {
86 System.err.println("AstroresSAXParser : " + e);
87 } catch (Exception f) {
88 System.err.println("AstroresSAXParser : " + f);
89 }
90 }
91
92 /**
93 * Constructor
94 *
95 * @param consumer
96 * AstroresSAXConsumer
97 * @param url
98 * url to parse
99 * @param enc
100 * encoding (example : UTF-8)
101 */
102 public AstroresSAXParser(AstroresSAXConsumer consumer, URL url, String enc) {
103 this(consumer, url, enc, false);
104 }
105
106 /**
107 * Constructor
108 *
109 * @param consumer
110 * AstroresSAXConsumer
111 * @param url
112 * url to parse
113 * @param enc
114 * encoding (example : UTF-8)
115 * @param debug
116 * boolean
117 */
118 public AstroresSAXParser(AstroresSAXConsumer consumer, URL url, String enc,
119 boolean debug) {
120
121 try {
122 // new parser
123 KXmlParser parser = new KXmlParser();
124
125 engine = new AstroresSAXEngine(consumer, parser, url, enc, debug);
126
127 engine.parse(parser);
128
129 } catch (IOException e) {
130 System.err.println("AstroresSAXParser : " + e);
131 } catch (Exception f) {
132 System.err.println("AstroresSAXParser : " + f);
133 }
134 }
135
136 /**
137 * Constructor
138 *
139 * @param consumer
140 * AstroresSAXConsumer
141 * @param instream
142 * stream to parse
143 * @param enc
144 * encoding (example : UTF-8)
145 */
146 public AstroresSAXParser(AstroresSAXConsumer consumer,
147 InputStream instream, String enc) {
148 this(consumer, instream, enc, false);
149 }
150
151 /**
152 * Constructor
153 *
154 * @param consumer
155 * AstroresSAXConsumer
156 * @param instream
157 * stream to parse
158 * @param enc
159 * encoding (example : UTF-8)
160 * @param debug
161 * boolean
162 */
163 public AstroresSAXParser(AstroresSAXConsumer consumer,
164 InputStream instream, String enc, boolean debug) {
165 try {
166 // new parser
167 KXmlParser parser = new KXmlParser();
168
169 engine = new AstroresSAXEngine(consumer, parser, instream, enc,
170 debug);
171
172 engine.parse(parser);
173
174 } catch (IOException e) {
175 System.err.println("AstroresSAXParser : " + e);
176 } catch (Exception f) {
177 System.err.println("AstroresSAXParser : " + f);
178 }
179 }
180
181 /**
182 * Main
183 *
184 * @param argv
185 * @throws IOException
186 */
187 public static void main(String[] argv) throws IOException {
188
189 if (argv.length == 0) {
190 System.err.println("Usage: java AstroresSAXParser <xml document>");
191 } else {
192 // new AstroresSAXParser(argv[0]);
193 }
194 }
195 }