1 28 29 package com.caucho.jsp.java; 30 31 import com.caucho.jsp.JspParseException; 32 import com.caucho.vfs.WriteStream; 33 import com.caucho.xml.QName; 34 35 import java.io.IOException ; 36 37 40 public class JstlCoreRtWhen extends JstlNode { 41 private static final QName TEST = new QName("test"); 42 private Object _test; 43 44 47 public void addAttribute(QName name, String value) 48 throws JspParseException 49 { 50 if (TEST.equals(name)) 51 _test = value; 52 else 53 throw error(L.l("`{0}' is an unknown attribute for <{1}>.", 54 name.getName(), getTagName())); 55 } 56 57 60 public void addAttribute(String name, JspAttribute value) 61 throws JspParseException 62 { 63 if (name.equals("test")) 64 _test = value; 65 else 66 throw error(L.l("`{0}' can is an illegal jsp:attribute for <{1}>.", 67 name, getTagName())); 68 } 69 70 75 public void printXml(WriteStream os) 76 throws IOException 77 { 78 os.print("<c-rt:when"); 79 80 if (_test instanceof String ) { 81 os.print(" test=\""); 82 printXmlText(os, (String ) _test); 83 os.print("\">"); 84 } 85 else { 86 os.print(">"); 87 } 88 89 printXmlChildren(os); 90 91 os.print("</c-rt:when>"); 92 } 93 94 97 public void generate(JspJavaWriter out) 98 throws Exception 99 { 100 if (_test == null) 101 throw error(L.l("required attribute `test' missing from <{0}>", 102 getTagName())); 103 104 String ifExpr = generateRTValue(boolean.class, _test); 105 106 out.println("if (" + ifExpr + ") {"); 107 out.pushDepth(); 108 generateChildren(out); 109 110 out.popDepth(); 111 out.println("}"); 112 } 113 } 114 | Popular Tags |