From a7ea831b1b70ddb1b36c5608fcf33ffb43751549 Mon Sep 17 00:00:00 2001 From: hns Date: Mon, 8 Jan 2001 18:30:38 +0000 Subject: [PATCH] made native skin support work --- src/helma/framework/core/ESNode.java | 8 +- src/helma/framework/core/HopExtension.java | 16 ++- .../framework/core/RequestEvaluator.java | 6 +- src/helma/framework/core/Skin.java | 129 ++++++++++++++++-- 4 files changed, 142 insertions(+), 17 deletions(-) diff --git a/src/helma/framework/core/ESNode.java b/src/helma/framework/core/ESNode.java index f1d5bfbf..2db75f82 100644 --- a/src/helma/framework/core/ESNode.java +++ b/src/helma/framework/core/ESNode.java @@ -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 () { diff --git a/src/helma/framework/core/HopExtension.java b/src/helma/framework/core/HopExtension.java index 803b71e2..701962a8 100644 --- a/src/helma/framework/core/HopExtension.java +++ b/src/helma/framework/core/HopExtension.java @@ -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) { diff --git a/src/helma/framework/core/RequestEvaluator.java b/src/helma/framework/core/RequestEvaluator.java index 6ef097b7..8b63d6f1 100644 --- a/src/helma/framework/core/RequestEvaluator.java +++ b/src/helma/framework/core/RequestEvaluator.java @@ -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 diff --git a/src/helma/framework/core/Skin.java b/src/helma/framework/core/Skin.java index 29e95573..dfd7486b 100644 --- a/src/helma/framework/core/Skin.java +++ b/src/helma/framework/core/Skin.java @@ -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 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()+"]"; + } } }