X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fibex%2Fxt%2FTemplate.java;h=cc2febb3e8210416db9e6456d51e6d0a2dfa9821;hb=4f3ad62d8bc5e2f2cc1f6674935bb9a088fa400a;hp=cbe272d6b9ed45e838a9e00a314ac1e57c9ba2db;hpb=50cd2b0cdda6355214e16e8e9f8dd65a31fe6934;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 cbe272d..cc2febb 100644 --- a/src/java/org/ibex/xt/Template.java +++ b/src/java/org/ibex/xt/Template.java @@ -1,4 +1,4 @@ -package ibex.xt; +package org.ibex.xt; import java.io.BufferedReader; import java.io.FileInputStream; @@ -10,18 +10,18 @@ import java.io.Writer; import java.io.IOException; import java.util.*; -import ibex.util.*; -import ibex.js.*; +import org.ibex.util.*; +import org.ibex.js.*; public class Template extends JSElement { - public static Template parse(String path, Template.Scope s) throws IOException, XML.Exn { + public static Template parse(String path, Template.Scope s) throws IOException { Reader xmlreader = new BufferedReader(new InputStreamReader(new FileInputStream(path))); XML.Document doc = new XML.Document(); doc.parse(xmlreader); return new Template(doc.getRoot(), s); } - public static XML.Element wrap(XML.Element e, Template.Scope s) throws IOException, XML.Exn { + public static XML.Element wrap(XML.Element e, Template.Scope s) throws IOException { final String uri = e.getUri(); if (uri.equals("http://xt.ibex.org/")) { @@ -37,7 +37,7 @@ public class Template extends JSElement { //#switch(uri.substring(19)) case "io": System.out.println("ibex.xt.io not yet implemented"); // TODO //#end - throw new RuntimeException("Unknown XT library: "+uri); + //throw new RuntimeException("Unknown XT library: "+uri); } else if (uri.startsWith("local:")) { Template t = parse(s.getLocalPath() + uri.substring(6), s); @@ -91,8 +91,8 @@ public class Template extends JSElement { public static final class If extends JSElement { public If(XML.Element e) { super(e); } - public void toXML(Writer w) throws IOException { - super.toXML(w); + public void out(Writer w) throws IOException { + super.out(w); try { Object varIf = get("if"); if (varIf != null) undeclare("if"); @@ -100,7 +100,7 @@ public class Template extends JSElement { } catch (JSExn e) { throw new RuntimeException(e); } List c = getChildren(); - for (int i=0; i < c.size(); i++) ((XML.Block)c.get(i)).toXML(w); + for (int i=0; i < c.size(); i++) ((Tree.Leaf)c.get(i)).out(w); } } @@ -113,8 +113,8 @@ public class Template extends JSElement { "<"+getPrefix()+":js> tags may not have child elements"); } - public void toXML(Writer w) throws IOException { - super.toXML(w); + public void out(Writer w) throws IOException { + super.out(w); try { Object varIf = get("if"); if (varIf != null) undeclare("if"); @@ -122,7 +122,7 @@ public class Template extends JSElement { List c = getChildren(); StringWriter s = new StringWriter(); - for (int i=0; i < c.size(); i++) ((XML.Block)c.get(i)).toXML(s); + 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); } } @@ -131,8 +131,8 @@ public class Template extends JSElement { public static final class ForEach extends JSElement { public ForEach(XML.Element e) { super(e); } - public void toXML(Writer w) throws IOException { - super.toXML(w); + public void out(Writer w) throws IOException { + super.out(w); try { Object varIn = get("in"); if (varIn != null) undeclare("in"); @@ -159,7 +159,7 @@ public class Template extends JSElement { declare((String)varPut); Iterator it = ((JSArray)varIn).toList().iterator(); while (it.hasNext()) { put(varPut, it.next()); - for (int i=0; i < c.size(); i++) ((XML.Block)c.get(i)).toXML(w); + for (int i=0; i < c.size(); i++) ((Tree.Leaf)c.get(i)).out(w); } } catch (JSExn e) { throw new RuntimeException(e); } } @@ -174,13 +174,13 @@ public class Template extends JSElement { private final Template.Scope scope; // FIXME: HACK. unstatisise all tags, or do this to all public Transaction(XML.Element e, Template.Scope s) { super(e); scope = s;} // TODO: check kids - public void toXML(Writer w) throws IOException { - super.toXML(w); + public void out(Writer w) throws IOException { + super.out(w); // TODO: List c = getChildren(); StringWriter sw = new StringWriter(); - for (int i=0; i < c.size(); i++) ((XML.Block)c.get(i)).toXML(sw); + 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)); scope.transaction(t);