1 29 30 package com.caucho.jsp.java; 31 32 import com.caucho.jsp.JspParseException; 33 import com.caucho.util.L10N; 34 import com.caucho.vfs.WriteStream; 35 import com.caucho.xml.QName; 36 37 import java.io.IOException ; 38 import java.util.ArrayList ; 39 40 public class JspElement extends JspContainerNode { 41 static final L10N L = new L10N(JspElement.class); 42 43 static final private QName NAME = new QName("name"); 44 45 private String _name; 46 private JspAttribute _attrName; 47 48 private ArrayList <QName> _attrNames = new ArrayList <QName>(); 49 private ArrayList <JspAttribute> _attrValues = new ArrayList <JspAttribute>(); 50 51 57 public void addAttribute(QName name, String value) 58 throws JspParseException 59 { 60 if (NAME.equals(name)) { 61 _name = value; 62 } 63 else { 64 throw error(L.l("`{0}' is an unknown jsp:element attribute. See the JSP documentation for a complete list of jsp:element directive attributes.", 65 name.getName())); 66 } 67 } 68 69 75 public void addAttribute(QName name, JspAttribute value) 76 throws JspParseException 77 { 78 if (_name == null && NAME.equals(name)) { 79 _attrName = value; 80 } 81 else { 82 _attrNames.add(name); 83 _attrValues.add(value); 84 } 85 } 86 87 90 public void endElement() 91 throws JspParseException 92 { 93 if (_name == null && _attrName == null) { 94 throw error(L.l("jsp:element requires a `name' attribute.")); 95 } 96 } 97 98 101 public boolean isStatic() 102 { 103 return false; 104 } 105 106 111 public void printXml(WriteStream os) 112 throws IOException 113 { 114 os.print("<jsp:element name=\"" + _name + "\">"); 115 printXmlChildren(os); 116 os.print("</jsp:element>"); 117 } 118 119 124 public void generate(JspJavaWriter out) 125 throws Exception 126 { 127 String var = null; 128 129 if (_attrName != null) { 130 var = "_caucho_var" + _gen.uniqueId(); 131 132 out.println("String " + var + " = " + _attrName.generateValue() + ";"); 133 } 134 else if (hasELAttribute(_name)) { 135 var = "_caucho_var" + _gen.uniqueId(); 136 int index = _gen.addExpr(_name); 137 138 out.println("String " + var + " = _caucho_expr_" + index + ".evalString(_jsp_env);"); 139 } 140 else if (hasRuntimeAttribute(_name)) { 141 143 var = "_caucho_var" + _gen.uniqueId(); 144 145 out.println("String " + var + " = " + getRuntimeAttribute(_name) + ";"); 146 } 147 148 if (var != null) { 149 out.addText("<"); 150 out.println("out.print(" + var + ");"); 151 } 152 else 153 out.addText("<" + _name); 154 155 for (int i = 0; i < _attrNames.size(); i++) { 156 QName name = _attrNames.get(i); 157 JspAttribute value = _attrValues.get(i); 158 159 out.addText(" " + name.getName() + "=\""); 160 161 if (value.isStatic()) 162 out.addText(value.getStaticText()); 163 else 164 out.print("out.print(" + value.generateValue() + ");"); 165 166 out.addText("\""); 167 } 168 169 170 out.addText(">"); 171 172 generateChildren(out); 173 174 if (var != null) { 175 out.println("out.print(\"</\");"); 176 out.println("out.print(" + var + ");"); 177 out.println("out.print(\">\");"); 178 } 179 else 180 out.addText("</" + _name + ">"); 181 } 182 } 183 | Popular Tags |