import javax.servlet.*;
import javax.servlet.http.*;
-import org.ibex.util.*;
import org.ibex.util.Collections;
import org.ibex.js.*;
public void doGet(HttpServletRequest rq, HttpServletResponse rs) throws IOException {
String src = rq.getServletPath();
Servlet.Scope scope = new Servlet.Scope(cx, rq, rs, prevayler);
+ PrintWriter w = new PrintWriter(rs.getWriter());
try {
while (src != null) {
try {
- StringWriter w = new StringWriter();
+ StringWriter buffer = new StringWriter();
Template t = Template.parse(cx.getRealPath(src), scope);
- Template.wrap(t, scope).out(w);
- rs.getWriter().write(w.toString());
+ Template.wrap(t, scope).out(buffer);
+ w.write(buffer.toString());
src = null;
} catch (Template.RedirectSignal r) {
src = r.getTarget();
}
}
} catch (Template.Signal s) {
+ // exit silently
} catch (JSElement.Exn e) {
- PrintWriter w = new PrintWriter(rs.getWriter());
w.print("\n"+src+": ");
w.println(e.getMessage());
System.out.println(e);
+ } catch (FileNotFoundException e) {
+ w.print("\nfile not found: ");
+ w.println(e.getMessage());
+ System.out.println(e);
+ } catch (IOException e) {
+ w.print("\nio error: ");
+ w.println(e.getMessage());
+ e.printStackTrace();
} catch (Exception e) {
System.out.println("Unexpected Exception:");
e.printStackTrace();
import java.io.StringWriter;
import java.io.Writer;
import java.io.IOException;
+import java.io.FileNotFoundException;
import java.util.*;
import org.ibex.util.*;
import org.ibex.js.*;
public class Template extends JSElement {
- public static Template parse(String path, Template.Scope s) throws IOException {
+ public static Template parse(String path, Template.Scope s) throws FileNotFoundException, IOException {
Reader xmlreader = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
XML.Document doc = new XML.Document();
doc.parse(xmlreader);
case "js": e = new Template.JSTag(e); break;
case "foreach": e = new Template.ForEach(e); break;
case "children": e = new Template.Children(e); break;
+ case "redirect": e = new Template.Redirect(e); break;
case "transaction": e = new Template.Transaction(e, s); break;
//#end
public Children(XML.Element e) { super(e); }
}
+ public static final class Redirect extends JSElement {
+ public Redirect(XML.Element e) { super(e); }
+
+ public void out(Writer w) throws IOException {
+ loadAttr();
+
+ try {
+ Object p = get("page"); if (p != null) undeclare("page");
+ if (p == null || !(p instanceof String) || ((String)p).trim().equals(""))
+ throw new JSElement.Exn("<"+getPrefix()+":redirect> requires 'page' "+
+ "attribute to be a valid template path");
+ throw new RedirectSignal((String)p);
+ } catch (JSExn e) { throw new JSElement.Exn(e); }
+ }
+ }
+
// TODO: finish
public static final class Transaction extends JSElement {
private final Template.Scope scope; // FIXME: HACK. unstatisise all tags, or do this to all