WIP: Convenient document creation utilities.
[jsvc.git] / src / dolda / jsvc / next / Html.java
1 package dolda.jsvc.next;
2
3 import org.w3c.dom.*;
4
5 public class Html extends DocBuffer {
6     public static final String ns = "http://www.w3.org/1999/xhtml";
7     
8     private Html(String pubid, String sysid) {
9         super(ns, "html", "html", pubid, sysid);
10     }
11
12     public static Html xhtml11(String title) {
13         Html buf = new Html("-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd");
14         Node html = buf.doc.getDocumentElement();
15         Node head = DomUtil.insertel(html, "head");
16         head.appendChild(buf.makecursor("head"));
17         Node tit = DomUtil.insertel(head, "title");
18         DomUtil.inserttext(tit, title);
19         Node body = DomUtil.insertel(html, "body");
20         body.appendChild(buf.makecursor("body"));
21         return(buf);
22     }
23     
24     public Element el(String name, Node contents, String... attrs) {
25         return(el(ns, name, contents, attrs));
26     }
27     
28     public Element csslink(String href, String name) {
29         Element el = el("link", null, "rel=stylesheet", "type=text/css");
30         if(name != null)
31             el.setAttribute("title", name);
32         el.setAttribute("href", href);
33         return(el);
34     }
35     
36     public void addcss(String href, String name) {
37         insert("head", csslink(href, name));
38     }
39 }