1 29 30 package com.caucho.jsp.java; 31 32 import com.caucho.jsp.JspParseException; 33 import com.caucho.vfs.WriteStream; 34 import com.caucho.xml.QName; 35 36 import java.io.IOException ; 37 38 44 public class JstlFmtSetBundle extends JstlNode { 45 private static final QName BASENAME = new QName("basename"); 46 private static final QName VAR = new QName("var"); 47 private static final QName SCOPE = new QName("scope"); 48 49 private String _basename; 50 private JspAttribute _basenameAttr; 51 52 private String _var = "javax.servlet.jsp.jstl.fmt.localizationContext"; 53 private String _scope; 54 55 58 public void addAttribute(QName name, String value) 59 throws JspParseException 60 { 61 if (BASENAME.equals(name)) 62 _basename = value; 63 else if (VAR.equals(name)) 64 _var = value; 65 else if (SCOPE.equals(name)) 66 _scope = value; 67 else 68 throw error(L.l("`{0}' is an unknown attribute for <{1}>.", 69 name.getName(), getTagName())); 70 } 71 72 75 public void addAttribute(QName name, JspAttribute value) 76 throws JspParseException 77 { 78 if (BASENAME.equals(name)) 79 _basenameAttr = value; 80 else 81 throw error(L.l("`{0}' is an unsupported jsp:attribute for <{1}>.", 82 name.getName(), getTagName())); 83 } 84 85 90 public void printXml(WriteStream os) 91 throws IOException 92 { 93 os.print("<fmt:bundle"); 94 95 if (_basename != null) 96 os.print(" basename=\"" + xmlText(_basename) + "\""); 97 98 if (_var != null) 99 os.print(" var=\"" + xmlText(_var) + "\""); 100 101 if (_scope != null) 102 os.print(" scope=\"" + xmlText(_scope) + "\""); 103 104 os.print(">"); 105 106 printXmlChildren(os); 107 108 os.print("</fmt:bundle>"); 109 } 110 111 114 public void generate(JspJavaWriter out) 115 throws Exception 116 { 117 if (_basename == null && _basenameAttr == null) 118 throw error(L.l("required attribute `basename' missing from `{0}'", 119 getTagName())); 120 121 String basenameExpr; 122 123 if (_basenameAttr != null) 124 basenameExpr = _basenameAttr.generateValue(); 125 else 126 basenameExpr = generateValue(String .class, _basename); 127 128 String value = "pageContext.getBundle(" + basenameExpr + ")"; 129 130 generateSetNotNull(out, _var, _scope, value); 131 } 132 } 133 | Popular Tags |