1 16 package org.apache.cocoon.components.serializers; 17 18 import org.apache.cocoon.components.serializers.encoding.XHTMLEncoder; 19 import org.apache.cocoon.components.serializers.util.DocType; 20 import org.xml.sax.SAXException ; 21 22 23 29 public class XHTMLSerializer extends XMLSerializer { 30 31 32 public static final String XHTML1_NAMESPACE = 33 "http://www.w3.org/1999/xhtml"; 34 35 36 public static final DocType XHTML1_DOCTYPE_STRICT = new DocType( 37 "html", "-//W3C//DTD XHTML 1.0 Strict//EN", 38 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"); 39 40 41 public static final DocType XHTML1_DOCTYPE_TRANSITIONAL = new DocType( 42 "html", "-//W3C//DTD XHTML 1.0 Transitional//EN", 43 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"); 44 45 46 public static final DocType XHTML1_DOCTYPE_FRAMESET = new DocType( 47 "html", "-//W3C//DTD XHTML 1.0 Frameset//EN", 48 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"); 49 50 51 52 private static final XHTMLEncoder XHTML_ENCODER = new XHTMLEncoder(); 53 54 57 public XHTMLSerializer() { 58 super(XHTML_ENCODER); 59 } 60 61 64 protected XHTMLSerializer(XHTMLEncoder encoder) { 65 super(encoder); 66 } 67 68 71 public String getMimeType() { 72 if (this.charset == null) return("text/html"); 73 return("text/html; charset=" + this.charset.getName()); 74 } 75 76 77 78 85 public void body(String uri, String local, String qual) 86 throws SAXException { 87 if (this.doctype == null) this.doctype = XHTML1_DOCTYPE_TRANSITIONAL; 88 if (this.namespaces.getUri("").length() == 0) { 89 this.namespaces.push("", XHTML1_NAMESPACE); 90 } 91 super.body(uri, local, qual); 92 } 93 94 105 public void startElementImpl(String uri, String local, String qual, 106 String namespaces[][], String attributes[][]) 107 throws SAXException { 108 if (uri.length() == 0) uri = XHTML1_NAMESPACE; 109 super.startElementImpl(uri, local, qual, namespaces, attributes); 110 } 111 112 119 public void endElementImpl(String uri, String local, String qual) 120 throws SAXException { 121 if (uri.length() == 0) uri = XHTML1_NAMESPACE; 122 123 if (XHTML1_NAMESPACE.equals(uri)) { 124 if ((local.equalsIgnoreCase("textarea")) || 125 (local.equalsIgnoreCase("script")) || 126 (local.equalsIgnoreCase("style"))) { 127 this.closeElement(false); 128 } else if (local.equalsIgnoreCase("head")) { 129 String loc = "meta"; 130 String qua = namespaces.qualify(XHTML1_NAMESPACE, loc, "meta"); 131 String nsp[][] = new String [0][0]; 132 String att[][] = new String [2][ATTRIBUTE_LENGTH]; 133 134 att[0][ATTRIBUTE_NSURI] = att[1][ATTRIBUTE_NSURI] = ""; 135 att[0][ATTRIBUTE_LOCAL] = att[0][ATTRIBUTE_QNAME] = "http-equiv"; 136 att[1][ATTRIBUTE_LOCAL] = att[1][ATTRIBUTE_QNAME] = "content"; 137 att[0][ATTRIBUTE_VALUE] = "Content-Type"; 138 att[1][ATTRIBUTE_VALUE] = this.getMimeType(); 139 140 this.closeElement(false); 141 this.startElementImpl(XHTML1_NAMESPACE, loc, qua, nsp, att); 142 this.endElementImpl(XHTML1_NAMESPACE, loc, qua); 143 } 144 } 145 super.endElementImpl(uri, local, qual); 146 } 147 } 148 | Popular Tags |