in src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/Generator.java [1389:1623]
public void visit(Node.PlugIn n) throws JasperException {
/**
* A visitor to handle <jsp:param> in a plugin
*/
class ParamVisitor extends Node.Visitor {
private boolean ie;
ParamVisitor(boolean ie) {
this.ie = ie;
}
@Override
public void visit(Node.ParamAction n) throws JasperException {
String name = n.getTextAttribute("name");
if (name.equalsIgnoreCase("object")) {
name = "java_object";
} else if (name.equalsIgnoreCase("type")) {
name = "java_type";
}
n.setBeginJavaLine(out.getJavaLine());
// XXX - Fixed a bug here - value used to be output
// inline, which is only okay if value is not an EL
// expression. Also, key/value pairs for the
// embed tag were not being generated correctly.
// Double check that this is now the correct behavior.
if (ie) {
// We want something of the form
// out.println( "<param name=\"blah\"
// value=\"" + ... + "\">" );
out.printil("out.write( \"<param name=\\\""
+ escape(name)
+ "\\\" value=\\\"\" + "
+ attributeValue(n.getValue(), false,
String.class) + " + \"\\\">\" );");
out.printil("out.write(\"\\n\");");
} else {
// We want something of the form
// out.print( " blah=\"" + ... + "\"" );
out.printil("out.write( \" "
+ escape(name)
+ "=\\\"\" + "
+ attributeValue(n.getValue(), false,
String.class) + " + \"\\\"\" );");
}
n.setEndJavaLine(out.getJavaLine());
}
}
String type = n.getTextAttribute("type");
String code = n.getTextAttribute("code");
String name = n.getTextAttribute("name");
Node.JspAttribute height = n.getHeight();
Node.JspAttribute width = n.getWidth();
String hspace = n.getTextAttribute("hspace");
String vspace = n.getTextAttribute("vspace");
String align = n.getTextAttribute("align");
String iepluginurl = n.getTextAttribute("iepluginurl");
String nspluginurl = n.getTextAttribute("nspluginurl");
String codebase = n.getTextAttribute("codebase");
String archive = n.getTextAttribute("archive");
String jreversion = n.getTextAttribute("jreversion");
String widthStr = null;
if (width != null) {
if (width.isNamedAttribute()) {
widthStr = generateNamedAttributeValue(width
.getNamedAttributeNode());
} else {
widthStr = attributeValue(width, false, String.class);
}
}
String heightStr = null;
if (height != null) {
if (height.isNamedAttribute()) {
heightStr = generateNamedAttributeValue(height
.getNamedAttributeNode());
} else {
heightStr = attributeValue(height, false, String.class);
}
}
if (iepluginurl == null) {
iepluginurl = Constants.IE_PLUGIN_URL;
}
if (nspluginurl == null) {
nspluginurl = Constants.NS_PLUGIN_URL;
}
n.setBeginJavaLine(out.getJavaLine());
// If any of the params have their values specified by
// jsp:attribute, prepare those values first.
// Look for a params node and prepare its param subelements:
Node.JspBody jspBody = findJspBody(n);
if (jspBody != null) {
Node.Nodes subelements = jspBody.getBody();
if (subelements != null) {
for (int i = 0; i < subelements.size(); i++) {
Node m = subelements.getNode(i);
if (m instanceof Node.ParamsAction) {
prepareParams(m);
break;
}
}
}
}
// XXX - Fixed a bug here - width and height can be set
// dynamically. Double-check if this generation is correct.
// IE style plugin
// <object ...>
// First compose the runtime output string
String s0 = "<object"
+ makeAttr("classid", ctxt.getOptions().getIeClassId())
+ makeAttr("name", name);
String s1 = "";
if (width != null) {
s1 = " + \" width=\\\"\" + " + widthStr + " + \"\\\"\"";
}
String s2 = "";
if (height != null) {
s2 = " + \" height=\\\"\" + " + heightStr + " + \"\\\"\"";
}
String s3 = makeAttr("hspace", hspace) + makeAttr("vspace", vspace)
+ makeAttr("align", align)
+ makeAttr("codebase", iepluginurl) + '>';
// Then print the output string to the java file
out.printil("out.write(" + quote(s0) + s1 + s2 + " + " + quote(s3)
+ ");");
out.printil("out.write(\"\\n\");");
// <param > for java_code
s0 = "<param name=\"java_code\"" + makeAttr("value", code) + '>';
out.printil("out.write(" + quote(s0) + ");");
out.printil("out.write(\"\\n\");");
// <param > for java_codebase
if (codebase != null) {
s0 = "<param name=\"java_codebase\""
+ makeAttr("value", codebase) + '>';
out.printil("out.write(" + quote(s0) + ");");
out.printil("out.write(\"\\n\");");
}
// <param > for java_archive
if (archive != null) {
s0 = "<param name=\"java_archive\""
+ makeAttr("value", archive) + '>';
out.printil("out.write(" + quote(s0) + ");");
out.printil("out.write(\"\\n\");");
}
// <param > for type
s0 = "<param name=\"type\""
+ makeAttr("value", "application/x-java-"
+ type
+ ";"
+ ((jreversion == null) ? "" : "version="
+ jreversion)) + '>';
out.printil("out.write(" + quote(s0) + ");");
out.printil("out.write(\"\\n\");");
/*
* generate a <param> for each <jsp:param> in the plugin body
*/
if (n.getBody() != null) {
n.getBody().visit(new ParamVisitor(true));
}
/*
* Netscape style plugin part
*/
out.printil("out.write(" + quote("<comment>") + ");");
out.printil("out.write(\"\\n\");");
s0 = "<EMBED"
+ makeAttr("type", "application/x-java-"
+ type
+ ";"
+ ((jreversion == null) ? "" : "version="
+ jreversion)) + makeAttr("name", name);
// s1 and s2 are the same as before.
s3 = makeAttr("hspace", hspace) + makeAttr("vspace", vspace)
+ makeAttr("align", align)
+ makeAttr("pluginspage", nspluginurl)
+ makeAttr("java_code", code)
+ makeAttr("java_codebase", codebase)
+ makeAttr("java_archive", archive);
out.printil("out.write(" + quote(s0) + s1 + s2 + " + " + quote(s3)
+ ");");
/*
* Generate a 'attr = "value"' for each <jsp:param> in plugin body
*/
if (n.getBody() != null) {
n.getBody().visit(new ParamVisitor(false));
}
out.printil("out.write(" + quote("/>") + ");");
out.printil("out.write(\"\\n\");");
out.printil("out.write(" + quote("<noembed>") + ");");
out.printil("out.write(\"\\n\");");
/*
* Fallback
*/
if (n.getBody() != null) {
visitBody(n);
out.printil("out.write(\"\\n\");");
}
out.printil("out.write(" + quote("</noembed>") + ");");
out.printil("out.write(\"\\n\");");
out.printil("out.write(" + quote("</comment>") + ");");
out.printil("out.write(\"\\n\");");
out.printil("out.write(" + quote("</object>") + ");");
out.printil("out.write(\"\\n\");");
n.setEndJavaLine(out.getJavaLine());
}