Improved the DocBuffer and DOM writers to where they are kind of usable.
[jsvc.git] / src / dolda / jsvc / next / HtmlWriter.java
1 package dolda.jsvc.next;
2
3 import java.io.*;
4 import org.w3c.dom.*;
5
6 public class HtmlWriter extends XHtmlWriter {
7     public HtmlWriter(Document doc) {
8         super(doc);
9     }
10     
11     protected boolean asempty(ColumnWriter out, Element el) {
12         if(!super.asempty(out, el))
13             return(false);
14         String n = el.getTagName();
15         if(n.equals("br") || n.equals("hr") || n.equals("img") ||
16            n.equals("input"))
17             return(true);
18         return(false);
19     }
20     
21     protected void attribute(ColumnWriter out, Attr attr, int indent) throws IOException {
22         if(attr.getNamespaceURI() != null)
23             throw(new RuntimeException("HTML does not support non-null-NS attributes (" + attr.getNamespaceURI() + " encountered)"));
24         super.attribute(out, attr, indent);
25     }
26
27     protected void element(ColumnWriter out, Element el, int indent) throws IOException {
28         if(!el.getNamespaceURI().equals(Html.ns))
29             throw(new RuntimeException("HTML does not support non-HTML elements (namespace " + el.getNamespaceURI() + " encountered)"));
30         super.element(out, el, indent);
31     }
32
33     public void write(Writer out) throws IOException {
34         DocumentType dt = doc.getDoctype();
35         if(dt == null)
36             throw(new RuntimeException("Writing HTML requires an HTML document"));
37         if(!dt.getName().equals("html"))
38             throw(new RuntimeException("Writing HTML requires an HTML document, not `" + dt.getName() + "'"));
39         String pubid = dt.getPublicId();
40         if(pubid.equals("-//W3C//DTD XHTML 1.1//EN")) {
41         } else {
42             throw(new RuntimeException("Unimplemented HTML doctype `" + pubid));
43         }
44         super.write(out);
45     }
46 }