1 29 30 package com.caucho.jsp.java; 31 32 import com.caucho.jsp.JspParseException; 33 import com.caucho.util.L10N; 34 import com.caucho.vfs.WriteStream; 35 import com.caucho.xml.QName; 36 37 import java.io.IOException ; 38 39 public class JspOutput extends JspNode { 40 static final L10N L = new L10N(JspOutput.class); 41 42 static final private QName OMIT_XML_DECLARATION = 43 new QName("omit-xml-declaration"); 44 static final private QName DOCTYPE_SYSTEM = 45 new QName("doctype-system"); 46 static final private QName DOCTYPE_PUBLIC = 47 new QName("doctype-public"); 48 static final private QName DOCTYPE_ROOT_ELEMENT = 49 new QName("doctype-root-element"); 50 51 private boolean _omitXmlDeclaration; 52 53 private String _doctypeSystem; 54 private String _doctypePublic; 55 private String _doctypeRootElement; 56 57 63 public void addAttribute(QName name, String value) 64 throws JspParseException 65 { 66 if (! _gen.isXml()) 67 throw error(L.l("jsp:output is only allowed in jspx files.")); 68 69 if (OMIT_XML_DECLARATION.equals(name)) { 70 _gen.setOmitXmlDeclaration(attributeToBoolean(name.getName(), value)); 71 } 72 else if (DOCTYPE_SYSTEM.equals(name)) { 73 String oldValue = _gen.getDoctypeSystem(); 74 75 if (oldValue != null && ! oldValue.equals(value)) { 76 throw error(L.l("jsp:output doctype-system '{0}' conflicts with previous value '{1}'. The doctype-system attribute may only be specified once.", 77 value, oldValue)); 78 } 79 80 _gen.setDoctypeSystem(value); 81 _doctypeSystem = value; 82 } 83 else if (DOCTYPE_PUBLIC.equals(name)) { 84 String oldValue = _gen.getDoctypePublic(); 85 86 if (oldValue != null && ! oldValue.equals(value)) { 87 throw error(L.l("jsp:output doctype-public '{0}' conflicts with previous value '{1}'. The doctype-public attribute may only be specified once.", 88 value, oldValue)); 89 } 90 91 _gen.setDoctypePublic(value); 92 _doctypePublic = value; 93 } 94 else if (DOCTYPE_ROOT_ELEMENT.equals(name)) { 95 String oldValue = _gen.getDoctypeRootElement(); 96 97 if (oldValue != null && ! oldValue.equals(value)) { 98 throw error(L.l("jsp:output doctype-root-element '{0}' conflicts with previous value '{1}'. The doctype-root-element attribute may only be specified once.", 99 value, oldValue)); 100 } 101 102 _gen.setDoctypeRootElement(value); 103 _doctypeRootElement = value; 104 } 105 else { 106 throw error(L.l("'{0}' is an unknown jsp:output attribute. Value attributes are: doctype-public, doctype-system, doctype-root-element.", 107 name.getName())); 108 } 109 } 110 111 114 public void endElement() 115 throws JspParseException 116 { 117 if (_doctypeSystem != null && _doctypeRootElement == null) { 118 throw error(L.l("<jsp:output> with a 'doctype-system' attribute requires a 'doctype-root-element' attribute.")); 119 } 120 121 if (_doctypePublic != null && _doctypeSystem == null) { 122 throw error(L.l("<jsp:output> with a 'doctype-public' attribute requires a 'doctype-system' attribute.")); 123 } 124 125 if (_doctypeRootElement != null && _doctypeSystem == null) { 126 throw error(L.l("<jsp:output> with a 'doctype-root-element' attribute requires a 'doctype-system' attribute.")); 127 } 128 129 _gen.setDoctypeSystem(_doctypeSystem); 130 _gen.setDoctypePublic(_doctypePublic); 131 _gen.setDoctypeRootElement(_doctypeRootElement); 132 } 133 134 137 public boolean isStatic() 138 { 139 return true; 140 } 141 142 147 public void printXml(WriteStream os) 148 throws IOException 149 { 150 } 151 152 157 public void generate(JspJavaWriter out) 158 throws Exception 159 { 160 } 161 } 162 | Popular Tags |