Added XHTML validation support.
[jsvc.git] / src / dolda / jsvc / next / Html.java
CommitLineData
816cbb00
FT
1package dolda.jsvc.next;
2
3import org.w3c.dom.*;
5203590b
FT
4import org.w3c.dom.ls.*;
5import javax.xml.validation.*;
6import java.net.*;
7import java.io.*;
816cbb00
FT
8
9public class Html extends DocBuffer {
10 public static final String ns = "http://www.w3.org/1999/xhtml";
5203590b
FT
11 private static final Schema schema = DomUtil.loadxsd("xhtml1-strict.xsd");
12
816cbb00
FT
13 private Html(String pubid, String sysid) {
14 super(ns, "html", "html", pubid, sysid);
15 }
16
17 public static Html xhtml11(String title) {
18 Html buf = new Html("-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd");
19 Node html = buf.doc.getDocumentElement();
20 Node head = DomUtil.insertel(html, "head");
21 head.appendChild(buf.makecursor("head"));
22 Node tit = DomUtil.insertel(head, "title");
23 DomUtil.inserttext(tit, title);
24 Node body = DomUtil.insertel(html, "body");
25 body.appendChild(buf.makecursor("body"));
26 return(buf);
27 }
28
29 public Element el(String name, Node contents, String... attrs) {
30 return(el(ns, name, contents, attrs));
31 }
32
33 public Element csslink(String href, String name) {
34 Element el = el("link", null, "rel=stylesheet", "type=text/css");
35 if(name != null)
36 el.setAttribute("title", name);
37 el.setAttribute("href", href);
38 return(el);
39 }
40
41 public void addcss(String href, String name) {
42 insert("head", csslink(href, name));
43 }
5203590b
FT
44
45 public void validate() {
46 Validator val = schema.newValidator();
47 try {
48 val.validate(new javax.xml.transform.dom.DOMSource(doc));
49 } catch(org.xml.sax.SAXException e) {
50 throw(new RuntimeException(e));
51 } catch(java.io.IOException e) {
52 /* Should never happen. */
53 throw(new Error(e));
54 }
55 }
816cbb00 56}