-package ibex.xt;
+package org.ibex.xt;
import java.io.StringReader;
import java.io.Writer;
+import java.io.OutputStream;
import java.io.IOException;
-
import java.util.*;
-import ibex.util.*;
-import ibex.js.JS;
-import ibex.js.JSScope;
+import org.ibex.util.*;
+import org.ibex.js.JS;
+import org.ibex.js.JSScope;
public class JSElement extends JSScope implements XML.Element {
protected XML.Element wrapped;
// remap parent and children
if (wrapped.getParent() != null) {
List c = wrapped.getParent().getChildren();
- c.remove(wrapped); c.add(this);
+ c.set(c.indexOf(wrapped), this);
}
List c = wrapped.getChildren();
- for (int i=c.size(); i >= 0; i--) ((XML.Block)c.get(i)).setParent(this);
+ for (int i=0; i < c.size(); i++) ((Tree.Leaf)c.get(i)).setParent(this);
}
- public void toXML(Writer w) throws IOException {
+ public void out(OutputStream o) throws IOException { throw new UnsupportedOperationException(); }
+ public void out(Writer w) throws IOException {
// grab all related attributes
try {
XML.Attributes a = getAttributes();
// Pass Through ///////////////////////////////////////////////////////////
- public void setParent(XML.Element p) { wrapped.setParent(p); }
- public XML.Element getParent() { return wrapped.getParent(); }
+ public void setParent(Tree.Node p) { wrapped.setParent(p); }
+ public Tree.Node getParent() { return wrapped.getParent(); }
public XML.Attributes getAttributes() { return wrapped.getAttributes(); }
public XML.Prefixes getPrefixes() { return wrapped.getPrefixes(); }
public List getChildren() { return wrapped.getChildren(); }
public String getUri() { return wrapped.getUri(); }
/** Works up the Element object model until an instance of a JSScope is found. */
- private static JSScope findScope(XML.Element e) {
+ private static JSScope findScope(Tree.Node e) {
while (e != null && !(e instanceof JSScope)) e = e.getParent();
return (JSScope)e;
}
-package ibex.xt;
+package org.ibex.xt;
import java.io.*;
import java.net.*;
+import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
-import java.util.*;
-import ibex.util.*;
-import ibex.util.Collections;
-import ibex.js.*;
+import org.ibex.util.*;
+import org.ibex.util.Collections;
+import org.ibex.js.*;
import org.prevayler.*;
import org.prevayler.implementation.snapshot.*;
public void doGet(HttpServletRequest rq, HttpServletResponse rs) throws IOException {
String path = cx.getRealPath(rq.getServletPath());
Servlet.Scope scope = new Servlet.Scope(cx, rq, rs, prevayler);
- try { Template.wrap(Template.parse(path, scope), scope).toXML(rs.getWriter()); }
+ rs.getWriter().write("beginning output...");
+ try { Template.wrap(Template.parse(path, scope), scope).out(rs.getWriter()); }
catch (Exception e) { e.printStackTrace(); System.out.println("e = "+e); }
+ rs.getWriter().write("...output ends.");
}
public static class Scope extends Template.Scope {
-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);