Implement basic encoding/decoding of incoming XML-RPC calls.
This commit is contained in:
parent
74a3137577
commit
5a519db3c6
2 changed files with 78 additions and 38 deletions
|
@ -378,43 +378,77 @@ public final class RhinoCore {
|
||||||
* representation.
|
* representation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* public static ESValue processXmlRpcArgument (Object what, Evaluator evaluator) throws Exception {
|
public Object processXmlRpcArgument (Object what, Context cx) throws Exception {
|
||||||
if (what == null)
|
if (what == null)
|
||||||
return ESNull.theNull;
|
return null;
|
||||||
if (what instanceof Vector) {
|
if (what instanceof Vector) {
|
||||||
Vector v = (Vector) what;
|
Vector v = (Vector) what;
|
||||||
ArrayPrototype retval = new ArrayPrototype (evaluator.getArrayPrototype (), evaluator);
|
return Context.toObject(v.toArray(), global);
|
||||||
int l = v.size ();
|
|
||||||
for (int i=0; i<l; i++)
|
|
||||||
retval.putProperty (i, processXmlRpcArgument (v.elementAt (i), evaluator));
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
if (what instanceof Hashtable) {
|
if (what instanceof Hashtable) {
|
||||||
Hashtable t = (Hashtable) what;
|
Hashtable t = (Hashtable) what;
|
||||||
ESObject retval = new ObjectPrototype (evaluator.getObjectPrototype (), evaluator);
|
return Context.toObject(new SystemMap(t), global);
|
||||||
for (Enumeration e=t.keys(); e.hasMoreElements(); ) {
|
|
||||||
String next = (String) e.nextElement ();
|
|
||||||
retval.putProperty (next, processXmlRpcArgument (t.get (next), evaluator), next.hashCode ());
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
if (what instanceof String)
|
if (what instanceof String)
|
||||||
return new ESString (what.toString ());
|
return what;
|
||||||
if (what instanceof Number)
|
if (what instanceof Number)
|
||||||
return new ESNumber (new Double (what.toString ()).doubleValue ());
|
return what;
|
||||||
if (what instanceof Boolean)
|
if (what instanceof Boolean)
|
||||||
return ESBoolean.makeBoolean (((Boolean) what).booleanValue ());
|
return what;
|
||||||
if (what instanceof Date)
|
if (what instanceof Date) {
|
||||||
return new DatePrototype (evaluator, (Date) what);
|
Date d = (Date) what;
|
||||||
return ESLoader.normalizeValue (what, evaluator);
|
Object[] args = { new Long(d.getTime()) };
|
||||||
} */
|
return cx.newObject(global, "Date", args);
|
||||||
|
}
|
||||||
|
return Context.toObject(what, global);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* convert a JavaScript Object object to a generic Java object stucture.
|
* convert a JavaScript Object object to a generic Java object stucture.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* public static Object processXmlRpcResponse (ESValue what) throws EcmaScriptException {
|
public Object processXmlRpcResponse (Object what) throws Exception {
|
||||||
if (what == null || what instanceof ESNull)
|
if (what instanceof NativeJavaObject) {
|
||||||
|
what = ((NativeJavaObject) what).unwrap();
|
||||||
|
}
|
||||||
|
if (what instanceof NativeObject) {
|
||||||
|
NativeObject no = (NativeObject) what;
|
||||||
|
Object[] ids = no.getIds();
|
||||||
|
Hashtable ht = new Hashtable(ids.length);
|
||||||
|
for (int i=0; i<ids.length; i++) {
|
||||||
|
if (ids[i] instanceof String) {
|
||||||
|
String key = (String) ids[i];
|
||||||
|
ht.put(key, processXmlRpcResponse(no.get(key, no)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
what = ht;
|
||||||
|
}
|
||||||
|
if (what instanceof NativeArray) {
|
||||||
|
NativeArray na = (NativeArray) what;
|
||||||
|
Number n = (Number) na.get("length", na);
|
||||||
|
int l = n.intValue();
|
||||||
|
Vector retval = new Vector(l);
|
||||||
|
for (int i=0; i<l; i++) {
|
||||||
|
retval.add(i, processXmlRpcResponse(na.get(i, na)));
|
||||||
|
}
|
||||||
|
what = retval;
|
||||||
|
}
|
||||||
|
if (what instanceof Number) {
|
||||||
|
Number n = (Number) what;
|
||||||
|
if (what instanceof Float || what instanceof Long) {
|
||||||
|
what = new Double(n.doubleValue());
|
||||||
|
} else if (!(what instanceof Double)) {
|
||||||
|
what = new Integer(n.intValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (what instanceof Scriptable) {
|
||||||
|
Scriptable s = (Scriptable) what;
|
||||||
|
if ("Date".equals(s.getClassName())) {
|
||||||
|
what = new Date((long) ScriptRuntime.toNumber(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return what;
|
||||||
|
/* if (what == null || what instanceof ESNull)
|
||||||
return null;
|
return null;
|
||||||
if (what instanceof ArrayPrototype) {
|
if (what instanceof ArrayPrototype) {
|
||||||
ArrayPrototype a = (ArrayPrototype) what;
|
ArrayPrototype a = (ArrayPrototype) what;
|
||||||
|
@ -458,8 +492,9 @@ public final class RhinoCore {
|
||||||
Object jval = what.toJavaObject ();
|
Object jval = what.toJavaObject ();
|
||||||
if (jval instanceof Byte || jval instanceof Short)
|
if (jval instanceof Byte || jval instanceof Short)
|
||||||
jval = new Integer (jval.toString ());
|
jval = new Integer (jval.toString ());
|
||||||
return jval;
|
return jval; */
|
||||||
} */
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the application we're running in
|
* Return the application we're running in
|
||||||
|
|
|
@ -286,8 +286,13 @@ public final class RhinoEngine implements ScriptingEngine {
|
||||||
esv[i] = new ESMapWrapper (this, (Map) args[i]);
|
esv[i] = new ESMapWrapper (this, (Map) args[i]);
|
||||||
else
|
else
|
||||||
esv[i] = ESLoader.normalizeValue (args[i], evaluator); */
|
esv[i] = ESLoader.normalizeValue (args[i], evaluator); */
|
||||||
|
// XML-RPC requires special argument conversion
|
||||||
|
if (xmlrpc) {
|
||||||
|
args[i] = core.processXmlRpcArgument (args[i], Context.getCurrentContext());
|
||||||
|
} else {
|
||||||
args[i] = context.toObject(args[i], global);
|
args[i] = context.toObject(args[i], global);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Object f = ScriptableObject.getProperty(eso, functionName);
|
Object f = ScriptableObject.getProperty(eso, functionName);
|
||||||
|
|
||||||
|
@ -297,9 +302,9 @@ public final class RhinoEngine implements ScriptingEngine {
|
||||||
|
|
||||||
Object retval = ((Function) f).call(context, global, eso, args);
|
Object retval = ((Function) f).call(context, global, eso, args);
|
||||||
|
|
||||||
// if (xmlrpc)
|
if (xmlrpc) {
|
||||||
// return processXmlRpcResponse (retval);
|
return core.processXmlRpcResponse (retval);
|
||||||
if ((retval == null) || (retval == Undefined.instance)) {
|
} else if ((retval == null) || (retval == Undefined.instance)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (retval instanceof NativeJavaObject) {
|
} else if (retval instanceof NativeJavaObject) {
|
||||||
return ((NativeJavaObject) retval).unwrap();
|
return ((NativeJavaObject) retval).unwrap();
|
||||||
|
|
Loading…
Add table
Reference in a new issue