Debian Codegraph @

cds/savot/sax/SavotSAXParser.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.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 * It has been tested with kXML parser implementation
35 * </p>
36 *
37 * @author Andre Schaaff
38 */
39 @SuppressWarnings({"deprecation", "UseOfSystemOutOrSystemErr"})
40 public final class SavotSAXParser {
41
42 // the parser engine
43 private SavotSAXEngine engine = null;
44
45 /**
46 * Constructor
47 *
48 * @param consumer
49 * @param file
50 * a file to parse
51 */
52 public SavotSAXParser(SavotSAXConsumer consumer, String file) {
53 this(consumer, file, false);
54 }
55
56 /**
57 * Constructor
58 *
59 * @param consumer
60 * SavotSAXConsumer
61 * @param file
62 * a file to parse
63 * @param debug
64 * boolean
65 */
66 public SavotSAXParser(SavotSAXConsumer consumer, String file, boolean debug) {
67
68 try {
69 // new parser
70 XmlPullParser parser = new KXmlParser();
71
72 engine = new SavotSAXEngine(consumer, parser, file, debug);
73
74 // parse the stream
75 // engine.parse(parser);
76 // } catch (IOException e){
77 // System.err.println("SavotSAXParser : " + e);
78 } catch (Exception f) {
79 System.err.println("SavotSAXParser : " + f);
80 }
81 }
82
83 /**
84 * Constructor
85 *
86 * @param consumer
87 * SavotSAXConsumer
88 * @param url
89 * url to parse
90 * @param enc
91 * encoding (example : UTF-8)
92 */
93 public SavotSAXParser(SavotSAXConsumer consumer, URL url, String enc) {
94 this(consumer, url, enc, false);
95 }
96
97 /**
98 * Constructor
99 *
100 * @param consumer
101 * SavotSAXConsumer
102 * @param url
103 * url to parse
104 * @param enc
105 * encoding (example : UTF-8)
106 * @param debug
107 * boolean
108 */
109 public SavotSAXParser(SavotSAXConsumer consumer, URL url, String enc,
110 boolean debug) {
111
112 try {
113 // new parser
114 KXmlParser parser = new KXmlParser();
115
116 engine = new SavotSAXEngine(consumer, parser, url, enc, debug);
117
118 // parse the stream
119 // engine.parse(parser);
120 // } catch (IOException e){
121 // System.err.println("SavotSAXParser : " + e);
122 } catch (Exception f) {
123 System.err.println("SavotSAXParser : " + f);
124 }
125 }
126
127 /**
128 * Constructor
129 *
130 * @param consumer
131 * SavotSAXConsumer
132 * @param instream
133 * stream to parse
134 * @param enc
135 * encoding (example : UTF-8)
136 */
137 public SavotSAXParser(SavotSAXConsumer consumer, InputStream instream,
138 String enc) {
139 this(consumer, instream, enc, false);
140 }
141
142 /**
143 * Constructor
144 *
145 * @param consumer
146 * SavotSAXConsumer
147 * @param instream
148 * stream to parse
149 * @param enc
150 * encoding (example : UTF-8)
151 * @param debug
152 * boolean
153 */
154 public SavotSAXParser(SavotSAXConsumer consumer, InputStream instream,
155 String enc, boolean debug) {
156 try {
157 // new parser
158 KXmlParser parser = new KXmlParser();
159
160 engine = new SavotSAXEngine(consumer, parser, instream, enc, debug);
161
162 // parse the stream
163 // engine.parse(parser);
164 // } catch (IOException e){
165 // System.err.println("SavotSAXParser : " + e);
166 } catch (Exception f) {
167 System.err.println("SavotSAXParser : " + f);
168 }
169 }
170
171 /**
172 * Get Parser Version
173 *
174 * @return String
175 */
176 public String getVersion() {
177 return SavotSAXEngine.SAVOTPARSER;
178 }
179
180 /**
181 * Enable debug mode
182 *
183 * @param debug
184 * boolean
185 */
186 public void enableDebug(boolean debug) {
187 engine.enableDebug(debug);
188 }
189
190 /**
191 * Main
192 *
193 * @param argv
194 * @throws IOException
195 */
196 public static void main(String[] argv) throws IOException {
197 if (argv.length == 0) {
198 System.out.println("Usage: java SavotSAXParser <xml document>");
199 } else {
200 // new SavotSAXParser(consumer, argv[0]);
201 }
202 }
203 }