WIP: Convenient document creation utilities.
[jsvc.git] / src / dolda / jsvc / next / Html.java
diff --git a/src/dolda/jsvc/next/Html.java b/src/dolda/jsvc/next/Html.java
new file mode 100644 (file)
index 0000000..6d6c24e
--- /dev/null
@@ -0,0 +1,39 @@
+package dolda.jsvc.next;
+
+import org.w3c.dom.*;
+
+public class Html extends DocBuffer {
+    public static final String ns = "http://www.w3.org/1999/xhtml";
+    
+    private Html(String pubid, String sysid) {
+       super(ns, "html", "html", pubid, sysid);
+    }
+
+    public static Html xhtml11(String title) {
+       Html buf = new Html("-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd");
+       Node html = buf.doc.getDocumentElement();
+       Node head = DomUtil.insertel(html, "head");
+       head.appendChild(buf.makecursor("head"));
+       Node tit = DomUtil.insertel(head, "title");
+       DomUtil.inserttext(tit, title);
+       Node body = DomUtil.insertel(html, "body");
+       body.appendChild(buf.makecursor("body"));
+       return(buf);
+    }
+    
+    public Element el(String name, Node contents, String... attrs) {
+       return(el(ns, name, contents, attrs));
+    }
+    
+    public Element csslink(String href, String name) {
+       Element el = el("link", null, "rel=stylesheet", "type=text/css");
+       if(name != null)
+           el.setAttribute("title", name);
+       el.setAttribute("href", href);
+       return(el);
+    }
+    
+    public void addcss(String href, String name) {
+       insert("head", csslink(href, name));
+    }
+}