-package ibex.xt;
+package org.ibex.xt;
import java.io.BufferedReader;
import java.io.FileInputStream;
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/")) {
//#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);
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");
} 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);
}
}
"<"+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");
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); }
}
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");
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); }
}
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: <xt:use />
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);