/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package org.apache.jasper.compiler;
private String createJspId() { if (this.jspIdPrefix == null) {
StringBuilder sb = new StringBuilder(32);
String name = ctxt.getServletJavaFileName();
sb.append("jsp_"); // Cast to long to avoid issue with Integer.MIN_VALUE
sb.append(Math.abs((long) name.hashCode()));
sb.append('_'); this.jspIdPrefix = sb.toString();
} returnthis.jspIdPrefix + (this.jspId++);
}
/** * Generates declarations. This includes "info" of the page directive, and * scriptlet declarations.
*/ privatevoid generateDeclarations(Node.Nodes page) throws JasperException {
class DeclarationVisitor extends Node.Visitor {
privateboolean getServletInfoGenerated = false;
/* * Generates getServletInfo() method that returns the value of the * page directive's 'info' attribute, if present. * * The Validator has already ensured that if the translation unit * contains more than one page directive with an 'info' attribute, * their values match.
*/
@Override publicvoid visit(Node.PageDirective n) throws JasperException {
if (getServletInfoGenerated) { return;
}
String info = n.getAttributeValue("info"); if (info == null) { return;
}
// Custom Tags may contain declarations from tag plugins.
@Override publicvoid visit(Node.CustomTag n) throws JasperException { if (n.useTagPlugin()) { // If a custom tag is configured to use a plug-in // getAtSTag() and getAtETag() will always be non-null
n.getAtSTag().visit(this);
visitBody(n);
n.getAtETag().visit(this);
} else {
visitBody(n);
}
}
}
/** * Compiles list of tag handler pool names.
*/ privatevoid compileTagHandlerPoolList(Node.Nodes page) throws JasperException {
class TagHandlerPoolVisitor extends Node.Visitor {
privatefinal List<String> names;
/* * Constructor * * @param v Vector of tag handler pool names to populate
*/
TagHandlerPoolVisitor(List<String> v) {
names = v;
}
/* * Gets the name of the tag handler pool for the given custom tag * and adds it to the list of tag handler pool names unless it is * already contained in it.
*/
@Override publicvoid visit(Node.CustomTag n) throws JasperException {
if (!n.implementsSimpleTag()) {
String name = createTagHandlerPoolName(n.getPrefix(), n
.getLocalName(), n.getAttributes(),
n.getNamedAttributeNodes(), n.hasEmptyBody());
n.setTagHandlerPoolName(name); if (!names.contains(name)) {
names.add(name);
}
}
visitBody(n);
}
/* * Creates the name of the tag handler pool whose tag handlers may * be (re)used to service this action. * * @return The name of the tag handler pool
*/ private String createTagHandlerPoolName(String prefix,
String shortName, Attributes attrs, Node.Nodes namedAttrs, boolean hasEmptyBody) {
StringBuilder poolName = new StringBuilder(64);
poolName.append("_jspx_tagPool_").append(prefix).append('_')
.append(shortName);
if (attrs != null) {
String[] attrNames = new String[attrs.getLength() + namedAttrs.size()]; for (int i = 0; i < attrNames.length; i++) {
attrNames[i] = attrs.getQName(i);
} for (int i = 0; i < namedAttrs.size(); i++) {
attrNames[attrs.getLength() + i] =
namedAttrs.getNode(i).getQName();
}
Arrays.sort(attrNames, Collections.reverseOrder()); if (attrNames.length > 0) {
poolName.append('&');
} for (String attrName : attrNames) {
poolName.append('_');
poolName.append(attrName);
}
} if (hasEmptyBody) {
poolName.append("_nobody");
} return JspUtil.makeJavaIdentifier(poolName.toString());
}
}
ScriptingVarVisitor() {
vars = new ArrayList<>();
}
@Override publicvoid visit(Node.CustomTag n) throws JasperException { // XXX - Actually there is no need to declare those // "_jspx_" + varName + "_" + nestingLevel variables when we are // inside a JspFragment.
/* * Generates getters for * - instance manager * - expression factory * * For JSPs these methods use lazy init. This is not an option for tag files * (at least it would be more complicated to generate) because the * ServletConfig is not readily available.
*/ privatevoid generateGetters() {
out.printil("public jakarta.el.ExpressionFactory _jsp_getExpressionFactory() {");
out.pushIndent(); if (!ctxt.isTagFile()) {
out.printin("if (");
out.print(ctxt.getOptions().getVariableForExpressionFactory());
out.println(" == null) {");
out.pushIndent();
out.printil("synchronized (this) {");
out.pushIndent();
out.printin("if (");
out.print(ctxt.getOptions().getVariableForExpressionFactory());
out.println(" == null) {");
out.pushIndent();
out.printin(ctxt.getOptions().getVariableForExpressionFactory());
out.println(" = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();");
out.popIndent();
out.printil("}");
out.popIndent();
out.printil("}");
out.popIndent();
out.printil("}");
}
out.printin("return ");
out.print(ctxt.getOptions().getVariableForExpressionFactory());
out.println(";");
out.popIndent();
out.printil("}");
/** * Generates the _jspInit() method for instantiating the tag handler pools. * For tag file, _jspInit has to be invoked manually, and the ServletConfig * object explicitly passed. * * In JSP 2.1, we also instantiate an ExpressionFactory
*/ privatevoid generateInit() {
out.pushIndent(); if (isPoolingEnabled) { for (int i = 0; i < tagHandlerPoolNames.size(); i++) {
out.printin(tagHandlerPoolNames.get(i));
out.print(" = org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool("); if (ctxt.isTagFile()) {
out.print("config");
} else {
out.print("getServletConfig()");
}
out.println(");");
}
}
// Tag files can't (easily) use lazy init for these so initialise them // here. if (ctxt.isTagFile()) {
out.printin(ctxt.getOptions().getVariableForExpressionFactory());
out.println(" = _jspxFactory.getJspApplicationContext(config.getServletContext()).getExpressionFactory();");
out.printin(ctxt.getOptions().getVariableForInstanceManager());
out.println(" = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(config);");
}
/** * Generates the _jspDestroy() method which is responsible for calling the * release() method on every tag handler in any of the tag handler pools.
*/ privatevoid generateDestroy() {
if (isPoolingEnabled) { for (int i = 0; i < tagHandlerPoolNames.size(); i++) {
out.printin(tagHandlerPoolNames.get(i));
out.println(".release();");
}
}
/** * Generate preamble package name (shared by servlet and tag handler * preamble generation). Package is always non-null as neither Servlets nor * tags can use a default package.
*/ privatevoid genPreamblePackage(String packageName) {
out.printil("package " + packageName + ";");
out.println();
}
/** * Generate preamble imports (shared by servlet and tag handler preamble * generation)
*/ privatevoid genPreambleImports() { for (String i : pageInfo.getImports()) {
out.printin("import ");
out.print(i);
out.println(";");
}
out.println();
}
/** * Generation of static initializers in preamble. For example, dependent * list, el function map, prefix map. (shared by servlet and tag handler * preamble generation)
*/ privatevoid genPreambleStaticInitializers() {
out.printil("private static final jakarta.servlet.jsp.JspFactory _jspxFactory =");
out.printil(" jakarta.servlet.jsp.JspFactory.getDefaultFactory();");
out.println();
// Static data for getDependants()
out.printil("private static java.util.Map _jspx_dependants;");
out.println();
Map<String,Long> dependants = pageInfo.getDependants(); if (!dependants.isEmpty()) {
out.printil("static {");
out.pushIndent();
out.printin("_jspx_dependants = new java.util.HashMap(");
out.print("" + dependants.size());
out.println(");"); for (Entry<String, Long> entry : dependants.entrySet()) {
out.printin("_jspx_dependants.put(\"");
out.print(entry.getKey());
out.print("\", Long.valueOf(");
out.print(entry.getValue().toString());
out.println("L));");
}
out.popIndent();
out.printil("}");
out.println();
}
// Static data for getImports()
List<String> imports = pageInfo.getImports();
Set<String> packages = new HashSet<>();
Set<String> classes = new HashSet<>(); for (String importName : imports) {
String trimmed = importName.trim(); if (trimmed.endsWith(".*")) {
packages.add(trimmed.substring(0, trimmed.length() - 2));
} else {
classes.add(trimmed);
}
}
out.printil("private static final java.util.Set _jspx_imports_packages;");
out.println();
out.printil("private static final java.util.Set _jspx_imports_classes;");
out.println();
out.printil("static {");
out.pushIndent(); // Packages is never empty because o.a.j.Constants.STANDARD_IMPORTS // contains 3 packages and is always added to the imports.
out.printin("_jspx_imports_packages = new java.util.HashSet<>();");
out.println(); for (String packageName : packages) {
out.printin("_jspx_imports_packages.add(\"");
out.print(packageName);
out.println("\");");
} // classes however, may be empty depending on the import declarations if (classes.size() == 0) {
out.printin("_jspx_imports_classes = null;");
out.println();
} else {
out.printin("_jspx_imports_classes = new java.util.HashSet<>();");
out.println(); for (String className : classes) {
out.printin("_jspx_imports_classes.add(\"");
out.print(className);
out.println("\");");
}
}
out.popIndent();
out.printil("}");
out.println();
}
/** * Declare tag handler pools (tags of the same type and with the same * attribute set share the same tag handler pool) (shared by servlet and tag * handler preamble generation) * * In JSP 2.1, we also scope an instance of ExpressionFactory
*/ privatevoid genPreambleClassVariableDeclarations() { if (isPoolingEnabled && !tagHandlerPoolNames.isEmpty()) { for (int i = 0; i < tagHandlerPoolNames.size(); i++) {
out.printil("private org.apache.jasper.runtime.TagHandlerPool " + tagHandlerPoolNames.get(i) + ";");
}
out.println();
}
out.printin("private volatile jakarta.el.ExpressionFactory ");
out.print(ctxt.getOptions().getVariableForExpressionFactory());
out.println(";");
out.printin("private volatile org.apache.tomcat.InstanceManager ");
out.print(ctxt.getOptions().getVariableForInstanceManager());
out.println(";");
out.println();
}
// First the package name:
genPreamblePackage(servletPackageName);
// Generate imports
genPreambleImports();
// Generate class declaration
out.printin("public final class ");
out.print(servletClassName);
out.print(" extends ");
out.println(pageInfo.getExtends());
out.printin(" implements org.apache.jasper.runtime.JspSourceDependent,");
out.println();
out.printin(" org.apache.jasper.runtime.JspSourceImports");
out.println(",");
out.printin(" org.apache.jasper.runtime.JspSourceDirectives");
out.println(" {");
out.pushIndent();
// Class body begins here
generateDeclarations(page);
// Static initializations here
genPreambleStaticInitializers();
// Class variable declarations
genPreambleClassVariableDeclarations();
// Methods here
genPreambleMethods();
// Now the service method if (pageInfo.isThreadSafe()) {
out.printin("public void ");
} else { // This is unlikely to perform well.
out.printin("public synchronized void "); // As required by JSP 3.1, log a warning
log.warn(Localizer.getMessage("jsp.warning.isThreadSafe", ctxt.getJspFile()));
}
out.print(serviceMethodName);
out.println("(final jakarta.servlet.http.HttpServletRequest request, final jakarta.servlet.http.HttpServletResponse response)");
out.pushIndent();
out.pushIndent();
out.printil("throws java.io.IOException, jakarta.servlet.ServletException {");
out.popIndent();
out.println();
/** * Generates an XML Prolog, which includes an XML declaration and an XML * doctype declaration.
*/ privatevoid generateXmlProlog(Node.Nodes page) {
/* * An XML declaration is generated under the following conditions: - * 'omit-xml-declaration' attribute of <jsp:output> action is set to * "no" or "false" - JSP document without a <jsp:root>
*/
String omitXmlDecl = pageInfo.getOmitXmlDecl(); if ((omitXmlDecl != null && !JspUtil.booleanValue(omitXmlDecl)) ||
(omitXmlDecl == null && page.getRoot().isXmlSyntax() && !pageInfo.hasJspRoot() && !ctxt.isTagFile())) {
String cType = pageInfo.getContentType();
String charSet = cType.substring(cType.indexOf("charset=") + 8);
out.printil("out.write(\"<?xml version=\\\"1.0\\\" encoding=\\\""
+ charSet + "\\\"?>\\n\");");
}
/* * Output a DOCTYPE declaration if the doctype-root-element appears. If * doctype-public appears: <!DOCTYPE name PUBLIC "doctypePublic" * "doctypeSystem"> else <!DOCTYPE name SYSTEM "doctypeSystem" >
*/
/** * A visitor that generates codes for the elements in the page.
*/ privateclass GenerateVisitor extends Node.Visitor {
/* * Map containing introspection information on tag handlers: * <key>: tag prefix <value>: Map containing introspection on tag * handlers: <key>: tag short name <value>: introspection info of tag * handler for <prefix:shortName> tag
*/ privatefinal Map<String,Map<String,TagHandlerInfo>> handlerInfos;
privatefinal Map<String,Integer> tagVarNumbers;
private String parent;
privateboolean isSimpleTagParent; // Is parent a SimpleTag?
/** * Returns an attribute value, optionally URL encoded. If the value is a * runtime expression, the result is the expression itself, as a string. * If the result is an EL expression, we insert a call to the * interpreter. If the result is a Named Attribute we insert the * generated variable name. Otherwise the result is a string literal, * quoted and escaped. * * @param attr * An JspAttribute object * @param encode * true if to be URL encoded * @param expectedType * the expected type for an EL evaluation (ignored for * attributes that aren't EL expressions)
*/ private String attributeValue(Node.JspAttribute attr, boolean encode, Class<?> expectedType) {
String v = attr.getValue(); if (attr.isExpression()) { if (encode) { return"org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode(String.valueOf("
+ v + "), request.getCharacterEncoding())";
} return v;
} elseif (attr.isELInterpreterInput()) {
v = elInterpreter.interpreterCall(ctxt, this.isTagFile, v,
expectedType, attr.getEL().getMapName()); if (encode) { return"org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode("
+ v + ", request.getCharacterEncoding())";
} return v;
} elseif (attr.isNamedAttribute()) { return attr.getNamedAttributeNode().getTemporaryVariableName();
} else { if (encode) { return"org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode("
+ quote(v) + ", request.getCharacterEncoding())";
} return quote(v);
}
}
/** * Prints the attribute value specified in the param action, in the form * of name=value string. * * @param n * the parent node for the param action nodes.
*/ privatevoid printParams(Node n, String pageParam, boolean literal) throws JasperException {
class ParamVisitor extends Node.Visitor { private String separator;
String pageParam; if (page.isNamedAttribute()) { // If the page for jsp:include was specified via // jsp:attribute, first generate code to evaluate // that body.
pageParam = generateNamedAttributeValue(page
.getNamedAttributeNode());
} else {
pageParam = attributeValue(page, false, String.class);
}
// If any of the params have their values specified by // jsp:attribute, prepare those values first.
Node jspBody = findJspBody(n); if (jspBody != null) {
prepareParams(jspBody);
} else {
prepareParams(n);
}
/** * Scans through all child nodes of the given parent for <param> * subelements. For each <param> element, if its value is specified via * a Named Attribute (<jsp:attribute>), generate the code to evaluate * those bodies first. * <p> * {@code parent} is assumed to be non-null
*/ privatevoid prepareParams(Node parent) throws JasperException {
Node.Nodes subelements = parent.getBody(); if (subelements != null) { for (int i = 0; i < subelements.size(); i++) {
Node n = subelements.getNode(i); // Validation during parsing ensures n is an instance of // Node.ParamAction
Node.Nodes paramSubElements = n.getBody(); for (int j = 0; (paramSubElements != null)
&& (j < paramSubElements.size()); j++) {
Node m = paramSubElements.getNode(j); if (m instanceof Node.NamedAttribute) {
generateNamedAttributeValue((Node.NamedAttribute) m);
}
}
}
}
}
/** * Finds the <jsp:body> subelement of the given parent node. If not * found, null is returned.
*/ private Node.JspBody findJspBody(Node parent) {
Node.JspBody result = null;
Node.Nodes subelements = parent.getBody(); for (int i = 0; (subelements != null) && (i < subelements.size()); i++) {
Node n = subelements.getNode(i); if (n instanceof Node.JspBody) {
result = (Node.JspBody) n; break;
}
}
out.printil("if (true) {"); // So that javac won't complain about
out.pushIndent(); // codes after "return"
String pageParam; if (page.isNamedAttribute()) { // If the page for jsp:forward was specified via // jsp:attribute, first generate code to evaluate // that body.
pageParam = generateNamedAttributeValue(page.getNamedAttributeNode());
} else {
pageParam = attributeValue(page, false, String.class);
}
// If any of the params have their values specified by // jsp:attribute, prepare those values first.
Node jspBody = findJspBody(n); if (jspBody != null) {
prepareParams(jspBody);
} else {
prepareParams(n);
}
if (beanInfo.checkVariable(name)) { // Bean is defined using useBean, introspect at compile time Class<?> bean = beanInfo.getBeanType(name);
String beanName = bean.getCanonicalName();
Method meth = JspRuntimeLibrary.getReadMethod(bean, property);
String methodName = meth.getName();
out.printil("out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString("
+ "((("
+ beanName
+ ")_jspx_page_context.findAttribute("
+ "\""
+ name + "\"))." + methodName + "())));");
} elseif (!ctxt.getOptions().getStrictGetProperty() || varInfoNames.contains(name)) { // The object is a custom action with an associated // VariableInfo entry for this name. // Get the class name and then introspect at runtime.
out.printil("out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString"
+ "(org.apache.jasper.runtime.JspRuntimeLibrary.handleGetProperty"
+ "(_jspx_page_context.findAttribute(\""
+ name
+ "\"), \""
+ property
+ "\")));");
} else { thrownew JasperException(Localizer.getMessage("jsp.error.invalid.name", n.getStart(), name));
}
if ("*".equals(property)) {
out.printil("org.apache.jasper.runtime.JspRuntimeLibrary.introspect("
+ "_jspx_page_context.findAttribute("
+ "\""
+ name + "\"), request);");
} elseif (value == null) { if (param == null)
{
param = property; // default to same as property
}
out.printil("org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper("
+ "_jspx_page_context.findAttribute(\""
+ name
+ "\"), \""
+ property
+ "\", request.getParameter(\""
+ param
+ "\"), "
+ "request, \""
+ param
+ "\", false);");
} elseif (value.isExpression()) {
out.printil("org.apache.jasper.runtime.JspRuntimeLibrary.handleSetProperty("
+ "_jspx_page_context.findAttribute(\""
+ name
+ "\"), \"" + property + "\",");
out.print(attributeValue(value, false, null));
out.println(");");
} elseif (value.isELInterpreterInput()) { // We've got to resolve the very call to the interpreter // at runtime since we don't know what type to expect // in the general case; we thus can't hard-wire the call // into the generated code. (XXX We could, however, // optimize the case where the bean is exposed with // <jsp:useBean>, much as the code here does for // getProperty.)
// The following holds true for the arguments passed to // JspRuntimeLibrary.handleSetPropertyExpression(): // - 'pageContext' is a VariableResolver. // - 'this' (either the generated Servlet or the generated tag // handler for Tag files) is a FunctionMapper.
out.printil("org.apache.jasper.runtime.JspRuntimeLibrary.handleSetPropertyExpression("
+ "_jspx_page_context.findAttribute(\""
+ name
+ "\"), \""
+ property
+ "\", "
+ quote(value.getValue())
+ ", "
+ "_jspx_page_context, "
+ value.getEL().getMapName() + ");");
} elseif (value.isNamedAttribute()) { // If the value for setProperty was specified via // jsp:attribute, first generate code to evaluate // that body.
String valueVarName = generateNamedAttributeValue(value
.getNamedAttributeNode());
out.printil("org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper("
+ "_jspx_page_context.findAttribute(\""
+ name
+ "\"), \""
+ property
+ "\", "
+ valueVarName
+ ", null, null, false);");
} else {
out.printin("org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper("
+ "_jspx_page_context.findAttribute(\""
+ name
+ "\"), \"" + property + "\", ");
out.print(attributeValue(value, false, null));
out.println(", null, null, false);");
}
String name = n.getTextAttribute("id");
String scope = n.getTextAttribute("scope");
String klass = n.getTextAttribute("class");
String type = n.getTextAttribute("type");
Node.JspAttribute beanName = n.getBeanName();
// If "class" is specified, try an instantiation at compile time boolean generateNew = false;
String canonicalName = null; // Canonical name for klass if (klass != null) { try { Class<?> bean = ctxt.getClassLoader().loadClass(klass); if (klass.indexOf('$') >= 0) { // Obtain the canonical type name
canonicalName = bean.getCanonicalName();
} else {
canonicalName = klass;
} // Check that there is a 0 arg constructor
Constructor<?> constructor = bean.getConstructor(newClass[] {}); // Check the bean is public, not an interface, not abstract // and in an exported module int modifiers = bean.getModifiers(); // No need to test for being an interface here as the // getConstructor() call above will have already failed for // any interfaces. if (!Modifier.isPublic(modifiers) ||
Modifier.isAbstract(modifiers) ||
!constructor.canAccess(null) ) { thrownew JasperException(Localizer.getMessage("jsp.error.invalid.bean",
Integer.valueOf(modifiers)));
} // At compile time, we have determined that the bean class // exists, with a public zero constructor, new() can be // used for bean instantiation.
generateNew = true;
} catch (Exception e) { // Cannot instantiate the specified class, either a // compilation error or a runtime error will be raised, // depending on a compiler flag. if (ctxt.getOptions()
.getErrorOnUseBeanInvalidClassAttribute()) {
err.jspError(n, "jsp.error.invalid.bean", klass);
} if (canonicalName == null) { // Doing our best here to get a canonical name // from the binary name, should work 99.99% of time.
canonicalName = klass.replace('$', '.');
}
} if (type == null) { // if type is unspecified, use "class" as type of bean
type = canonicalName;
}
}
// JSP.5.1, Semantics, para 1 - lock not required for request or // page scope
String scopename = "jakarta.servlet.jsp.PageContext.PAGE_SCOPE"; // Default to page
String lock = null;
// Create bean /* * Check if bean is already there
*/
out.printin("if (");
out.print(name);
out.println(" == null){");
out.pushIndent(); if (klass == null && beanName == null) { /* * If both class name and beanName is not specified, the bean * must be found locally, otherwise it's an error
*/
out.printin("throw new java.lang.InstantiationException(\"bean ");
out.print(name);
out.println(" not found within scope\");");
} else { /* * Instantiate the bean if it is not in the specified scope.
*/ if (!generateNew) {
String binaryName; if (beanName != null) { if (beanName.isNamedAttribute()) { // If the value for beanName was specified via // jsp:attribute, first generate code to evaluate // that body.
binaryName = generateNamedAttributeValue(beanName
.getNamedAttributeNode());
} else {
binaryName = attributeValue(beanName, false, String.class);
}
} else { // Implies klass is not null
binaryName = quote(klass);
}
out.printil("try {");
out.pushIndent();
out.printin(name);
out.print(" = (");
out.print(type);
out.print(") java.beans.Beans.instantiate(");
out.print("this.getClass().getClassLoader(), ");
out.print(binaryName);
out.println(");");
out.popIndent(); /* * Note: Beans.instantiate throws ClassNotFoundException if * the bean class is abstract.
*/
out.printil("} catch (java.lang.ClassNotFoundException exc) {");
out.pushIndent();
out.printil("throw new InstantiationException(exc.getMessage());");
out.popIndent();
out.printil("} catch (java.lang.Exception exc) {");
out.pushIndent();
out.printin("throw new jakarta.servlet.ServletException(");
out.print("\"Cannot create bean of class \" + ");
out.print(binaryName);
out.println(", exc);");
out.popIndent();
out.printil("}"); // close of try
} else { // Implies klass is not null // Generate codes to instantiate the bean class
out.printin(name);
out.print(" = new ");
out.print(canonicalName);
out.println("();");
} /* * Set attribute for bean in the specified scope
*/
out.printin("_jspx_page_context.setAttribute(");
out.print(quote(name));
out.print(", ");
out.print(name);
out.print(", ");
out.print(scopename);
out.println(");");
// Only visit the body when bean is instantiated
visitBody(n);
}
out.popIndent();
out.printil("}");
// End of lock block if (lock != null) {
out.popIndent();
out.printil("}");
}
// If the tag contains no scripting element, generate its codes // to a method.
ServletWriter outSave = null;
Node.ChildInfo ci = n.getChildInfo(); if (ci.isScriptless() && !ci.hasScriptingVars()) { // The tag handler and its body code can reside in a separate // method if it is scriptless and does not have any scripting // variable defined.
String tagMethod = "_jspx_meth_" + baseVar;
// Generate a call to this method
out.printin("if (");
out.print(tagMethod);
out.print("("); if (parent != null) {
out.print(parent);
out.print(", ");
}
out.print("_jspx_page_context"); if (pushBodyCountVar != null) {
out.print(", ");
out.print(pushBodyCountVar);
}
out.println("))");
out.pushIndent();
out.printil((methodNesting > 0) ? "return true;" : "return;");
out.popIndent();
// Set up new buffer for the method
outSave = out; /* * For fragments, their bodies will be generated in fragment * helper classes, and the Java line adjustments will be done * there, hence they are set to null here to avoid double * adjustments.
*/
GenBuffer genBuffer = new GenBuffer(n,
n.implementsSimpleTag() ? null : n.getBody());
methodsBuffered.add(genBuffer);
out = genBuffer.getOut();
// Initialize local variables used in this method. if (!isTagFile) {
out.printil("jakarta.servlet.jsp.PageContext pageContext = _jspx_page_context;");
} // Only need to define out if the tag has a non-empty body, // implements TryCatchFinally or uses // <jsp:attribute>...</jsp:attribute> nodes if (!n.hasEmptyBody() || n.implementsTryCatchFinally() || n.getNamedAttributeNodes().size() > 0) {
out.printil("jakarta.servlet.jsp.JspWriter out = _jspx_page_context.getOut();");
}
generateLocalVariables(out, n);
}
// Add the named objects to the list of 'introduced' names to enable // a later test as per JSP.5.3
VariableInfo[] infos = n.getVariableInfos(); // The Validator always calls setTagData() which ensures infos is // non-null if (infos.length > 0) { for (VariableInfo info : infos) { // A null variable name will trigger multiple compilation // failures so assume non-null here
pageInfo.getVarInfoNames().add(info.getVarName());
}
}
TagVariableInfo[] tagInfos = n.getTagVariableInfos(); // The way Tomcat constructs the TagInfo, getTagVariableInfos() // will never return null. if (tagInfos.length > 0) { for (TagVariableInfo tagInfo : tagInfos) { // tagInfo is always non-null
String name = tagInfo.getNameGiven(); if (name == null) {
String nameFromAttribute =
tagInfo.getNameFromAttribute();
name = n.getAttributeValue(nameFromAttribute);
}
pageInfo.getVarInfoNames().add(name);
}
}
if (n.implementsSimpleTag()) {
generateCustomDoTag(n, handlerInfo, tagHandlerVar);
} else { /* * Classic tag handler: Generate code for start element, body, * and end element
*/
generateCustomStart(n, handlerInfo, tagHandlerVar, tagEvalVar,
tagPushBodyCountVar);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.