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 public class JstlCoreSet extends JstlNode { 39 private static final QName VALUE = new QName("value"); 40 private static final QName VAR = new QName("var"); 41 private static final QName SCOPE = new QName("scope"); 42 private static final QName TARGET = new QName("target"); 43 private static final QName PROPERTY = new QName("property"); 44 45 private String _value; 46 private JspAttribute _valueAttr; 47 48 private String _var; 49 private String _scope; 50 51 private String _target; 52 private JspAttribute _targetAttr; 53 54 private String _property; 55 private JspAttribute _propertyAttr; 56 57 60 public void addAttribute(QName name, String value) 61 throws JspParseException 62 { 63 if (VALUE.equals(name)) 64 _value = value; 65 else if (VAR.equals(name)) 66 _var = value; 67 else if (SCOPE.equals(name)) 68 _scope = value; 69 else if (TARGET.equals(name)) 70 _target = value; 71 else if (PROPERTY.equals(name)) 72 _property = value; 73 else 74 throw error(L.l("`{0}' is an unknown attribute for <{1}>.", 75 name.getName(), getTagName())); 76 } 77 78 81 public void addAttribute(QName name, JspAttribute value) 82 throws JspParseException 83 { 84 if (VALUE.equals(name)) 85 _valueAttr = value; 86 else if (TARGET.equals(name)) 87 _targetAttr = value; 88 else if (PROPERTY.equals(name)) 89 _propertyAttr = value; 90 else 91 throw error(L.l("`{0}' is an unsupported jsp:attribute for <{1}>.", 92 name.getName(), getTagName())); 93 } 94 95 98 public boolean hasScripting() 99 { 100 return (super.hasScripting() || 101 hasScripting(_value) || hasScripting(_valueAttr) || 102 hasScripting(_target) || hasScripting(_targetAttr) || 103 hasScripting(_property) || hasScripting(_propertyAttr)); 104 } 105 106 111 public void printXml(WriteStream os) 112 throws IOException 113 { 114 os.print("<c:set"); 115 116 if (_value != null) { 117 os.print(" value=\""); 118 printXmlText(os, _value); 119 os.print("\""); 120 } 121 122 if (_var != null) 123 os.print(" var=\"" + _var + "\""); 124 125 if (_scope != null) 126 os.print(" scope=\"" + _scope + "\""); 127 128 if (_target != null) 129 os.print(" target=\"" + _target + "\""); 130 131 if (_property != null) 132 os.print(" property=\"" + _property + "\""); 133 134 os.print(">"); 135 136 printXmlChildren(os); 137 138 os.print("</c:set>"); 139 } 140 141 144 public void generate(JspJavaWriter out) 145 throws Exception 146 { 147 if (_value != null) { 148 String value = generateValue(Object .class, _value); 149 150 generateSet(out, value); 151 } 152 else if (_valueAttr != null) { 153 generateSet(out, _valueAttr.generateValue()); 154 } 155 else if (! hasChildren()) { 156 generateSet(out, "\"\""); 157 } 158 else if (isChildrenStatic()) { 159 generateSet(out, '"' + escapeJavaString(getStaticText().trim()) + '"'); 160 } 161 else if (hasChildren()) { 162 out.println("out = pageContext.pushBody();"); 163 164 generateChildren(out); 165 166 String cauchoVar = "_caucho_var_" + _gen.uniqueId(); 167 168 out.println("Object " + cauchoVar + " = ((com.caucho.jsp.BodyContentImpl) out).getTrimString();"); 169 170 out.println("out = pageContext.popAndReleaseBody();"); 171 172 generateSet(out, cauchoVar); 173 } 174 } 175 176 private void generateSet(JspJavaWriter out, String value) 177 throws Exception 178 { 179 if (_var != null) 180 generateSetOrRemove(out, _var, _scope, value); 181 else { 182 out.print("com.caucho.el.Expr.setProperty("); 183 if (_targetAttr != null) 184 out.print(_targetAttr.generateValue() + ", "); 185 else 186 out.print(generateValue(Object .class, _target) + ", "); 187 188 if (_propertyAttr != null) 189 out.print(_propertyAttr.generateValue() + ", "); 190 else 191 out.print(generateValue(String .class, _property) + ", "); 192 193 out.println(value + ");"); 194 } 195 } 196 } 197 | Popular Tags |