X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fibex%2Fxt%2FTemplate.java;h=c9b8611628bd817896347fc1834a3d54d75131b3;hb=0ce341ef6d77e3b1cd3034d65f6451871be31a4e;hp=cc2febb3e8210416db9e6456d51e6d0a2dfa9821;hpb=1a9695b5601cd90a65c743c859931d7146bdeed3;p=org.ibex.xt-crawshaw.git diff --git a/src/java/org/ibex/xt/Template.java b/src/java/org/ibex/xt/Template.java index cc2febb..c9b8611 100644 --- a/src/java/org/ibex/xt/Template.java +++ b/src/java/org/ibex/xt/Template.java @@ -26,7 +26,6 @@ public class Template extends JSElement { if (uri.equals("http://xt.ibex.org/")) { //#switch(e.getLocalName()) - case "if": e = new Template.If(e); break; case "js": e = new Template.JSTag(e); break; case "foreach": e = new Template.ForEach(e); break; case "children": e = new Template.Children(e); break; @@ -56,9 +55,14 @@ public class Template extends JSElement { // merge original attributes with replacement template e = new JSElement.Merge(t, e); + } - } else if (uri.startsWith("java:")) { - e = new Java(e); + XML.Attributes a = e.getAttributes(); + for (int i=0; i < a.attrSize(); i++) { + if ("if".equals(a.getKey(i)) && + "http://xt.ibex.org/".equals(a.getUri(i))) { + e = new Template.IfWrap(e); + } } // wrap children @@ -87,20 +91,18 @@ public class Template extends JSElement { public JSScope getParentScope() { return tscope; } - - public static final class If extends JSElement { - public If(XML.Element e) { super(e); } + public static final class IfWrap extends JSElement { + public IfWrap(XML.Element e) { super(e); } public void out(Writer w) throws IOException { - super.out(w); + loadAttr(); try { Object varIf = get("if"); if (varIf != null) undeclare("if"); if (varIf != null && !Boolean.getBoolean((String)varIf)) return; } catch (JSExn e) { throw new RuntimeException(e); } - List c = getChildren(); - for (int i=0; i < c.size(); i++) ((Tree.Leaf)c.get(i)).out(w); + wrapped.out(w); } } @@ -114,17 +116,12 @@ public class Template extends JSElement { } public void out(Writer w) throws IOException { - super.out(w); + loadAttr(); - try { - Object varIf = get("if"); if (varIf != null) undeclare("if"); - if (varIf != null && !Boolean.getBoolean((String)varIf)) return; - - List c = getChildren(); - StringWriter s = new StringWriter(); - for (int i=0; i < c.size(); i++) ((Tree.Leaf)c.get(i)).out(s); - exec(s.toString()); - } catch (JSExn e) { throw new RuntimeException(e); } + List c = getChildren(); + StringWriter s = new StringWriter(); + for (int i=0; i < c.size(); i++) ((Tree.Leaf)c.get(i)).out(s); + exec(s.toString()); } } @@ -132,13 +129,11 @@ public class Template extends JSElement { public ForEach(XML.Element e) { super(e); } public void out(Writer w) throws IOException { - super.out(w); + loadAttr(); try { Object varIn = get("in"); if (varIn != null) undeclare("in"); Object varPut = get("put"); if (varPut != null) undeclare("put"); - Object varIf = get("if"); if (varIf != null) undeclare("if"); - if (varIf != null && !Boolean.getBoolean((String)varIf)) return; varIn = exec("return (" + varIn + ");"); if (varIn == null || (varIn instanceof JSArray)) throw new RuntimeException( @@ -175,7 +170,7 @@ public class Template extends JSElement { public Transaction(XML.Element e, Template.Scope s) { super(e); scope = s;} // TODO: check kids public void out(Writer w) throws IOException { - super.out(w); + loadAttr(); // TODO: List c = getChildren();