From f452b10d473d1a3f6b9dc45a98fb6cc98d7f3944 Mon Sep 17 00:00:00 2001 From: crawshaw Date: Mon, 29 Nov 2004 09:40:28 +0000 Subject: [PATCH] move transaction scope management into Template.java darcs-hash:20041129094028-2eb37-1e5042a6f51463b1d9de4800163fbb4e726783f8.gz --- src/java/org/ibex/xt/Prevalence.java | 27 ++++++-------------------- src/java/org/ibex/xt/Template.java | 35 +++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/java/org/ibex/xt/Prevalence.java b/src/java/org/ibex/xt/Prevalence.java index 8468769..80d1f85 100644 --- a/src/java/org/ibex/xt/Prevalence.java +++ b/src/java/org/ibex/xt/Prevalence.java @@ -1,7 +1,6 @@ package org.ibex.xt; import java.io.*; -import java.net.*; import java.util.*; import javax.servlet.ServletContext; @@ -72,27 +71,13 @@ public class Prevalence { public static class JSTransaction implements Transaction { public static final long serialVersionUid = 0xfb2aa281; private JS js; - JSScope newscope; - List v; - public JSTransaction(JS js) throws JSExn { - newscope = new JSScope(null); - this.js = JS.cloneWithNewParentScope(js, newscope); - v = JS.getFormalArgs(this.js); - for(int i=0; i - List c = getChildren(); StringWriter sw = new StringWriter(); + List c = getChildren(); for (int i=0; i < c.size(); i++) ((Tree.Leaf)c.get(i)).out(sw); - JS t = JS.fromReader("input", 0, new StringReader(sw.toString())); - t = JS.cloneWithNewParentScope(t, new JSScope(null)); + StringReader sr = new StringReader(sw.toString()); + + JS t; + try { t = JS.fromReader("input", 0, sr); } + catch (IOException e) { throw new JSLeaf.Exn(e.getMessage()); } + + try { + JSScope scope = JS.getParentScope(t); + + Object u = scope().get("use"); if (u != null) scope().undeclare("use"); + if (u != null) { + if (!(u instanceof String)) throw new JSLeaf.Exn( + "<"+getPrefix()+":transaction> requires 'use' attribute "+ + "to be a valid space-seperated list of variables"); + StringTokenizer st = new StringTokenizer((String)u); + while (st.hasMoreTokens()) { + String k = st.nextToken(); + scope.put(k, scope().get(k)); + } + } + } catch (JSExn e) { throw new JSLeaf.Exn(e); } + scope.transaction(t); } } @@ -239,7 +261,6 @@ public class Template extends JSLeaf.Element { public static final class Text extends JSLeaf { public Text(Tree.Leaf w) { super(w); } public void out(Writer w) throws IOException { - // FIXME: make eval() take a writer StringWriter sw = new StringWriter(); super.out(sw); w.write((String)eval(sw.toString())); -- 1.7.10.4