made native skin support work
This commit is contained in:
parent
ea128e6cc3
commit
a7ea831b1b
4 changed files with 142 additions and 17 deletions
|
@ -26,7 +26,6 @@ public class ESNode extends ObjectPrototype {
|
|||
|
||||
// The ID of the wrapped Node. Makes ESNodes comparable without accessing the wrapped node.
|
||||
String nodeID;
|
||||
String protoName;
|
||||
ESObject cacheWrapper;
|
||||
Throwable lastError = null;
|
||||
RequestEvaluator eval;
|
||||
|
@ -89,12 +88,15 @@ public class ESNode extends ObjectPrototype {
|
|||
|
||||
public void setPrototype (String protoName) {
|
||||
checkNode ();
|
||||
this.protoName = protoName;
|
||||
node.setPrototype (protoName);
|
||||
}
|
||||
|
||||
public String getPrototypeName () {
|
||||
return node.getPrototype ();
|
||||
}
|
||||
|
||||
public String getESClassName () {
|
||||
return protoName == null ? "HopObject" : protoName;
|
||||
return "HopObject";
|
||||
}
|
||||
|
||||
public String toString () {
|
||||
|
|
|
@ -97,6 +97,7 @@ public class HopExtension {
|
|||
go.putHiddenProperty("getXmlDocument", new GlobalGetXmlDocument ("getXmlDocument", evaluator, fp));
|
||||
go.putHiddenProperty("getHtmlDocument", new GlobalGetHtmlDocument ("getHtmlDocument", evaluator, fp));
|
||||
go.putHiddenProperty("jdomize", new GlobalJDOM ("jdomize", evaluator, fp));
|
||||
go.putHiddenProperty("getSkin", new GlobalGetSkin ("getSkin", evaluator, fp, reval));
|
||||
go.deleteProperty("exit", "exit".hashCode());
|
||||
|
||||
// and some methods for session management from JS...
|
||||
|
@ -546,7 +547,20 @@ public class HopExtension {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class GlobalGetSkin extends BuiltinFunctionObject {
|
||||
RequestEvaluator reval;
|
||||
GlobalGetSkin (String name, Evaluator evaluator, FunctionPrototype fp, RequestEvaluator reval) {
|
||||
super (fp, evaluator, name, 1);
|
||||
this.reval = reval;
|
||||
}
|
||||
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||
if (arguments.length != 1 || ESNull.theNull.equals (arguments[0]))
|
||||
throw new EcmaScriptException ("getSkin must be called with one String argument!");
|
||||
return new ESWrapper (new Skin (arguments[0].toString(), reval), evaluator);
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalGetUser extends BuiltinFunctionObject {
|
||||
RequestEvaluator reval;
|
||||
GlobalGetUser (String name, Evaluator evaluator, FunctionPrototype fp, RequestEvaluator reval) {
|
||||
|
|
|
@ -42,7 +42,7 @@ public class RequestEvaluator implements Runnable {
|
|||
ESValue esresult;
|
||||
Object result;
|
||||
Exception exception;
|
||||
private ArrayPrototype reqPath;
|
||||
protected ArrayPrototype reqPath;
|
||||
private ESRequestData reqData;
|
||||
|
||||
// vars for FESI EcmaScript support
|
||||
|
@ -178,8 +178,8 @@ public class RequestEvaluator implements Runnable {
|
|||
esu.setUser (user);
|
||||
global.putHiddenProperty ("root", getNodeWrapper (root));
|
||||
global.putHiddenProperty("user", esu);
|
||||
global.putHiddenProperty ("req", ESLoader.normalizeValue(req, evaluator));
|
||||
global.putHiddenProperty ("res", ESLoader.normalizeValue(res, evaluator));
|
||||
global.putHiddenProperty ("req", new ESWrapper (req, evaluator));
|
||||
global.putHiddenProperty ("res", new ESWrapper (res, evaluator));
|
||||
global.putHiddenProperty ("path", reqPath);
|
||||
global.putHiddenProperty ("app", appnode);
|
||||
// set and mount the request data object
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.*;
|
|||
import java.io.*;
|
||||
import helma.framework.*;
|
||||
import FESI.Data.*;
|
||||
import FESI.Exceptions.*;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -17,8 +18,10 @@ import FESI.Data.*;
|
|||
public class Skin {
|
||||
|
||||
Object[] parts;
|
||||
RequestEvaluator reval;
|
||||
|
||||
public Skin (String content) {
|
||||
public Skin (String content, RequestEvaluator reval) {
|
||||
this.reval = reval;
|
||||
parse (content);
|
||||
}
|
||||
|
||||
|
@ -61,27 +64,133 @@ public class Skin {
|
|||
return b.toString ();
|
||||
}
|
||||
|
||||
static final int HANDLER = 0;
|
||||
static final int MACRO = 1;
|
||||
static final int PARAMNAME = 2;
|
||||
static final int PARAMVALUE = 3;
|
||||
|
||||
class Macro {
|
||||
|
||||
String handler;
|
||||
String name;
|
||||
HashMap parameters;
|
||||
ESObject parameters;
|
||||
|
||||
public Macro (String str) {
|
||||
int dot = str.indexOf (".");
|
||||
if (dot < 0) {
|
||||
handler = null;
|
||||
name = str;
|
||||
} else {
|
||||
handler = str.substring (0, dot);
|
||||
name = str.substring (dot+1);
|
||||
|
||||
parameters = new ObjectPrototype (null, reval.evaluator);
|
||||
|
||||
int l = str.length ();
|
||||
char cnt[] = new char[l];
|
||||
str.getChars (0, l, cnt, 0);
|
||||
|
||||
int state = HANDLER;
|
||||
boolean escape = false;
|
||||
char quotechar = '\u0000';
|
||||
String lastParamName = null;
|
||||
StringBuffer b = new StringBuffer();
|
||||
|
||||
for (int i=0; i<l; i++) {
|
||||
switch (cnt[i]) {
|
||||
case '.':
|
||||
if (state == HANDLER) {
|
||||
handler = b.toString ().trim();
|
||||
b.setLength (0);
|
||||
state = MACRO;
|
||||
} else
|
||||
b.append (cnt[i]);
|
||||
break;
|
||||
case '\\':
|
||||
if (escape)
|
||||
b.append (cnt[i]);
|
||||
escape = !escape;
|
||||
break;;
|
||||
case '"':
|
||||
case '\'':
|
||||
if (!escape && state == PARAMVALUE) {
|
||||
if (quotechar == cnt[i]) {
|
||||
try {
|
||||
parameters.putHiddenProperty (lastParamName, new ESString (b.toString()));
|
||||
} catch (EcmaScriptException badluck) {}
|
||||
b.setLength (0);
|
||||
state = PARAMNAME;
|
||||
quotechar = '\u0000';
|
||||
} else if (quotechar == '\u0000') {
|
||||
quotechar = cnt[i];
|
||||
b.setLength (0);
|
||||
} else
|
||||
b.append (cnt[i]);
|
||||
} else
|
||||
b.append (cnt[i]);
|
||||
escape = false;
|
||||
break;
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\f':
|
||||
if (state == MACRO || (state == HANDLER && b.length() > 0)) {
|
||||
name = b.toString().trim();
|
||||
b.setLength (0);
|
||||
state = PARAMNAME;
|
||||
} else if (state == PARAMVALUE && quotechar == '\u0000') {
|
||||
try {
|
||||
parameters.putHiddenProperty (lastParamName, new ESString (b.toString()));
|
||||
} catch (EcmaScriptException badluck) {}
|
||||
b.setLength (0);
|
||||
state = PARAMNAME;
|
||||
} else if (state == PARAMVALUE)
|
||||
b.append (cnt[i]);
|
||||
else
|
||||
b.setLength (0);
|
||||
break;
|
||||
case '=':
|
||||
if (state == PARAMNAME) {
|
||||
lastParamName = b.toString().trim();
|
||||
b.setLength (0);
|
||||
state = PARAMVALUE;
|
||||
} else
|
||||
b.append (cnt[i]);
|
||||
break;
|
||||
default:
|
||||
b.append (cnt[i]);
|
||||
escape = false;
|
||||
}
|
||||
}
|
||||
if (lastParamName != null && b.length() > 0) try {
|
||||
parameters.putHiddenProperty (lastParamName, new ESString (b.toString()));
|
||||
} catch (EcmaScriptException noluck) {}
|
||||
}
|
||||
|
||||
|
||||
public String toString () {
|
||||
return "[HopMacro: "+handler+","+name+"]";
|
||||
|
||||
try {
|
||||
|
||||
ESValue[] arguments = new ESValue[2];
|
||||
arguments[0] = new ESString (name);
|
||||
arguments[1] = parameters;
|
||||
ESNode handlerNode = null;
|
||||
|
||||
if (handler != null) {
|
||||
int l = reval.reqPath.size();
|
||||
for (int i=l-1; i>=0; i--) {
|
||||
if (handler.equalsIgnoreCase (((ESNode) reval.reqPath.getProperty(i)).getPrototypeName())) {
|
||||
handlerNode = (ESNode) reval.reqPath.getProperty(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handlerNode = (ESNode) reval.reqPath.getProperty(0);
|
||||
}
|
||||
|
||||
if (handlerNode != null) {
|
||||
return handlerNode.doIndirectCall (reval.evaluator, handlerNode, "handleMacro", arguments).toString();
|
||||
} else {
|
||||
return "[HopMacro unhandled: "+handler+"."+name+"]";
|
||||
}
|
||||
} catch (Exception x) {
|
||||
return "[HopMacro error: "+x.getMessage()+"]";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue