Refactored and simplified renderSkin* methods.
This commit is contained in:
parent
5618ac1b4e
commit
9a05228c4c
4 changed files with 84 additions and 175 deletions
|
@ -84,44 +84,22 @@ public class GlobalObject extends ScriptableObject {
|
||||||
*
|
*
|
||||||
* @return ...
|
* @return ...
|
||||||
*/
|
*/
|
||||||
public boolean renderSkin(Object skin, Object param) {
|
public boolean renderSkin(Object skinobj, Object paramobj) {
|
||||||
// System.err.println ("RENDERSKIN CALLED WITH PARAM "+param);
|
|
||||||
Context cx = Context.getCurrentContext();
|
Context cx = Context.getCurrentContext();
|
||||||
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
||||||
Skin s;
|
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine");
|
||||||
|
Skin skin;
|
||||||
|
|
||||||
if (skin instanceof Skin) {
|
if (skinobj instanceof Skin) {
|
||||||
s = (Skin) skin;
|
skin = (Skin) skinobj;
|
||||||
} else {
|
} else {
|
||||||
// retrieve res.skinpath, an array of objects that tell us where to look for skins
|
skin = engine.getSkin("global", skinobj.toString());
|
||||||
// (strings for directory names and INodes for internal, db-stored skinsets)
|
|
||||||
Object[] skinpath = reval.res.getSkinpath();
|
|
||||||
RhinoCore.unwrapSkinpath(skinpath);
|
|
||||||
s = core.app.getSkin(null, skin.toString(), skinpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map p = null;
|
Map param = RhinoCore.getSkinParam(paramobj);
|
||||||
|
|
||||||
if ((param != null) && (param != Undefined.instance)) {
|
if (skin != null) {
|
||||||
p = new HashMap();
|
skin.render(reval, null, param);
|
||||||
|
|
||||||
if (param instanceof Scriptable) {
|
|
||||||
Scriptable sp = (Scriptable) param;
|
|
||||||
Object[] ids = sp.getIds();
|
|
||||||
|
|
||||||
for (int i = 0; i < ids.length; i++) {
|
|
||||||
Object obj = sp.get(ids[i].toString(), sp);
|
|
||||||
if (obj instanceof NativeJavaObject) {
|
|
||||||
p.put(ids[i], ((NativeJavaObject) obj).unwrap());
|
|
||||||
} else {
|
|
||||||
p.put(ids[i], obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s != null) {
|
|
||||||
s.render(reval, null, p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -135,44 +113,23 @@ public class GlobalObject extends ScriptableObject {
|
||||||
*
|
*
|
||||||
* @return ...
|
* @return ...
|
||||||
*/
|
*/
|
||||||
public String renderSkinAsString(Object skin, Object param) {
|
public String renderSkinAsString(Object skinobj, Object paramobj) {
|
||||||
Context cx = Context.getCurrentContext();
|
Context cx = Context.getCurrentContext();
|
||||||
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
||||||
Skin s;
|
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine");
|
||||||
|
Skin skin;
|
||||||
|
|
||||||
if (skin instanceof Skin) {
|
if (skinobj instanceof Skin) {
|
||||||
s = (Skin) skin;
|
skin = (Skin) skinobj;
|
||||||
} else {
|
} else {
|
||||||
// retrieve res.skinpath, an array of objects that tell us where to look for skins
|
skin = engine.getSkin("global", skinobj.toString());
|
||||||
// (strings for directory names and INodes for internal, db-stored skinsets)
|
|
||||||
Object[] skinpath = reval.res.getSkinpath();
|
|
||||||
RhinoCore.unwrapSkinpath(skinpath);
|
|
||||||
s = core.app.getSkin(null, skin.toString(), skinpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map p = null;
|
Map param = RhinoCore.getSkinParam(paramobj);
|
||||||
|
|
||||||
if ((param != null) && (param != Undefined.instance)) {
|
if (skin != null) {
|
||||||
p = new HashMap();
|
|
||||||
|
|
||||||
if (param instanceof Scriptable) {
|
|
||||||
Scriptable sp = (Scriptable) param;
|
|
||||||
Object[] ids = sp.getIds();
|
|
||||||
|
|
||||||
for (int i = 0; i < ids.length; i++) {
|
|
||||||
Object obj = sp.get(ids[i].toString(), sp);
|
|
||||||
if (obj instanceof NativeJavaObject) {
|
|
||||||
p.put(ids[i], ((NativeJavaObject) obj).unwrap());
|
|
||||||
} else {
|
|
||||||
p.put(ids[i], obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s != null) {
|
|
||||||
reval.res.pushStringBuffer();
|
reval.res.pushStringBuffer();
|
||||||
s.render(reval, null, p);
|
skin.render(reval, null, param);
|
||||||
|
|
||||||
return reval.res.popStringBuffer();
|
return reval.res.popStringBuffer();
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,44 +172,22 @@ public class HopObject extends ScriptableObject {
|
||||||
*
|
*
|
||||||
* @return ...
|
* @return ...
|
||||||
*/
|
*/
|
||||||
public boolean jsFunction_renderSkin(Object skin, Object param) {
|
public boolean jsFunction_renderSkin(Object skinobj, Object paramobj) {
|
||||||
// System.err.println ("RENDERSKIN CALLED WITH PARAM "+param);
|
|
||||||
Context cx = Context.getCurrentContext();
|
Context cx = Context.getCurrentContext();
|
||||||
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
||||||
Skin s;
|
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine");
|
||||||
|
Skin skin;
|
||||||
|
|
||||||
if (skin instanceof Skin) {
|
if (skinobj instanceof Skin) {
|
||||||
s = (Skin) skin;
|
skin = (Skin) skinobj;
|
||||||
} else {
|
} else {
|
||||||
// retrieve res.skinpath, an array of objects that tell us where to look for skins
|
skin = engine.getSkin(className, skinobj.toString());
|
||||||
// (strings for directory names and INodes for internal, db-stored skinsets)
|
|
||||||
Object[] skinpath = reval.res.getSkinpath();
|
|
||||||
RhinoCore.unwrapSkinpath(skinpath);
|
|
||||||
s = core.app.getSkin(node, skin.toString(), skinpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map p = null;
|
Map param = RhinoCore.getSkinParam(paramobj);
|
||||||
|
|
||||||
if ((param != null) && (param != Undefined.instance)) {
|
if (skin != null) {
|
||||||
p = new HashMap();
|
skin.render(reval, node, param);
|
||||||
|
|
||||||
if (param instanceof Scriptable) {
|
|
||||||
Scriptable sp = (Scriptable) param;
|
|
||||||
Object[] ids = sp.getIds();
|
|
||||||
|
|
||||||
for (int i = 0; i < ids.length; i++) {
|
|
||||||
Object obj = sp.get(ids[i].toString(), sp);
|
|
||||||
if (obj instanceof NativeJavaObject) {
|
|
||||||
p.put(ids[i], ((NativeJavaObject) obj).unwrap());
|
|
||||||
} else {
|
|
||||||
p.put(ids[i], obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s != null) {
|
|
||||||
s.render(reval, node, p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -223,45 +201,23 @@ public class HopObject extends ScriptableObject {
|
||||||
*
|
*
|
||||||
* @return ...
|
* @return ...
|
||||||
*/
|
*/
|
||||||
public String jsFunction_renderSkinAsString(Object skin, Object param) {
|
public String jsFunction_renderSkinAsString(Object skinobj, Object paramobj) {
|
||||||
// System.err.println ("RENDERSKIN CALLED WITH PARAM "+param);
|
|
||||||
Context cx = Context.getCurrentContext();
|
Context cx = Context.getCurrentContext();
|
||||||
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
||||||
Skin s;
|
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine");
|
||||||
|
Skin skin;
|
||||||
|
|
||||||
if (skin instanceof Skin) {
|
if (skinobj instanceof Skin) {
|
||||||
s = (Skin) skin;
|
skin = (Skin) skinobj;
|
||||||
} else {
|
} else {
|
||||||
// retrieve res.skinpath, an array of objects that tell us where to look for skins
|
skin = engine.getSkin(className, skinobj.toString());
|
||||||
// (strings for directory names and INodes for internal, db-stored skinsets)
|
|
||||||
Object[] skinpath = reval.res.getSkinpath();
|
|
||||||
RhinoCore.unwrapSkinpath(skinpath);
|
|
||||||
s = core.app.getSkin(node, skin.toString(), skinpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map p = null;
|
Map param = RhinoCore.getSkinParam(paramobj);
|
||||||
|
|
||||||
if ((param != null) && (param != Undefined.instance)) {
|
if (skin != null) {
|
||||||
p = new HashMap();
|
|
||||||
|
|
||||||
if (param instanceof Scriptable) {
|
|
||||||
Scriptable sp = (Scriptable) param;
|
|
||||||
Object[] ids = sp.getIds();
|
|
||||||
|
|
||||||
for (int i = 0; i < ids.length; i++) {
|
|
||||||
Object obj = sp.get(ids[i].toString(), sp);
|
|
||||||
if (obj instanceof NativeJavaObject) {
|
|
||||||
p.put(ids[i], ((NativeJavaObject) obj).unwrap());
|
|
||||||
} else {
|
|
||||||
p.put(ids[i], obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s != null) {
|
|
||||||
reval.res.pushStringBuffer();
|
reval.res.pushStringBuffer();
|
||||||
s.render(reval, node, p);
|
skin.render(reval, node, param);
|
||||||
|
|
||||||
return reval.res.popStringBuffer();
|
return reval.res.popStringBuffer();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ public class JavaObject extends NativeJavaObject {
|
||||||
|
|
||||||
RhinoCore core;
|
RhinoCore core;
|
||||||
Scriptable prototype;
|
Scriptable prototype;
|
||||||
|
String protoName;
|
||||||
|
|
||||||
static HashMap overload;
|
static HashMap overload;
|
||||||
|
|
||||||
|
@ -53,9 +54,11 @@ public class JavaObject extends NativeJavaObject {
|
||||||
/**
|
/**
|
||||||
* Creates a new JavaObject wrapper.
|
* Creates a new JavaObject wrapper.
|
||||||
*/
|
*/
|
||||||
public JavaObject(Scriptable scope, Object obj, Scriptable prototype, RhinoCore core) {
|
public JavaObject(Scriptable scope, Object obj,
|
||||||
|
String protoName, Scriptable prototype, RhinoCore core) {
|
||||||
this.parent = scope;
|
this.parent = scope;
|
||||||
this.javaObject = obj;
|
this.javaObject = obj;
|
||||||
|
this.protoName = protoName;
|
||||||
this.prototype = prototype;
|
this.prototype = prototype;
|
||||||
this.core = core;
|
this.core = core;
|
||||||
staticType = obj.getClass();
|
staticType = obj.getClass();
|
||||||
|
@ -71,38 +74,22 @@ public class JavaObject extends NativeJavaObject {
|
||||||
*
|
*
|
||||||
* @return ...
|
* @return ...
|
||||||
*/
|
*/
|
||||||
public boolean renderSkin(Object skin, Object param) {
|
public boolean renderSkin(Object skinobj, Object paramobj) {
|
||||||
// System.err.println ("RENDERSKIN CALLED WITH PARAM "+param);
|
|
||||||
Context cx = Context.getCurrentContext();
|
Context cx = Context.getCurrentContext();
|
||||||
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
||||||
Skin s;
|
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine");
|
||||||
|
Skin skin;
|
||||||
|
|
||||||
if (skin instanceof Skin) {
|
if (skinobj instanceof Skin) {
|
||||||
s = (Skin) skin;
|
skin = (Skin) skinobj;
|
||||||
} else {
|
} else {
|
||||||
// retrieve res.skinpath, an array of objects that tell us where to look for skins
|
skin = engine.getSkin(protoName, skinobj.toString());
|
||||||
// (strings for directory names and INodes for internal, db-stored skinsets)
|
|
||||||
Object[] skinpath = reval.res.getSkinpath();
|
|
||||||
RhinoCore.unwrapSkinpath(skinpath);
|
|
||||||
s = core.app.getSkin(javaObject, skin.toString(), skinpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map p = null;
|
Map param = RhinoCore.getSkinParam(paramobj);
|
||||||
|
|
||||||
if ((param != null) && (param != Undefined.instance)) {
|
if (skin != null) {
|
||||||
p = new HashMap();
|
skin.render(reval, javaObject, param);
|
||||||
|
|
||||||
if (param instanceof Scriptable) {
|
|
||||||
Scriptable sp = (Scriptable) param;
|
|
||||||
Object[] ids = sp.getIds();
|
|
||||||
|
|
||||||
for (int i = 0; i < ids.length; i++)
|
|
||||||
p.put(ids[i], sp.get(ids[i].toString(), sp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s != null) {
|
|
||||||
s.render(reval, javaObject, p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -116,39 +103,23 @@ public class JavaObject extends NativeJavaObject {
|
||||||
*
|
*
|
||||||
* @return ...
|
* @return ...
|
||||||
*/
|
*/
|
||||||
public String renderSkinAsString(Object skin, Object param) {
|
public String renderSkinAsString(Object skinobj, Object paramobj) {
|
||||||
// System.err.println ("RENDERSKINASSTRING CALLED WITH skin "+skin);
|
|
||||||
Context cx = Context.getCurrentContext();
|
Context cx = Context.getCurrentContext();
|
||||||
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
RequestEvaluator reval = (RequestEvaluator) cx.getThreadLocal("reval");
|
||||||
Skin s;
|
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine");
|
||||||
|
Skin skin;
|
||||||
|
|
||||||
if (skin instanceof Skin) {
|
if (skinobj instanceof Skin) {
|
||||||
s = (Skin) skin;
|
skin = (Skin) skinobj;
|
||||||
} else {
|
} else {
|
||||||
// retrieve res.skinpath, an array of objects that tell us where to look for skins
|
skin = engine.getSkin(protoName, skinobj.toString());
|
||||||
// (strings for directory names and INodes for internal, db-stored skinsets)
|
|
||||||
Object[] skinpath = reval.res.getSkinpath();
|
|
||||||
RhinoCore.unwrapSkinpath(skinpath);
|
|
||||||
s = core.app.getSkin(javaObject, skin.toString(), skinpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map p = null;
|
Map param = RhinoCore.getSkinParam(paramobj);
|
||||||
|
|
||||||
if ((param != null) && (param != Undefined.instance)) {
|
if (skin != null) {
|
||||||
p = new HashMap();
|
|
||||||
|
|
||||||
if (param instanceof Scriptable) {
|
|
||||||
Scriptable sp = (Scriptable) param;
|
|
||||||
Object[] ids = sp.getIds();
|
|
||||||
|
|
||||||
for (int i = 0; i < ids.length; i++)
|
|
||||||
p.put(ids[i], sp.get(ids[i].toString(), sp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s != null) {
|
|
||||||
reval.res.pushStringBuffer();
|
reval.res.pushStringBuffer();
|
||||||
s.render(reval, javaObject, p);
|
skin.render(reval, javaObject, param);
|
||||||
|
|
||||||
return reval.res.popStringBuffer();
|
return reval.res.popStringBuffer();
|
||||||
}
|
}
|
||||||
|
|
|
@ -574,10 +574,11 @@ public final class RhinoCore {
|
||||||
Scriptable op = getPrototype(prototypeName);
|
Scriptable op = getPrototype(prototypeName);
|
||||||
|
|
||||||
if (op == null) {
|
if (op == null) {
|
||||||
|
prototypeName = "hopobject";
|
||||||
op = getPrototype("hopobject");
|
op = getPrototype("hopobject");
|
||||||
}
|
}
|
||||||
|
|
||||||
w = new JavaObject(global, e, op, this);
|
w = new JavaObject(global, e, prototypeName, op, this);
|
||||||
|
|
||||||
wrappercache.put(e, w);
|
wrappercache.put(e, w);
|
||||||
}
|
}
|
||||||
|
@ -687,6 +688,30 @@ public final class RhinoCore {
|
||||||
return skinpath;
|
return skinpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static Map getSkinParam(Object paramobj) {
|
||||||
|
Map param = null;
|
||||||
|
|
||||||
|
if ((paramobj != null) && (paramobj != Undefined.instance)) {
|
||||||
|
param = new HashMap();
|
||||||
|
|
||||||
|
if (paramobj instanceof Scriptable) {
|
||||||
|
Scriptable sp = (Scriptable) paramobj;
|
||||||
|
Object[] ids = sp.getIds();
|
||||||
|
|
||||||
|
for (int i = 0; i < ids.length; i++) {
|
||||||
|
Object obj = sp.get(ids[i].toString(), sp);
|
||||||
|
if (obj instanceof NativeJavaObject) {
|
||||||
|
param.put(ids[i], ((NativeJavaObject) obj).unwrap());
|
||||||
|
} else {
|
||||||
|
param.put(ids[i], obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized void updateEvaluator(Prototype prototype, Reader reader,
|
private synchronized void updateEvaluator(Prototype prototype, Reader reader,
|
||||||
String sourceName, int firstline) {
|
String sourceName, int firstline) {
|
||||||
// context = Context.enter(context);
|
// context = Context.enter(context);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue