From 6576b9fc0feea34a3702f7b69b45d9cb18c40094 Mon Sep 17 00:00:00 2001 From: hns Date: Thu, 23 May 2002 19:35:18 +0000 Subject: [PATCH] Templates work again (also with _as_string). --- .../scripting/fesi/FesiActionAdapter.java | 53 ++++++++----------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/src/helma/scripting/fesi/FesiActionAdapter.java b/src/helma/scripting/fesi/FesiActionAdapter.java index fb3d8287..ba94d51a 100644 --- a/src/helma/scripting/fesi/FesiActionAdapter.java +++ b/src/helma/scripting/fesi/FesiActionAdapter.java @@ -31,7 +31,7 @@ public class FesiActionAdapter { Application app; String sourceName; // this is the parsed function which can be easily applied to RequestEvaluator objects - TypeUpdater pfunc; + TypeUpdater pfunc, pfuncAsString; public FesiActionAdapter (ActionFile action) { prototype = action.getPrototype (); @@ -40,45 +40,34 @@ public class FesiActionAdapter { String functionName = action.getFunctionName (); sourceName = action.toString (); try { - pfunc = parseFunction (functionName, "arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10", content); + pfunc = parseFunction (functionName, + "arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10", + content); } catch (Throwable x) { String message = x.getMessage (); pfunc = new ErrorFeedback (functionName, message); } + // check if this is a template and we need to generate an "_as_string" variant + if (action instanceof Template) { + try { + pfuncAsString = parseFunction (functionName+"_as_string", + "arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10", + "res.pushStringBuffer(); "+content+"\r\nreturn res.popStringBuffer();\r\n"); + } catch (Throwable x) { + String message = x.getMessage (); + pfunc = new ErrorFeedback (functionName+"_as_string", message); + } + } else { + pfuncAsString = null; + } } - /* protected void update (FesiEvaluator fesi) throws Exception { - // app.logEvent ("Reading text template " + name); - - FesiScriptingEnvironment scriptEnv = (FesiScriptingEnvironment) app.getScriptingEnvironment (); - Iterator evals = scriptEnv.getEvaluators().iterator(); - while (evals.hasNext ()) { - try { - FesiEvaluator fesi = (FesiEvaluator) evals.next (); - updateEvaluator (fesi); - } catch (Exception ignore) {} - } - } */ - - /* protected void remove () { - Iterator evals = app.typemgr.getRegisteredRequestEvaluators (); - while (evals.hasNext ()) { - try { - RequestEvaluator reval = (RequestEvaluator) evals.next (); - ObjectPrototype op = reval.getPrototype (prototype.getName()); - functionName = name+"_action"; - ESValue esv = (ESValue) op.getProperty (functionName, functionName.hashCode()); - if (esv instanceof ConstructedFunctionObject || esv instanceof ThrowException) { - op.deleteProperty (functionName, functionName.hashCode()); - } - } catch (Exception ignore) {} - } - } */ - public synchronized void updateEvaluator (FesiEvaluator fesi) throws EcmaScriptException { - if (pfunc != null) - pfunc.updateEvaluator (fesi); + if (pfunc != null) + pfunc.updateEvaluator (fesi); + if (pfuncAsString != null) + pfuncAsString.updateEvaluator (fesi); } protected TypeUpdater parseFunction (String funcname, String params, String body) throws EcmaScriptException {