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