Added basic HTML generation and response handling.
[jrw.git] / src / jrw / sp / xhtml.java
diff --git a/src/jrw/sp/xhtml.java b/src/jrw/sp/xhtml.java
new file mode 100644 (file)
index 0000000..6d9120c
--- /dev/null
@@ -0,0 +1,106 @@
+package jrw.sp;
+
+import jrw.*;
+import java.util.*;
+import static jrw.sp.cons.populate;
+
+public class xhtml {
+    public static final Namespace ns = new Namespace("http://www.w3.org/1999/xhtml", "h");
+    public static final DocType doctype = new DocType("html", "-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd");
+
+    public static class cons {
+       private static final Name html = new Name(ns, "html");
+       public static Element html(Object... c) {return(populate(new Element(html), c));}
+       private static final Name head = new Name(ns, "head");
+       public static Element head(Object... c) {return(populate(new Element(head), c));}
+       private static final Name base = new Name(ns, "base");
+       public static Element base(Object... c) {return(populate(new Element(base), c));}
+       private static final Name title = new Name(ns, "title");
+       public static Element title(Object... c) {return(populate(new Element(title), c));}
+       private static final Name link = new Name(ns, "link");
+       public static Element link(Object... c) {return(populate(new Element(link), c));}
+       private static final Name meta = new Name(ns, "meta");
+       public static Element meta(Object... c) {return(populate(new Element(meta), c));}
+       private static final Name style = new Name(ns, "style");
+       public static Element style(Object... c) {return(populate(new Element(style), c));}
+       private static final Name script = new Name(ns, "script");
+       public static Element script(Object... c) {return(populate(new Element(script), c));}
+       private static final Name body = new Name(ns, "body");
+       public static Element body(Object... c) {return(populate(new Element(body), c));}
+       private static final Name div = new Name(ns, "div");
+       public static Element div(Object... c) {return(populate(new Element(div), c));}
+       private static final Name span = new Name(ns, "span");
+       public static Element span(Object... c) {return(populate(new Element(span), c));}
+       private static final Name p = new Name(ns, "p");
+       public static Element p(Object... c) {return(populate(new Element(p), c));}
+       private static final Name ul = new Name(ns, "ul");
+       public static Element ul(Object... c) {return(populate(new Element(ul), c));}
+       private static final Name ol = new Name(ns, "ol");
+       public static Element ol(Object... c) {return(populate(new Element(ol), c));}
+       private static final Name li = new Name(ns, "li");
+       public static Element li(Object... c) {return(populate(new Element(li), c));}
+       private static final Name dl = new Name(ns, "dl");
+       public static Element dl(Object... c) {return(populate(new Element(dl), c));}
+       private static final Name dt = new Name(ns, "dt");
+       public static Element dt(Object... c) {return(populate(new Element(dt), c));}
+       private static final Name dd = new Name(ns, "dd");
+       public static Element dd(Object... c) {return(populate(new Element(dd), c));}
+       private static final Name table = new Name(ns, "table");
+       public static Element table(Object... c) {return(populate(new Element(table), c));}
+       private static final Name th = new Name(ns, "th");
+       public static Element th(Object... c) {return(populate(new Element(th), c));}
+       private static final Name tr = new Name(ns, "tr");
+       public static Element tr(Object... c) {return(populate(new Element(tr), c));}
+       private static final Name td = new Name(ns, "td");
+       public static Element td(Object... c) {return(populate(new Element(td), c));}
+       private static final Name a = new Name(ns, "a");
+       public static Element a(Object... c) {return(populate(new Element(a), c));}
+       private static final Name img = new Name(ns, "img");
+       public static Element img(Object... c) {return(populate(new Element(img), c));}
+       private static final Name video = new Name(ns, "video");
+       public static Element video(Object... c) {return(populate(new Element(video), c));}
+       private static final Name audio = new Name(ns, "audio");
+       public static Element audio(Object... c) {return(populate(new Element(audio), c));}
+       private static final Name source = new Name(ns, "source");
+       public static Element source(Object... c) {return(populate(new Element(source), c));}
+       private static final Name track = new Name(ns, "track");
+       public static Element track(Object... c) {return(populate(new Element(track), c));}
+       private static final Name form = new Name(ns, "form");
+       public static Element form(Object... c) {return(populate(new Element(form), c));}
+       private static final Name input = new Name(ns, "input");
+       public static Element input(Object... c) {return(populate(new Element(input), c));}
+       private static final Name em = new Name(ns, "em");
+       public static Element em(Object... c) {return(populate(new Element(em), c));}
+       private static final Name strong = new Name(ns, "strong");
+       public static Element strong(Object... c) {return(populate(new Element(strong), c));}
+       private static final Name hr = new Name(ns, "hr");
+       public static Element hr(Object... c) {return(populate(new Element(hr), c));}
+       private static final Name br = new Name(ns, "br");
+       public static Element br(Object... c) {return(populate(new Element(br), c));}
+       private static final Name blockquote = new Name(ns, "blockquote");
+       public static Element blockquote(Object... c) {return(populate(new Element(blockquote), c));}
+       private static final Name code = new Name(ns, "code");
+       public static Element code(Object... c) {return(populate(new Element(code), c));}
+       private static final Name pre = new Name(ns, "pre");
+       public static Element pre(Object... c) {return(populate(new Element(pre), c));}
+       private static final Name h1 = new Name(ns, "h1");
+       public static Element h1(Object... c) {return(populate(new Element(h1), c));}
+       private static final Name h2 = new Name(ns, "h2");
+       public static Element h2(Object... c) {return(populate(new Element(h2), c));}
+       private static final Name h3 = new Name(ns, "h3");
+       public static Element h3(Object... c) {return(populate(new Element(h3), c));}
+       private static final Name h4 = new Name(ns, "h4");
+       public static Element h4(Object... c) {return(populate(new Element(h4), c));}
+       private static final Name h5 = new Name(ns, "h5");
+       public static Element h5(Object... c) {return(populate(new Element(h5), c));}
+       private static final Name h6 = new Name(ns, "h6");
+       public static Element h6(Object... c) {return(populate(new Element(h6), c));}
+    }
+
+    public static Map<Object, Object> response(Request req, Element root) {
+       // XXX: Use proper Content-Type for clients accepting it.
+       req.ohead("Content-Type", "text/html; charset=utf-8", true);
+       req.body(new HtmlFormatter(root));
+       return(req.response());
+    }
+}