From 4f3ad62d8bc5e2f2cc1f6674935bb9a088fa400a Mon Sep 17 00:00:00 2001 From: crawshaw Date: Wed, 24 Nov 2004 13:22:37 +0000 Subject: [PATCH] patch for rearrangement of ibex packages darcs-hash:20041124132237-2eb37-d5a3bfab728bb11d5df5bff6ad4b93a5dfede4d2.gz --- src/java/org/ibex/xt/JSElement.java | 23 +++++++++++----------- src/java/org/ibex/xt/Prevalence.java | 11 +++++------ src/java/org/ibex/xt/Servlet.java | 14 +++++++------ src/java/org/ibex/xt/Template.java | 36 +++++++++++++++++----------------- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/java/org/ibex/xt/JSElement.java b/src/java/org/ibex/xt/JSElement.java index 4de51f0..06a6f72 100644 --- a/src/java/org/ibex/xt/JSElement.java +++ b/src/java/org/ibex/xt/JSElement.java @@ -1,14 +1,14 @@ -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; @@ -22,13 +22,14 @@ public class JSElement extends JSScope implements XML.Element { // 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(); @@ -75,8 +76,8 @@ public class JSElement extends JSScope implements XML.Element { // 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(); } @@ -86,7 +87,7 @@ public class JSElement extends JSScope implements XML.Element { 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; } diff --git a/src/java/org/ibex/xt/Prevalence.java b/src/java/org/ibex/xt/Prevalence.java index e638cfa..d5b2229 100644 --- a/src/java/org/ibex/xt/Prevalence.java +++ b/src/java/org/ibex/xt/Prevalence.java @@ -1,13 +1,12 @@ -package ibex.xt; +package org.ibex.xt; import java.io.*; - import java.net.*; -import javax.servlet.ServletContext; // FIXME: remove references - import java.util.*; -import ibex.util.*; -import ibex.js.*; +import javax.servlet.ServletContext; // FIXME: remove references, use Template.Scope + +import org.ibex.util.*; +import org.ibex.js.*; import org.prevayler.*; import org.prevayler.implementation.snapshot.*; diff --git a/src/java/org/ibex/xt/Servlet.java b/src/java/org/ibex/xt/Servlet.java index ff63ab9..fcdbde2 100644 --- a/src/java/org/ibex/xt/Servlet.java +++ b/src/java/org/ibex/xt/Servlet.java @@ -1,14 +1,14 @@ -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.*; @@ -39,8 +39,10 @@ public class Servlet extends HttpServlet { 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 { 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); -- 1.7.10.4