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 import java.util.ArrayList ; 37 38 41 public class JspPlugin extends JspNode { 42 private static final QName NAME = new QName("name"); 43 private static final QName TYPE = new QName("type"); 44 private static final QName CODE = new QName("code"); 45 private static final QName CODEBASE = new QName("codebase"); 46 private static final QName IEPLUGINURL = new QName("iepluginurl"); 47 private static final QName JREVERSION = new QName("jreversion"); 48 private static final QName NSPLUGINURL = new QName("nspluginurl"); 49 private static final QName WIDTH = new QName("width"); 50 private static final QName HEIGHT = new QName("height"); 51 private static final QName ALIGN = new QName("align"); 52 private static final QName VSPACE = new QName("vspace"); 53 private static final QName HSPACE = new QName("hspace"); 54 private static final QName ARCHIVE = new QName("archive"); 55 56 static final String IE_CLSID = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"; 57 static final String IE_URL = "http://java.sun.com/products/plugin/1.2.2/jinstall-1_2_2-win.cab#Version=1,2,2,0"; 58 static final String NS_URL = "http://java.sun.com/products/plugin/"; 59 60 private String _name; 61 private String _type; 62 private String _code; 63 64 private String _jreversion; 65 private String _nspluginurl; 66 private String _iepluginurl; 67 68 private String _width; 69 private String _height; 70 private String _archive; 71 72 private ArrayList <String > _attrNames = new ArrayList <String >(); 73 private ArrayList <String > _attrValues = new ArrayList <String >(); 74 75 private JspParams _params; 76 77 private JspFallback _fallback; 78 79 82 public void addAttribute(QName name, String value) 83 throws JspParseException 84 { 85 if (NAME.equals(name)) { 86 _name = value; 87 88 checkForbidExpression("name", value); 89 } 90 else if (TYPE.equals(name)) { 91 _type = value; 92 93 checkForbidExpression("type", value); 94 } 95 else if (CODE.equals(name)) { 96 _code = value; 97 98 checkForbidExpression("code", value); 99 } 100 else if (IEPLUGINURL.equals(name)) { 101 _iepluginurl = value; 102 103 checkForbidExpression("ispluginurl", value); 104 } 105 else if (JREVERSION.equals(name)) { 106 _jreversion = value; 107 108 checkForbidExpression("jreversion", value); 109 } 110 else if (NSPLUGINURL.equals(name)) { 111 _nspluginurl = value; 112 113 checkForbidExpression("nspluginurl", value); 114 } 115 else if (WIDTH.equals(name)) { 116 } 117 else if (HEIGHT.equals(name)) { 118 } 119 else if (ALIGN.equals(name)) { 120 checkForbidExpression("align", value); 121 } 122 else if (VSPACE.equals(name)) { 123 checkForbidExpression("vspace", value); 124 } 125 else if (HSPACE.equals(name)) { 126 checkForbidExpression("hspace", value); 127 } 128 else if (ARCHIVE.equals(name)) { 129 checkForbidExpression("archive", value); 130 } 131 else if (CODEBASE.equals(name)) { 132 checkForbidExpression("codebase", value); 133 } 134 else 135 super.addAttribute(name, value); 136 137 _attrNames.add(name.getName()); 138 _attrValues.add(value); 139 } 140 141 private void checkForbidExpression(String attribute, String value) 142 throws JspParseException 143 { 144 if (hasELAttribute(value)) 145 throw error(L.l("'{0}' may not have EL expression '{1}'", 146 attribute, value)); 147 else if (hasRuntimeAttribute(value)) 148 throw error(L.l("'{0}' may not have RT expression '{1}'", 149 attribute, value)); 150 } 151 152 155 public void addChild(JspNode node) 156 throws JspParseException 157 { 158 if (node instanceof JspParams) { 159 _params = (JspParams) node; 160 } 161 else if (node instanceof JspFallback) { 162 _fallback = (JspFallback) node; 163 } 164 else if (node instanceof JspBody) { 165 } 166 else { 167 super.addChild(node); 168 } 169 } 170 171 174 public void addChildEnd(JspNode node) 175 throws JspParseException 176 { 177 if (node instanceof JspBody) { 178 JspBody body = (JspBody) node; 179 180 for (JspNode child : body.getChildren()) 181 addChild(child); 182 } 183 else 184 super.addChildEnd(node); 185 } 186 187 190 public void endElement() 191 throws JspParseException 192 { 193 if (_code == null) 194 throw error(L.l("<jsp:plugin> expects a `code' attribute.")); 195 196 if (_type == null) 197 throw error(L.l("<jsp:plugin> expects a `type' attribute.")); 198 else if (! _type.equals("applet") && ! _type.equals("bean")) 199 throw error(L.l("`type' attribute of <jsp:plugin> must either be `applet' or `bean'.")); 200 201 if (_iepluginurl == null) 202 _iepluginurl = IE_URL; 203 204 if (_nspluginurl == null) 205 _nspluginurl = NS_URL; 206 } 207 208 213 public void printXml(WriteStream os) 214 throws IOException 215 { 216 os.print("<jsp:plugin/>"); 217 } 218 219 224 public void generate(JspJavaWriter out) 225 throws Exception 226 { 227 String type = null; 228 if (_type.equals("applet")) 229 type = "application/x-java-applet"; 230 else if (_type.equals("bean")) 231 type = "application/x-java-bean"; 232 233 if (_jreversion != null) 234 type = type + ";version=" + _jreversion; 235 236 printText(out, "<object classid=\"" + IE_CLSID + "\""); 237 printText(out, " codebase=\"" + _iepluginurl + "\""); 238 239 generateObjectParams(out, false); 240 241 printText(out, "<param name=\"type\" value=\"" + type + "\">\n"); 242 243 printText(out, "<comment>"); 244 245 printText(out, "<embed type=\"" + type + "\""); 246 printText(out, " codebase=\"" + _nspluginurl + "\""); 247 248 generateObjectParams(out, true); 249 250 printText(out, ">\n<noembed></comment>"); 251 252 if (_fallback != null) 253 _fallback.generateFallback(out); 254 255 printText(out, "</noembed></embed></object>\n"); 256 } 257 258 261 protected void generateObjectParams(JspJavaWriter out, boolean isEmbed) 262 throws Exception 263 { 264 for (int i = 0; i < _attrNames.size(); i++) { 265 String name = _attrNames.get(i); 266 String value = _attrValues.get(i); 267 268 if (name.equals("type") || name.equals("jreversion") || 269 name.equals("iepluginurl") || name.equals("nspluginurl") || 270 name.equals("code") || name.equals("archive") || 271 name.equals("codebase") || name.equals("object")) 272 continue; 273 274 printText(out, " " + name + "=\""); 275 276 out.println("out.print(" + generateValue(String .class, value) + ");"); 277 278 printText(out, "\""); 279 } 280 281 if (! isEmbed) 282 printText(out, ">\n"); 283 284 for (int i = 0; i < _attrNames.size(); i++) { 285 String name = _attrNames.get(i); 286 String value = _attrValues.get(i); 287 288 if (name.equals("archive")) 289 name = "java_archive"; 290 else if (name.equals("codebase")) 291 name = "java_codebase"; 292 else if (name.equals("code")) 293 name = "java_code"; 294 else if (name.equals("object")) 295 name = "java_object"; 296 else 297 continue; 298 299 if (isEmbed) { 300 printText(out, " " + name + "=\""); 301 302 if (hasRuntimeAttribute(value)) 303 out.println("out.print(" + getRuntimeAttribute(value) + ");"); 304 else 305 printText(out, value); 306 307 printText(out, "\""); 308 } 309 else { 310 printText(out, "<param name=\"" + name + "\" value=\""); 311 312 if (hasRuntimeAttribute(value)) 313 out.println("out.print(" + getRuntimeAttribute(value) + ");"); 314 else 315 printText(out, value); 316 317 printText(out, "\">\n"); 318 } 319 } 320 321 if (_params == null) 322 return; 323 324 ArrayList <JspParam> paramList = _params.getParams(); 325 326 for (int i = 0; i < paramList.size(); i++) { 327 JspParam param = paramList.get(i); 328 329 String name = param.getName(); 330 String value = param.getValue(); 331 332 if (isEmbed) 333 printText(out, " " + name + "=\""); 334 else 335 printText(out, "<param name=\"" + name + "\" value=\""); 336 337 if (hasRuntimeAttribute(value)) { 338 out.println("out.print(" + getRuntimeAttribute(value) + ");"); 339 } 340 else 341 printText(out, value); 342 343 if (isEmbed) 344 printText(out, "\""); 345 else 346 printText(out, "\">\n"); 347 } 348 } 349 350 private void printText(JspJavaWriter out, String text) 351 throws Exception 352 { 353 out.print("out.print(\""); 354 out.printJavaString(text); 355 out.println("\");"); 356 } 357 } 358 359 | Popular Tags |