1 28 29 package com.caucho.jsp.java; 30 31 import com.caucho.jsp.JspParseException; 32 import com.caucho.util.L10N; 33 import com.caucho.vfs.WriteStream; 34 import com.caucho.xml.QName; 35 36 import java.io.IOException ; 37 38 public class JspDirectiveTag extends JspNode { 39 private static final QName IMPORT = new QName("import"); 40 private static final QName DISPLAY_NAME = new QName("display-name"); 41 private static final QName BODY_CONTENT = new QName("body-content"); 42 private static final QName DYNAMIC_ATTRIBUTES 43 = new QName("dynamic-attributes"); 44 private static final QName SMALL_ICON = new QName("small-icon"); 45 private static final QName LARGE_ICON = new QName("large-icon"); 46 private static final QName DESCRIPTION = new QName("description"); 47 private static final QName EXAMPLE = new QName("example"); 48 private static final QName LANGUAGE = new QName("language"); 49 private static final QName PAGE_ENCODING = new QName("pageEncoding"); 50 private static final QName IS_EL_IGNORED = new QName("isELIgnored"); 51 private static final QName DEFERRED_AS_LITERAL 52 = new QName("deferredSyntaxAllowedAsLiteral"); 53 private static final QName TRIM_WHITESPACES 54 = new QName("trimDirectiveWhitespaces"); 55 56 private static final QName IS_VELOCITY_ENABLED = 57 new QName("isVelocityEnabled"); 58 59 static final L10N L = new L10N(JspDirectiveTag.class); 60 61 private Boolean _isElIgnored; 62 private String _import; 63 64 70 public void addAttribute(QName name, String value) 71 throws JspParseException 72 { 73 if (! _gen.isTag()) 74 throw error(L.l("@tag directive is only allowed in tag files")); 75 76 JavaTagGenerator gen = (JavaTagGenerator) _gen; 77 78 if (IS_EL_IGNORED.equals(name)) { 79 boolean isIgnored = value.equals("true"); 80 81 _parseState.setELIgnored(isIgnored); 82 83 if (_isElIgnored != null && _isElIgnored.booleanValue() != isIgnored) 84 throw error(L.l("isELIgnored values conflict")); 85 86 _isElIgnored = new Boolean (isIgnored); 87 } 88 92 else if (IS_VELOCITY_ENABLED.equals(name)) 93 _parseState.setVelocityEnabled(value.equals("true")); 94 else if (PAGE_ENCODING.equals(name)) { 95 String oldEncoding = _parseState.getPageEncoding(); 96 97 if (oldEncoding != null && ! value.equals(oldEncoding)) 98 throw error(L.l("pageEncoding `{0}' conflicts with previous value of pageEncoding `{1}'. Check the .jsp and any included .jsp files for conflicts.", value, oldEncoding)); 99 100 _parseState.setPageEncoding(value); 101 } 102 else if (LANGUAGE.equals(name)) { 103 if (! value.equals("java")) 104 throw error(L.l("`{0}' is not supported as a JSP scripting language.", 105 value)); 106 } 107 else if (IMPORT.equals(name)) { 108 _import = value; 109 110 _parseState.addImport(value); 111 } 112 else if (DISPLAY_NAME.equals(name)) { 113 String oldValue = gen.getDisplayName(); 114 115 if (oldValue != null && ! oldValue.equals(value)) 116 throw error(L.l("@tag display-name '{0}' conflicts with previous value '{1}'. The display-name attribute may only be specified once.", 117 value, oldValue)); 118 119 120 gen.setDisplayName(value); 121 } 122 else if (SMALL_ICON.equals(name)) { 123 String oldValue = gen.getSmallIcon(); 124 125 if (oldValue != null && ! oldValue.equals(value)) 126 throw error(L.l("@tag small-icon '{0}' conflicts with previous value '{1}'. The small-icon attribute may only be specified once.", 127 value, oldValue)); 128 129 130 gen.setSmallIcon(value); 131 } 132 else if (LARGE_ICON.equals(name)) { 133 String oldValue = gen.getLargeIcon(); 134 135 if (oldValue != null && ! oldValue.equals(value)) 136 throw error(L.l("@tag large-icon '{0}' conflicts with previous value '{1}'. The large-icon attribute may only be specified once.", 137 value, oldValue)); 138 139 140 gen.setLargeIcon(value); 141 } 142 else if (DESCRIPTION.equals(name)) { 143 String oldValue = gen.getDescription(); 144 145 if (oldValue != null && ! oldValue.equals(value)) 146 throw error(L.l("@tag description '{0}' conflicts with previous value '{1}'. The description attribute may only be specified once.", 147 value, oldValue)); 148 149 150 gen.setDescription(value); 151 } 152 else if (EXAMPLE.equals(name)) { 153 String oldValue = gen.getExample(); 154 155 if (oldValue != null && ! oldValue.equals(value)) 156 throw error(L.l("@tag example '{0}' conflicts with previous value '{1}'. The example attribute may only be specified once.", 157 value, oldValue)); 158 159 160 gen.setExample(value); 161 } 162 else if (DYNAMIC_ATTRIBUTES.equals(name)) { 163 String oldValue = gen.getDynamicAttributes(); 164 165 if (oldValue != null && ! oldValue.equals(value)) 166 throw error(L.l("@tag dynamic-attributes '{0}' conflicts with previous value '{1}'. The dynamic-attributes attribute may only be specified once.", 167 value, oldValue)); 168 else if (gen.findAttribute(value) != null) { 169 throw error(L.l("@tag dynamic-attributes '{0}' conflicts with an attribute.", 170 value)); 171 } 172 else if (gen.findVariable(value) != null) { 173 throw error(L.l("@tag dynamic-attributes '{0}' conflicts with a variable.", 174 value)); 175 } 176 177 gen.setDynamicAttributes(value); 178 } 179 else if (BODY_CONTENT.equals(name)) { 180 String oldValue = gen.getBodyContent(); 181 182 if (oldValue != null && ! oldValue.equals(value)) { 183 throw error(L.l("@tag body-content '{0}' conflicts with previous value '{1}'. The body-content attribute may only be specified once.", 184 value, oldValue)); 185 } 186 187 if (value.equals("scriptless") || 188 value.equals("tagdependent") || 189 value.equals("empty")) { 190 } 191 else 192 throw error(L.l("'{0}' is an unknown body-content value for the JSP tag directive attribute. 'scriptless', 'tagdependent', and 'empty' are the allowed values.", 193 value)); 194 195 gen.setBodyContent(value); 196 } 197 else if (DEFERRED_AS_LITERAL.equals(name)) { 198 _parseState.setDeferredSyntaxAllowedAsLiteral(value.equals("true")); 199 } 200 else { 201 throw error(L.l("'{0}' is an unknown JSP tag directive attribute. The valid attributes are: body-content, deferredSyntaxAllowedAsLiteral, display-name, dynamic-attributes, example, isELIgnored, language, large-icon, pageEncoding, small-icon, trimDirectiveWhitespace.", 202 name.getName())); 203 } 204 } 205 206 protected String getRelativeUrl(String value) 207 { 208 if (value.length() > 0 && value.charAt(0) == '/') 209 return value; 210 else 211 return _parseState.getUriPwd() + value; 212 } 213 214 218 static String parseCharEncoding(String type) 219 throws JspParseException 220 { 221 type = type.toLowerCase(); 222 int i; 223 char ch; 224 while ((i = type.indexOf(';')) >= 0 && i < type.length()) { 225 i++; 226 while (i < type.length() && ((ch = type.charAt(i)) == ' ' || ch == '\t')) 227 i++; 228 229 if (i >= type.length()) 230 return null; 231 232 type = type.substring(i); 233 i = type.indexOf('='); 234 if (i >= 0) { 235 if (! type.startsWith("charset")) 236 continue; 237 238 for (i++; 239 i < type.length() && ((ch = type.charAt(i)) == ' ' || ch == '\t'); 240 i++) { 241 } 242 243 type = type.substring(i); 244 } 245 246 for (i = 0; 247 i < type.length() && (ch = type.charAt(i)) != ';' && ch != ' '; 248 i++) { 249 } 250 251 return type.substring(0, i); 252 } 253 254 return null; 255 } 256 257 260 public void endAttributes() 261 throws JspParseException 262 { 263 if (! _gen.isTag()) 264 throw error(L.l("tag directive is only allowed in tag files.")); 265 } 266 267 270 public boolean isStatic() 271 { 272 return true; 273 } 274 275 280 public void printXml(WriteStream os) 281 throws IOException 282 { 283 JavaTagGenerator gen = (JavaTagGenerator) _gen; 284 285 os.print("<jsp:directive.tag"); 286 os.print(" jsp:id=\"" + gen.generateJspId() + "\""); 287 288 if (_isElIgnored != null) 289 os.print(" el-ignored='" + _isElIgnored + "'"); 290 291 if (_import != null) 292 os.print(" import='" + _import + "'"); 293 294 298 String dynAttr = gen.getDynamicAttributes(); 299 if (dynAttr != null) 300 os.print("dynamic-attributes='" + dynAttr + "'"); 301 302 os.print("/>"); 303 } 304 305 310 public void generate(JspJavaWriter out) 311 throws Exception 312 { 313 } 314 } 315 | Popular Tags |