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 JstlFmtBundle 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 private static final QName PREFIX = new QName("prefix"); 49 50 private String _basename; 51 private JspAttribute _basenameAttr; 52 53 private String _var; 54 private String _scope; 55 56 private String _prefix; 57 private JspAttribute _prefixAttr; 58 59 62 public void addAttribute(QName name, String value) 63 throws JspParseException 64 { 65 if (BASENAME.equals(name)) 66 _basename = value; 67 else if (VAR.equals(name)) 68 _var = value; 69 else if (SCOPE.equals(name)) 70 _scope = value; 71 else if (PREFIX.equals(name)) 72 _prefix = value; 73 else 74 throw error(L.l("`{0}' is an unknown attribute for <{1}>.", 75 name.getName(), getTagName())); 76 } 77 78 81 public boolean hasScripting() 82 { 83 return (super.hasScripting() || 84 hasScripting(_prefix) || hasScripting(_prefixAttr)); 85 } 86 87 90 public String getPrefixCode() 91 { 92 if (_prefix != null) 93 return "\"" + _prefix + "\" + "; 94 else 95 return ""; 96 } 97 98 103 public void printXml(WriteStream os) 104 throws IOException 105 { 106 os.print("<fmt:bundle"); 107 108 if (_basename != null) 109 os.print(" basename=\"" + xmlText(_basename) + "\""); 110 111 if (_var != null) 112 os.print(" var=\"" + xmlText(_var) + "\""); 113 114 if (_scope != null) 115 os.print(" scope=\"" + xmlText(_scope) + "\""); 116 117 if (_prefix != null) 118 os.print(" prefix=\"" + xmlText(_prefix) + "\""); 119 120 os.print(">"); 121 122 printXmlChildren(os); 123 124 os.print("</fmt:bundle>"); 125 } 126 127 130 public void generate(JspJavaWriter out) 131 throws Exception 132 { 133 if (_basename == null && _basenameAttr == null) 134 throw error(L.l("required attribute `basename' missing from `{0}'", 135 getTagName())); 136 137 String basenameExpr; 138 139 if (_basenameAttr != null) 140 basenameExpr = _basenameAttr.generateValue(); 141 else 142 basenameExpr = generateValue(String .class, _basename); 143 144 String oldVar = "_caucho_bundle_" + _gen.uniqueId(); 145 146 out.print("Object " + oldVar + " = pageContext.putAttribute(\"caucho.bundle\", "); 147 out.println("pageContext.getBundle(" + basenameExpr + "));"); 148 149 String oldPrefixVar = "_caucho_bundle_prefix_" + _gen.uniqueId(); 150 151 if (_prefix != null) 152 out.println("Object " + oldPrefixVar + " = pageContext.putAttribute(\"caucho.bundle.prefix\", \"" + _prefix + "\");"); 153 else 154 out.println("Object " + oldPrefixVar + " = pageContext.putAttribute(\"caucho.bundle.prefix\", null);"); 155 156 194 195 out.println("try {"); 196 out.pushDepth(); 197 198 generateChildren(out); 199 200 out.popDepth(); 201 out.println("} finally {"); 202 out.println(" pageContext.setAttribute(\"caucho.bundle\", " + oldVar + ");"); 203 out.println(" pageContext.setAttribute(\"caucho.bundle.prefix\", " + oldPrefixVar + ");"); 204 209 210 out.println("}"); 211 } 212 } 213 | Popular Tags |