- // Methods to Recieve and parse XML-RPC Response ////////////////////////////////////////////////////
-
- public void startElement(XML.Element c) {
- content.reset();
- if (c.localName.equals("fault")) fault = true;
- else if (c.localName.equals("struct")) objects.setElementAt(new JSObject(false), objects.size() - 1);
- else if (c.localName.equals("array")) objects.setElementAt(null, objects.size() - 1);
- else if (c.localName.equals("value")) objects.addElement("");
- }
-
- public void endElement(XML.Element c) {
-
- if (c.localName.equals("int") || c.localName.equals("i4"))
- objects.setElementAt(new Integer(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
-
- else if (c.localName.equals("boolean"))
- objects.setElementAt(content.getBuf()[0] == '1' ? Boolean.TRUE : Boolean.FALSE, objects.size() - 1);
-
- else if (c.localName.equals("string"))
- objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1);
-
- else if (c.localName.equals("double"))
- objects.setElementAt(new Double(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
-
- else if (c.localName.equals("base64"))
- objects.setElementAt(new ByteStream(Base64.decode(new String(content.getBuf(), 0, content.size()))), objects.size() - 1);
-
- else if (c.localName.equals("name"))
- objects.addElement(new String(content.getBuf(), 0, content.size()));
-
- else if (c.localName.equals("value") && "".equals(objects.lastElement()))
- objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1);
-
- else if (c.localName.equals("dateTime.iso8601")) {
- String s = new String(content.getBuf(), 0, content.size());
-
- // strip whitespace
- int i=0;
- while(Character.isWhitespace(s.charAt(i))) i++;
- if (i > 0) s = s.substring(i);
-
- try {
- NativeDate nd = (NativeDate)Context.enter().newObject(org.xwt.util.JSObject.defaultObjects, "Date");
- double date = NativeDate.date_msecFromDate(Double.valueOf(s.substring(0, 4)).doubleValue(),
- Double.valueOf(s.substring(4, 6)).doubleValue() - 1,
- Double.valueOf(s.substring(6, 8)).doubleValue(),
- Double.valueOf(s.substring(9, 11)).doubleValue(),
- Double.valueOf(s.substring(12, 14)).doubleValue(),
- Double.valueOf(s.substring(15, 17)).doubleValue(),
- (double)0
- );
- nd.jsFunction_setTime(NativeDate.internalUTC(date));
- objects.setElementAt(nd, objects.size() - 1);
-
- } catch (Exception e) {
- if (Log.on) Log.log(this, "error parsing date : " + s);
- if (Log.on) Log.log(this, e);
+ public void startElement(XML.Element c) {
+ content.reset();
+ //#switch(c.getLocalName())
+ case "fault": fault = true;
+ case "struct": objects.setElementAt(new JS(), objects.size() - 1);
+ case "array": objects.setElementAt(null, objects.size() - 1);
+ case "value": objects.addElement("");
+ //#end
+ }
+
+ public void endElement(XML.Element c) {
+ //#switch(c.getLocalName())
+ case "int": objects.setElementAt(new Integer(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
+ case "i4": objects.setElementAt(new Integer(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
+ case "boolean": objects.setElementAt(content.getBuf()[0] == '1' ? Boolean.TRUE : Boolean.FALSE, objects.size() - 1);
+ case "string": objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1);
+ case "double": objects.setElementAt(new Double(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
+ case "base64": objects.setElementAt(new Stream.ByteArray(Base64.decode(new String(content.getBuf(), 0, content.size())),
+ null), objects.size() - 1);
+ case "name": objects.addElement(new String(content.getBuf(), 0, content.size()));
+ case "value": if ("".equals(objects.lastElement()))
+ objects.setElementAt(new String(content.getBuf(), 0, content.size()), objects.size() - 1);
+ case "dateTime.iso8601":
+ String s = new String(content.getBuf(), 0, content.size());
+
+ // strip whitespace
+ int i=0;
+ while(Character.isWhitespace(s.charAt(i))) i++;
+ if (i > 0) s = s.substring(i);
+
+ try {
+ JSDate nd = new JSDate();
+ double date = JSDate.date_msecFromDate(Double.valueOf(s.substring(0, 4)).doubleValue(),
+ Double.valueOf(s.substring(4, 6)).doubleValue() - 1,
+ Double.valueOf(s.substring(6, 8)).doubleValue(),
+ Double.valueOf(s.substring(9, 11)).doubleValue(),
+ Double.valueOf(s.substring(12, 14)).doubleValue(),
+ Double.valueOf(s.substring(15, 17)).doubleValue(),
+ (double)0
+ );
+ nd.setTime(JSDate.internalUTC(date));
+ objects.setElementAt(nd, objects.size() - 1);
+
+ } catch (Exception e) {
+ if (Log.on) Log.info(this, "error parsing date : " + s);
+ if (Log.on) Log.info(this, e);
+ }
+ case "member":
+ Object memberValue = objects.elementAt(objects.size() - 1);
+ String memberName = (String)objects.elementAt(objects.size() - 2);
+ JS struct = (JS)objects.elementAt(objects.size() - 3);
+ try {
+ struct.put(memberName, memberValue);
+ } catch (JSExn e) {
+ throw new Error("this should never happen");
+ }
+ objects.setSize(objects.size() - 2);
+ case "data":
+ int i;
+ for(i=objects.size() - 1; objects.elementAt(i) != null; i--);
+ JSArray arr = new JSArray();
+ try {
+ for(int j = i + 1; j<objects.size(); j++) arr.put(new Integer(j - i - 1), objects.elementAt(j));
+ } catch (JSExn e) {
+ throw new Error("this should never happen");
+ }
+ objects.setElementAt(arr, i);
+ objects.setSize(i + 1);
+ //#end
+ content.reset();
+ }
+
+ public void characters(char[] ch, int start, int length) {
+ try { content.write(ch, start, length); }
+ catch (Exception e) {
+ if (Log.on) Log.info(this, "Exception in XMLRPC.content() -- this should never happen");
+ if (Log.on) Log.info(this, e);