69688a552d7a0d30e1f4e36f39f0ad9ba3574784
[jalviewjs.git] / site / j2s / org / xml / sax / helpers / ParserAdapter.js
1 Clazz.declarePackage ("org.xml.sax.helpers");
2 Clazz.load (["org.xml.sax.Attributes", "$.DocumentHandler", "$.XMLReader"], "org.xml.sax.helpers.ParserAdapter", ["java.lang.IllegalStateException", "$.NullPointerException", "java.util.Vector", "org.xml.sax.InputSource", "$.SAXException", "$.SAXNotRecognizedException", "$.SAXNotSupportedException", "$.SAXParseException", "org.xml.sax.helpers.AttributesImpl", "$.NamespaceSupport", "$.ParserFactory"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.nsSupport = null;
5 this.attAdapter = null;
6 this.parsing = false;
7 this.nameParts = null;
8 this.parser = null;
9 this.atts = null;
10 this.namespaces = true;
11 this.prefixes = false;
12 this.uris = false;
13 this.locator = null;
14 this.entityResolver = null;
15 this.dtdHandler = null;
16 this.contentHandler = null;
17 this.errorHandler = null;
18 if (!Clazz.isClassDefined ("org.xml.sax.helpers.ParserAdapter.AttributeListAdapter")) {
19 org.xml.sax.helpers.ParserAdapter.$ParserAdapter$AttributeListAdapter$ ();
20 }
21 Clazz.instantialize (this, arguments);
22 }, org.xml.sax.helpers, "ParserAdapter", null, [org.xml.sax.XMLReader, org.xml.sax.DocumentHandler]);
23 Clazz.prepareFields (c$, function () {
24 this.nameParts =  new Array (3);
25 });
26 Clazz.makeConstructor (c$, 
27 function () {
28 var driver = System.getProperty ("org.xml.sax.parser");
29 try {
30 this.setup (org.xml.sax.helpers.ParserFactory.makeParser ());
31 } catch (e$$) {
32 if (Clazz.exceptionOf (e$$, ClassNotFoundException)) {
33 var e1 = e$$;
34 {
35 throw  new org.xml.sax.SAXException ("Cannot find SAX1 driver class " + driver, e1);
36 }
37 } else if (Clazz.exceptionOf (e$$, IllegalAccessException)) {
38 var e2 = e$$;
39 {
40 throw  new org.xml.sax.SAXException ("SAX1 driver class " + driver + " found but cannot be loaded", e2);
41 }
42 } else if (Clazz.exceptionOf (e$$, InstantiationException)) {
43 var e3 = e$$;
44 {
45 throw  new org.xml.sax.SAXException ("SAX1 driver class " + driver + " loaded but cannot be instantiated", e3);
46 }
47 } else if (Clazz.exceptionOf (e$$, ClassCastException)) {
48 var e4 = e$$;
49 {
50 throw  new org.xml.sax.SAXException ("SAX1 driver class " + driver + " does not implement org.xml.sax.Parser");
51 }
52 } else if (Clazz.exceptionOf (e$$, NullPointerException)) {
53 var e5 = e$$;
54 {
55 throw  new org.xml.sax.SAXException ("System property org.xml.sax.parser not specified");
56 }
57 } else {
58 throw e$$;
59 }
60 }
61 });
62 Clazz.makeConstructor (c$, 
63 function (parser) {
64 this.setup (parser);
65 }, "org.xml.sax.Parser");
66 Clazz.defineMethod (c$, "setup", 
67  function (parser) {
68 if (parser == null) {
69 throw  new NullPointerException ("Parser argument must not be null");
70 }this.parser = parser;
71 this.atts =  new org.xml.sax.helpers.AttributesImpl ();
72 this.nsSupport =  new org.xml.sax.helpers.NamespaceSupport ();
73 this.attAdapter = Clazz.innerTypeInstance (org.xml.sax.helpers.ParserAdapter.AttributeListAdapter, this, null);
74 }, "org.xml.sax.Parser");
75 Clazz.overrideMethod (c$, "setFeature", 
76 function (name, value) {
77 if (name.equals ("http://xml.org/sax/features/namespaces")) {
78 this.checkNotParsing ("feature", name);
79 this.namespaces = value;
80 if (!this.namespaces && !this.prefixes) {
81 this.prefixes = true;
82 }} else if (name.equals ("http://xml.org/sax/features/namespace-prefixes")) {
83 this.checkNotParsing ("feature", name);
84 this.prefixes = value;
85 if (!this.prefixes && !this.namespaces) {
86 this.namespaces = true;
87 }} else if (name.equals ("http://xml.org/sax/features/xmlns-uris")) {
88 this.checkNotParsing ("feature", name);
89 this.uris = value;
90 } else {
91 throw  new org.xml.sax.SAXNotRecognizedException ("Feature: " + name);
92 }}, "~S,~B");
93 Clazz.overrideMethod (c$, "getFeature", 
94 function (name) {
95 if (name.equals ("http://xml.org/sax/features/namespaces")) {
96 return this.namespaces;
97 } else if (name.equals ("http://xml.org/sax/features/namespace-prefixes")) {
98 return this.prefixes;
99 } else if (name.equals ("http://xml.org/sax/features/xmlns-uris")) {
100 return this.uris;
101 } else {
102 throw  new org.xml.sax.SAXNotRecognizedException ("Feature: " + name);
103 }}, "~S");
104 Clazz.overrideMethod (c$, "setProperty", 
105 function (name, value) {
106 throw  new org.xml.sax.SAXNotRecognizedException ("Property: " + name);
107 }, "~S,~O");
108 Clazz.overrideMethod (c$, "getProperty", 
109 function (name) {
110 throw  new org.xml.sax.SAXNotRecognizedException ("Property: " + name);
111 }, "~S");
112 Clazz.overrideMethod (c$, "setEntityResolver", 
113 function (resolver) {
114 this.entityResolver = resolver;
115 }, "org.xml.sax.EntityResolver");
116 Clazz.overrideMethod (c$, "getEntityResolver", 
117 function () {
118 return this.entityResolver;
119 });
120 Clazz.overrideMethod (c$, "setDTDHandler", 
121 function (handler) {
122 this.dtdHandler = handler;
123 }, "org.xml.sax.DTDHandler");
124 Clazz.overrideMethod (c$, "getDTDHandler", 
125 function () {
126 return this.dtdHandler;
127 });
128 Clazz.overrideMethod (c$, "setContentHandler", 
129 function (handler) {
130 this.contentHandler = handler;
131 }, "org.xml.sax.ContentHandler");
132 Clazz.overrideMethod (c$, "getContentHandler", 
133 function () {
134 return this.contentHandler;
135 });
136 Clazz.overrideMethod (c$, "setErrorHandler", 
137 function (handler) {
138 this.errorHandler = handler;
139 }, "org.xml.sax.ErrorHandler");
140 Clazz.overrideMethod (c$, "getErrorHandler", 
141 function () {
142 return this.errorHandler;
143 });
144 Clazz.defineMethod (c$, "parse", 
145 function (systemId) {
146 this.parse ( new org.xml.sax.InputSource (systemId));
147 }, "~S");
148 Clazz.defineMethod (c$, "parse", 
149 function (input) {
150 if (this.parsing) {
151 throw  new org.xml.sax.SAXException ("Parser is already in use");
152 }this.setupParser ();
153 this.parsing = true;
154 try {
155 this.parser.parse (input);
156 } finally {
157 this.parsing = false;
158 }
159 this.parsing = false;
160 }, "org.xml.sax.InputSource");
161 Clazz.overrideMethod (c$, "setDocumentLocator", 
162 function (locator) {
163 this.locator = locator;
164 if (this.contentHandler != null) {
165 this.contentHandler.setDocumentLocator (locator);
166 }}, "org.xml.sax.Locator");
167 Clazz.overrideMethod (c$, "startDocument", 
168 function () {
169 if (this.contentHandler != null) {
170 this.contentHandler.startDocument ();
171 }});
172 Clazz.overrideMethod (c$, "endDocument", 
173 function () {
174 if (this.contentHandler != null) {
175 this.contentHandler.endDocument ();
176 }});
177 Clazz.overrideMethod (c$, "startElement", 
178 function (qName, qAtts) {
179 var exceptions = null;
180 if (!this.namespaces) {
181 if (this.contentHandler != null) {
182 this.attAdapter.setAttributeList (qAtts);
183 this.contentHandler.startElement ("", "", qName.intern (), this.attAdapter);
184 }return;
185 }this.nsSupport.pushContext ();
186 var length = qAtts.getLength ();
187 for (var i = 0; i < length; i++) {
188 var attQName = qAtts.getName (i);
189 if (!attQName.startsWith ("xmlns")) continue;
190 var prefix;
191 var n = attQName.indexOf (':');
192 if (n == -1 && attQName.length == 5) {
193 prefix = "";
194 } else if (n != 5) {
195 continue;
196 } else prefix = attQName.substring (n + 1);
197 var value = qAtts.getValue (i);
198 if (!this.nsSupport.declarePrefix (prefix, value)) {
199 this.reportError ("Illegal Namespace prefix: " + prefix);
200 continue;
201 }if (this.contentHandler != null) this.contentHandler.startPrefixMapping (prefix, value);
202 }
203 this.atts.clear ();
204 for (var i = 0; i < length; i++) {
205 var attQName = qAtts.getName (i);
206 var type = qAtts.getType (i);
207 var value = qAtts.getValue (i);
208 if (attQName.startsWith ("xmlns")) {
209 var prefix;
210 var n = attQName.indexOf (':');
211 if (n == -1 && attQName.length == 5) {
212 prefix = "";
213 } else if (n != 5) {
214 prefix = null;
215 } else {
216 prefix = attQName.substring (6);
217 }if (prefix != null) {
218 if (this.prefixes) {
219 if (this.uris) this.atts.addAttribute (org.xml.sax.helpers.NamespaceSupport.XMLNS, prefix, attQName.intern (), type, value);
220  else this.atts.addAttribute ("", "", attQName.intern (), type, value);
221 }continue;
222 }}try {
223 var attName = this.processName (attQName, true, true);
224 this.atts.addAttribute (attName[0], attName[1], attName[2], type, value);
225 } catch (e) {
226 if (Clazz.exceptionOf (e, org.xml.sax.SAXException)) {
227 if (exceptions == null) exceptions =  new java.util.Vector ();
228 exceptions.addElement (e);
229 this.atts.addAttribute ("", attQName, attQName, type, value);
230 } else {
231 throw e;
232 }
233 }
234 }
235 if (exceptions != null && this.errorHandler != null) {
236 for (var i = 0; i < exceptions.size (); i++) this.errorHandler.error ((exceptions.elementAt (i)));
237
238 }if (this.contentHandler != null) {
239 var name = this.processName (qName, false, false);
240 this.contentHandler.startElement (name[0], name[1], name[2], this.atts);
241 }}, "~S,org.xml.sax.AttributeList");
242 Clazz.overrideMethod (c$, "endElement", 
243 function (qName) {
244 if (!this.namespaces) {
245 if (this.contentHandler != null) {
246 this.contentHandler.endElement ("", "", qName.intern ());
247 }return;
248 }var names = this.processName (qName, false, false);
249 if (this.contentHandler != null) {
250 this.contentHandler.endElement (names[0], names[1], names[2]);
251 var prefixes = this.nsSupport.getDeclaredPrefixes ();
252 while (prefixes.hasMoreElements ()) {
253 var prefix = prefixes.nextElement ();
254 this.contentHandler.endPrefixMapping (prefix);
255 }
256 }this.nsSupport.popContext ();
257 }, "~S");
258 Clazz.overrideMethod (c$, "characters", 
259 function (ch, start, length) {
260 if (this.contentHandler != null) {
261 this.contentHandler.characters (ch, start, length);
262 }}, "~A,~N,~N");
263 Clazz.overrideMethod (c$, "ignorableWhitespace", 
264 function (ch, start, length) {
265 if (this.contentHandler != null) {
266 this.contentHandler.ignorableWhitespace (ch, start, length);
267 }}, "~A,~N,~N");
268 Clazz.overrideMethod (c$, "processingInstruction", 
269 function (target, data) {
270 if (this.contentHandler != null) {
271 this.contentHandler.processingInstruction (target, data);
272 }}, "~S,~S");
273 Clazz.defineMethod (c$, "setupParser", 
274  function () {
275 if (!this.prefixes && !this.namespaces) throw  new IllegalStateException ();
276 this.nsSupport.reset ();
277 if (this.uris) this.nsSupport.setNamespaceDeclUris (true);
278 if (this.entityResolver != null) {
279 this.parser.setEntityResolver (this.entityResolver);
280 }if (this.dtdHandler != null) {
281 this.parser.setDTDHandler (this.dtdHandler);
282 }if (this.errorHandler != null) {
283 this.parser.setErrorHandler (this.errorHandler);
284 }this.parser.setDocumentHandler (this);
285 this.locator = null;
286 });
287 Clazz.defineMethod (c$, "processName", 
288  function (qName, isAttribute, useException) {
289 var parts = this.nsSupport.processName (qName, this.nameParts, isAttribute);
290 if (parts == null) {
291 if (useException) throw this.makeException ("Undeclared prefix: " + qName);
292 this.reportError ("Undeclared prefix: " + qName);
293 parts =  new Array (3);
294 parts[0] = parts[1] = "";
295 parts[2] = qName.intern ();
296 }return parts;
297 }, "~S,~B,~B");
298 Clazz.defineMethod (c$, "reportError", 
299 function (message) {
300 if (this.errorHandler != null) this.errorHandler.error (this.makeException (message));
301 }, "~S");
302 Clazz.defineMethod (c$, "makeException", 
303  function (message) {
304 if (this.locator != null) {
305 return  new org.xml.sax.SAXParseException (message, this.locator);
306 } else {
307 return  new org.xml.sax.SAXParseException (message, null, null, -1, -1);
308 }}, "~S");
309 Clazz.defineMethod (c$, "checkNotParsing", 
310  function (type, name) {
311 if (this.parsing) {
312 throw  new org.xml.sax.SAXNotSupportedException ("Cannot change " + type + ' ' + name + " while parsing");
313 }}, "~S,~S");
314 c$.$ParserAdapter$AttributeListAdapter$ = function () {
315 Clazz.pu$h(self.c$);
316 c$ = Clazz.decorateAsClass (function () {
317 Clazz.prepareCallback (this, arguments);
318 this.qAtts = null;
319 Clazz.instantialize (this, arguments);
320 }, org.xml.sax.helpers.ParserAdapter, "AttributeListAdapter", null, org.xml.sax.Attributes);
321 Clazz.makeConstructor (c$, 
322 function () {
323 });
324 Clazz.defineMethod (c$, "setAttributeList", 
325 function (a) {
326 this.qAtts = a;
327 }, "org.xml.sax.AttributeList");
328 Clazz.overrideMethod (c$, "getLength", 
329 function () {
330 return this.qAtts.getLength ();
331 });
332 Clazz.overrideMethod (c$, "getURI", 
333 function (a) {
334 return "";
335 }, "~N");
336 Clazz.overrideMethod (c$, "getLocalName", 
337 function (a) {
338 return "";
339 }, "~N");
340 Clazz.overrideMethod (c$, "getQName", 
341 function (a) {
342 return this.qAtts.getName (a).intern ();
343 }, "~N");
344 Clazz.defineMethod (c$, "getType", 
345 function (a) {
346 return this.qAtts.getType (a).intern ();
347 }, "~N");
348 Clazz.defineMethod (c$, "getValue", 
349 function (a) {
350 return this.qAtts.getValue (a);
351 }, "~N");
352 Clazz.defineMethod (c$, "getIndex", 
353 function (a, b) {
354 return -1;
355 }, "~S,~S");
356 Clazz.defineMethod (c$, "getIndex", 
357 function (a) {
358 var b = this.b$["org.xml.sax.helpers.ParserAdapter"].atts.getLength ();
359 for (var c = 0; c < b; c++) {
360 if (this.qAtts.getName (c).equals (a)) {
361 return c;
362 }}
363 return -1;
364 }, "~S");
365 Clazz.defineMethod (c$, "getType", 
366 function (a, b) {
367 return null;
368 }, "~S,~S");
369 Clazz.defineMethod (c$, "getType", 
370 function (a) {
371 return this.qAtts.getType (a).intern ();
372 }, "~S");
373 Clazz.defineMethod (c$, "getValue", 
374 function (a, b) {
375 return null;
376 }, "~S,~S");
377 Clazz.defineMethod (c$, "getValue", 
378 function (a) {
379 return this.qAtts.getValue (a);
380 }, "~S");
381 c$ = Clazz.p0p ();
382 };
383 Clazz.defineStatics (c$,
384 "FEATURES", "http://xml.org/sax/features/");
385 c$.NAMESPACES = c$.prototype.NAMESPACES = "http://xml.org/sax/features/namespaces";
386 c$.NAMESPACE_PREFIXES = c$.prototype.NAMESPACE_PREFIXES = "http://xml.org/sax/features/namespace-prefixes";
387 c$.XMLNS_URIs = c$.prototype.XMLNS_URIs = "http://xml.org/sax/features/xmlns-uris";
388 });