+
+ public void validate() {
+ Validator val;
+ synchronized(schema) {
+ val = schema.newValidator();
+ }
+ try {
+ val.validate(new javax.xml.transform.dom.DOMSource(doc));
+ } catch(org.xml.sax.SAXException e) {
+ throw(new RuntimeException(e));
+ } catch(java.io.IOException e) {
+ /* Should never happen. */
+ throw(new Error(e));
+ }
+ }
+
+ private static boolean asxhtml(Request req) {
+ String ah = req.inheaders().get("Accept");
+ AcceptMap ctmap = AcceptMap.parse((ah == null)?"":ah);
+ AcceptMap.Entry ha = ctmap.accepts("text/html");
+ AcceptMap.Entry xa = ctmap.accepts("text/xhtml+xml");
+ if(xa == null)
+ xa = ctmap.accepts("application/xhtml+xml");
+ if((ha == null) && (xa == null))
+ return(false);
+ else if((ha != null) && (xa == null))
+ return(false);
+ else if((ha == null) && (xa != null))
+ return(true);
+ if(xa.q < ha.q)
+ return(false);
+ return(true);
+ }
+
+ public void output(Request req) throws IOException {
+ finalise();
+ validate();
+ XmlWriter w;
+ if(asxhtml(req)) {
+ req.outheaders().put("Content-Type", "application/xhtml+xml");
+ w = new XHtmlWriter(doc);
+ } else {
+ req.outheaders().put("Content-Type", "text/html; charset=utf-8");
+ w = new HtmlWriter(doc);
+ }
+ w.write(req.output());
+ }