fixed bug for global skins
This commit is contained in:
parent
c708ff0c29
commit
0a2cbec8f7
3 changed files with 40 additions and 7 deletions
|
@ -607,24 +607,30 @@ public class HopExtension {
|
|||
try {
|
||||
Skin skin = null;
|
||||
ESNode handlerNode = global ? null : (ESNode) thisObject;
|
||||
ESObject paramObject = null;
|
||||
if (arguments.length > 1 && arguments[1] instanceof ESObject)
|
||||
paramObject = (ESObject) arguments[1];
|
||||
|
||||
// first, see if the first argument already is a skin object. If not, it's the name of the skin to be called
|
||||
if (arguments[0] instanceof ESWrapper) {
|
||||
Object obj = ((ESWrapper) arguments[0]).toJavaObject ();
|
||||
if (obj instanceof Skin)
|
||||
skin = (Skin) obj;
|
||||
}
|
||||
|
||||
if (skin == null)
|
||||
skin = reval.getSkin (handlerNode, arguments[0].toString ());
|
||||
if (asString)
|
||||
reval.res.pushStringBuffer ();
|
||||
try {
|
||||
skin.render (reval, handlerNode);
|
||||
skin.render (reval, handlerNode, paramObject);
|
||||
} catch (NullPointerException npx) {
|
||||
reval.res.write ("[Skin not found: "+arguments[0]+"]");
|
||||
}
|
||||
if (asString)
|
||||
return new ESString (reval.res.popStringBuffer ());
|
||||
} catch (Exception x) {
|
||||
x.printStackTrace ();
|
||||
throw new EcmaScriptException ("renderSkin: "+x);
|
||||
}
|
||||
return ESNull.theNull;
|
||||
|
|
|
@ -655,14 +655,17 @@ public class RequestEvaluator implements Runnable {
|
|||
|
||||
public Skin getSkin (ESObject thisObject, String skinname) {
|
||||
INode n = null;
|
||||
if (thisObject != null && thisObject instanceof ESNode)
|
||||
Prototype proto = null;
|
||||
if (thisObject != null && thisObject instanceof ESNode) {
|
||||
n = ((ESNode) thisObject).getNode ();
|
||||
Prototype proto = app.getPrototype (n);
|
||||
proto = app.getPrototype (n);
|
||||
} else // the requested skin is global
|
||||
proto = app.typemgr.getPrototype ("global");
|
||||
Skin skin = null;
|
||||
if (proto != null)
|
||||
skin = proto.getSkin (skinname);
|
||||
// if we have a thisObject and didn't find the skin, try in hopobject
|
||||
if (skin == null) {
|
||||
if (skin == null && n != null) {
|
||||
proto = app.typemgr.getPrototype ("hopobject");
|
||||
if (proto != null)
|
||||
skin = proto.getSkin (skinname);
|
||||
|
|
|
@ -55,12 +55,12 @@ public class Skin {
|
|||
parts = partBuffer.toArray ();
|
||||
}
|
||||
|
||||
public void render (RequestEvaluator reval, ESNode thisNode) {
|
||||
public void render (RequestEvaluator reval, ESNode thisNode, ESObject paramObject) {
|
||||
if (parts == null)
|
||||
return;
|
||||
for (int i=0; i<parts.length; i++) {
|
||||
if (parts[i] instanceof Macro)
|
||||
((Macro) parts[i]).render (reval, thisNode);
|
||||
((Macro) parts[i]).render (reval, thisNode, paramObject);
|
||||
else
|
||||
reval.res.write (parts[i]);
|
||||
}
|
||||
|
@ -165,11 +165,17 @@ public class Skin {
|
|||
}
|
||||
|
||||
|
||||
public void render (RequestEvaluator reval, ESNode thisNode) {
|
||||
public void render (RequestEvaluator reval, ESNode thisNode, ESObject paramObject) {
|
||||
|
||||
if ("response".equalsIgnoreCase (handler)) {
|
||||
renderFromResponse (reval);
|
||||
return;
|
||||
} else if ("request".equalsIgnoreCase (handler)) {
|
||||
renderFromRequest (reval);
|
||||
return;
|
||||
} else if ("param".equalsIgnoreCase (handler)) {
|
||||
renderFromParam (reval, paramObject);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -246,6 +252,24 @@ public class Skin {
|
|||
reval.res.write (reval.res.message);
|
||||
}
|
||||
|
||||
private void renderFromRequest (RequestEvaluator reval) {
|
||||
Object value = reval.req.get (name);
|
||||
if (value != null)
|
||||
reval.res.write (value);
|
||||
}
|
||||
|
||||
private void renderFromParam (RequestEvaluator reval, ESObject paramObject) {
|
||||
if (paramObject == null)
|
||||
reval.res.write ("[HopMacro error: Skin requires a parameter object]");
|
||||
else {
|
||||
try {
|
||||
ESValue value = paramObject.getProperty (name, name.hashCode());
|
||||
if (value != null && value != ESUndefined.theUndefined)
|
||||
reval.res.write (value);
|
||||
} catch (EcmaScriptException ignore) {}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString () {
|
||||
return "[HopMacro: "+handler+","+name+"]";
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue