- Vector obStack = new Vector();
- public XMLHelper() { super(BUFFER_SIZE); }
- public void startElement(XML.Element c) throws XML.SchemaException {
- try {
- JS o = new JS();
- o.put("$name", c.localName);
- for(int i=0; i<c.len; i++) o.put(c.keys[i], c.vals[i]);
- o.put("$numchildren", new Integer(0));
- obStack.addElement(o);
- } catch (JSExn jse) {
- throw new Error("this should never happen");
+ private class Wrapper extends XML.Exn { public JSExn wrapee; public Wrapper(JSExn jse) { super(""); wrapee = jse; } }
+ private JS characters, whitespace, endElement, startElement;
+ public XMLHelper(JS b) throws JSExn {
+ super(BUFFER_SIZE);
+ startElement = (JS)b.getAndTriggerTraps("startElement");
+ endElement = (JS)b.getAndTriggerTraps("endElement");
+ characters = (JS)b.getAndTriggerTraps("characters");
+ whitespace = (JS)b.getAndTriggerTraps("whitespace");
+ }
+
+ public void startElement(XML.Element c) throws XML.Exn { try {
+ JS attrs = new JS();
+ // FIXME attribute URIs? add an additional hash?
+ for(int i=0; i<c.getAttrLen(); i++) attrs.put(c.getAttrKey(i), c.getAttrVal(i));
+ startElement.call(c.getLocalName(), attrs, c.getUri(), null, 3);
+ } catch (JSExn jse) { throw new Wrapper(jse); } }
+
+ public void endElement(XML.Element c) throws XML.Exn { try {
+ endElement.call(c.getLocalName(), c.getUri(), null, null, 2);
+ } catch (JSExn jse) { throw new Wrapper(jse); } }
+
+ public void characters(char[] ch, int start, int length) throws XML.Exn { try {
+ characters.call(new String(ch, start, length), null, null, null, 1);
+ } catch (JSExn jse) { throw new Wrapper(jse); } }
+
+ public void whitespace(char[] ch, int start, int length) throws XML.Exn { try {
+ whitespace.call(new String(ch, start, length), null, null, null, 1);
+ } catch (JSExn jse) { throw new Wrapper(jse); } }
+
+ public void doParse(JS s) throws JSExn {
+ try {
+ parse(new BufferedReader(new InputStreamReader(Stream.getInputStream(s))));
+ } catch (Wrapper e) {
+ throw e.wrapee;
+ } catch (XML.Exn e) {
+ throw new JSExn("error parsing XML: " + e.toString());
+ } catch (IOException e) {
+ if (Log.on) Log.info(this, "IO Exception while reading from file");
+ if (Log.on) Log.info(this, e);
+ throw new JSExn("error reading from Resource");