![]() |
![]() |
selenium-server-standalone-2.42.2e { out.println("null);"); } } else if (parent != null) { out.printin(tagHandlerVar); out.print(".setParent("); out.print(parent); out.println(");"); } Node.JspAttribute[] attrs = n.getJspAttributes(); for (int i = 0; (attrs != null) && (i < attrs.length); i++) { String attrValue = evaluateAttribute(handlerInfo, attrs[i], n, tagHandlerVar); if (attrs[i].isDynamic()) { out.printin(tagHandlerVar); out.print("."); out.print("setDynamicAttribute("); String uri = attrs[i].getURI(); if (("".equals(uri)) || (uri == null)) { out.print("null"); } else { out.print("\"" + attrs[i].getURI() + "\""); } out.print(", \""); out.print(attrs[i].getLocalName()); out.print("\", "); out.print(attrValue); out.println(");"); } else { out.printin(tagHandlerVar); out.print("."); out.print(handlerInfo.getSetterMethod(attrs[i].getLocalName()).getName()); out.print("("); out.print(attrValue); out.println(");"); } } } private String convertString(Class c, String s, String attrName, Class propEditorClass, boolean isNamedAttribute) throws JasperException { String quoted = s; if (!isNamedAttribute) { quoted = Generator.quote(s); } if (propEditorClass != null) { String className = JspUtil.getCanonicalName(c); return "(" + className + ")org.apache.jasper.runtime.JspRuntimeLibrary.getValueFromBeanInfoPropertyEditor(" + className + ".class, \"" + attrName + "\", " + quoted + ", " + JspUtil.getCanonicalName(propEditorClass) + ".class)"; } if (c == (Generator.class$java$lang$String == null ? (Generator.class$java$lang$String = Generator.class$("java.lang.String")) : Generator.class$java$lang$String)) { return quoted; } if (c == Boolean.TYPE) { return JspUtil.coerceToPrimitiveBoolean(s, isNamedAttribute); } if (c == (Generator.class$java$lang$Boolean == null ? (Generator.class$java$lang$Boolean = Generator.class$("java.lang.Boolean")) : Generator.class$java$lang$Boolean)) { return JspUtil.coerceToBoolean(s, isNamedAttribute); } if (c == Byte.TYPE) { return JspUtil.coerceToPrimitiveByte(s, isNamedAttribute); } if (c == (Generator.class$java$lang$Byte == null ? (Generator.class$java$lang$Byte = Generator.class$("java.lang.Byte")) : Generator.class$java$lang$Byte)) { return JspUtil.coerceToByte(s, isNamedAttribute); } if (c == Character.TYPE) { return JspUtil.coerceToChar(s, isNamedAttribute); } if (c == (Generator.class$java$lang$Character == null ? (Generator.class$java$lang$Character = Generator.class$("java.lang.Character")) : Generator.class$java$lang$Character)) { return JspUtil.coerceToCharacter(s, isNamedAttribute); } if (c == Double.TYPE) { return JspUtil.coerceToPrimitiveDouble(s, isNamedAttribute); } if (c == (Generator.class$java$lang$Double == null ? (Generator.class$java$lang$Double = Generator.class$("java.lang.Double")) : Generator.class$java$lang$Double)) { return JspUtil.coerceToDouble(s, isNamedAttribute); } if (c == Float.TYPE) { return JspUtil.coerceToPrimitiveFloat(s, isNamedAttribute); } if (c == (Generator.class$java$lang$Float == null ? (Generator.class$java$lang$Float = Generator.class$("java.lang.Float")) : Generator.class$java$lang$Float)) { return JspUtil.coerceToFloat(s, isNamedAttribute); } if (c == Integer.TYPE) { return JspUtil.coerceToInt(s, isNamedAttribute); } if (c == (Generator.class$java$lang$Integer == null ? (Generator.class$java$lang$Integer = Generator.class$("java.lang.Integer")) : Generator.class$java$lang$Integer)) { return JspUtil.coerceToInteger(s, isNamedAttribute); } if (c == Short.TYPE) { return JspUtil.coerceToPrimitiveShort(s, isNamedAttribute); } if (c == (Generator.class$java$lang$Short == null ? (Generator.class$java$lang$Short = Generator.class$("java.lang.Short")) : Generator.class$java$lang$Short)) { return JspUtil.coerceToShort(s, isNamedAttribute); } if (c == Long.TYPE) { return JspUtil.coerceToPrimitiveLong(s, isNamedAttribute); } if (c == (Generator.class$java$lang$Long == null ? (Generator.class$java$lang$Long = Generator.class$("java.lang.Long")) : Generator.class$java$lang$Long)) { return JspUtil.coerceToLong(s, isNamedAttribute); } if (c == (Generator.class$java$lang$Object == null ? (Generator.class$java$lang$Object = Generator.class$("java.lang.Object")) : Generator.class$java$lang$Object)) { return "new String(" + quoted + ")"; } String className = JspUtil.getCanonicalName(c); return "(" + className + ")org.apache.jasper.runtime.JspRuntimeLibrary.getValueFromPropertyEditorManager(" + className + ".class, \"" + attrName + "\", " + quoted + ")"; } private String getScopeConstant(String scope) { String scopeName = "PageContext.PAGE_SCOPE"; if ("request".equals(scope)) { scopeName = "PageContext.REQUEST_SCOPE"; } else if ("session".equals(scope)) { scopeName = "PageContext.SESSION_SCOPE"; } else if ("application".equals(scope)) { scopeName = "PageContext.APPLICATION_SCOPE"; } return scopeName; } private void generateJspFragment(Node n, String tagHandlerVar) throws JasperException { Generator.FragmentHelperClass.Fragment fragment = fragmentHelperClass.openFragment(n, tagHandlerVar, methodNesting); ServletWriter outSave = out; out = fragment.getGenBuffer().getOut(); String tmpParent = parent; parent = "_jspx_parent"; boolean isSimpleTagParentSave = isSimpleTagParent; isSimpleTagParent = true; boolean tmpIsFragment = isFragment; isFragment = true; String pushBodyCountVarSave = pushBodyCountVar; if (pushBodyCountVar != null) { pushBodyCountVar = "_jspx_push_body_count"; } visitBody(n); out = outSave; parent = tmpParent; isSimpleTagParent = isSimpleTagParentSave; isFragment = tmpIsFragment; pushBodyCountVar = pushBodyCountVarSave; fragmentHelperClass.closeFragment(fragment, methodNesting); out.print("new " + fragmentHelperClass.getClassName() + "( " + fragment.getId() + ", _jspx_page_context, " + tagHandlerVar + ", " + pushBodyCountVar + ")"); } public String generateNamedAttributeValue(Node.NamedAttribute n) throws JasperException { String varName = n.getTemporaryVariableName(); Node.Nodes body = n.getBody(); if (body != null) { boolean templateTextOptimization = false; if (body.size() == 1) { Node bodyElement = body.getNode(0); if ((bodyElement instanceof Node.TemplateText)) { templateTextOptimization = true; out.printil("String " + varName + " = " + Generator.quote(new String(((Node.TemplateText)bodyElement).getText())) + ";"); } } if (!templateTextOptimization) { out.printil("out = _jspx_page_context.pushBody();"); visitBody(n); out.printil("String " + varName + " = " + "((javax.servlet.jsp.tagext.BodyContent)" + "out).getString();"); out.printil("out = _jspx_page_context.popBody();"); } } else { out.printil("String " + varName + " = \"\";"); } return varName; } public String generateNamedAttributeJspFragment(Node.NamedAttribute n, String tagHandlerVar) throws JasperException { String varName = n.getTemporaryVariableName(); out.printin("javax.servlet.jsp.tagext.JspFragment " + varName + " = "); generateJspFragment(n, tagHandlerVar); out.println(";"); return varName; } } /* Location: * Qualified Name: org.apache.jasper.compiler.Generator.GenerateVisitor * Java Class Version: 1.4 (48.0) * JD-Core Version: 0.7.1 */ package org.apache.jasper.compiler; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import java.util.Hashtable; import org.apache.jasper.JasperException; class Generator$TagHandlerInfo { private Hashtable methodMaps; private Hashtable propertyEditorMaps; private Class tagHandlerClass; Generator$TagHandlerInfo(Node n, Class tagHandlerClass, ErrorDispatcher err) throws JasperException { this.tagHandlerClass = tagHandlerClass; methodMaps = new Hashtable(); propertyEditorMaps = new Hashtable(); try { BeanInfo tagClassInfo = Introspector.getBeanInfo(tagHandlerClass); PropertyDescriptor[] pd = tagClassInfo.getPropertyDescriptors(); for (int i = 0; i < pd.length; i++) { if (pd[i].getWriteMethod() != null) { methodMaps.put(pd[i].getName(), pd[i].getWriteMethod()); } if (pd[i].getPropertyEditorClass() != null) { propertyEditorMaps.put(pd[i].getName(), pd[i].getPropertyEditorClass()); } } } catch (IntrospectionException ie) { err.jspError(n, "jsp.error.introspect.taghandler", tagHandlerClass.getName(), ie); } } public Method getSetterMethod(String attrName) { return (Method)methodMaps.get(attrName); } public Class getPropertyEditorClass(String attrName) { return (Class)propertyEditorMaps.get(attrName); } public Class getTagHandlerClass() { return tagHandlerClass; } } /* Location: * Qualified Name: org.apache.jasper.compiler.Generator.TagHandlerInfo * Java Class Version: 1.4 (48.0) * JD-Core Version: 0.7.1 */ package org.apache.jasper.compiler; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.io.CharArrayWriter; import java.io.PrintWriter; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Vector; import javax.servlet.jsp.tagext.TagAttributeInfo; import javax.servlet.jsp.tagext.TagData; import javax.servlet.jsp.tagext.TagInfo; import javax.servlet.jsp.tagext.TagVariableInfo; import javax.servlet.jsp.tagext.VariableInfo; import org.apache.jasper.JasperException; import org.apache.jasper.JspCompilationContext; import org.apache.jasper.Options; import org.apache.jasper.runtime.JspRuntimeLibrary; import org.xml.sax.Attributes; class Generator { private static final Class[] OBJECT_CLASS = { Object.class }; private ServletWriter out; private ArrayList methodsBuffered; private FragmentHelperClass fragmentHelperClass; private ErrorDispatcher err; private BeanRepository beanInfo; private JspCompilationContext ctxt; private boolean isPoolingEnabled; private boolean breakAtLF; private PageInfo pageInfo; private Vector tagHandlerPoolNames; private GenBuffer charArrayBuffer; static String quote(String s) { if (s == null) { return "null"; } return '"' + escape(s) + '"'; } static String escape(String s) { if (s == null) { return ""; } StringBuffer b = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == '"') { b.append('\\').append('"'); } else if (c == '\\') { b.append('\\').append('\\'); } else if (c == '\n') { b.append('\\').append('n'); } else if (c == '\r') { b.append('\\').append('r'); } else { b.append(c); } } return b.toString(); } static String quote(char c) { StringBuffer b = new StringBuffer(); b.append('\''); if (c == '\'') { b.append('\\').append('\''); } else if (c == '\\') { b.append('\\').append('\\'); } else if (c == '\n') { b.append('\\').append('n'); } else if (c == '\r') { b.append('\\').append('r'); } else { b.append(c); } b.append('\''); return b.toString(); } private void generateDeclarations(Node.Nodes page) throws JasperException { out.println(); page.visit(new Node.Visitor() { private boolean getServletInfoGenerated = false; public void visit(Node.PageDirective n) throws JasperException { if (getServletInfoGenerated) { return; } String info = n.getAttributeValue("info"); if (info == null) { return; } getServletInfoGenerated = true; out.printil("public String getServletInfo() {"); out.pushIndent(); out.printin("return "); out.print(Generator.quote(info)); out.println(";"); out.popIndent(); out.printil("}"); out.println(); } public void visit(Node.Declaration n) throws JasperException { n.setBeginJavaLine(out.getJavaLine()); out.printMultiLn(new String(n.getText())); out.println(); n.setEndJavaLine(out.getJavaLine()); } public void visit(Node.CustomTag n) throws JasperException { if (n.useTagPlugin()) { if (n.getAtSTag() != null) { n.getAtSTag().visit(this); } visitBody(n); if (n.getAtETag() != null) { n.getAtETag().visit(this); } } else { visitBody(n); } } }); } private void compileTagHandlerPoolList(Node.Nodes page) throws JasperException { page.visit(new Node.Visitor() { private Vector names; public void visit(Node.CustomTag n) throws JasperException { if (!n.implementsSimpleTag()) { String name = createTagHandlerPoolName(n.getPrefix(), n.getLocalName(), n.getAttributes(), n.hasEmptyBody()); n.setTagHandlerPoolName(name); if (!names.contains(name)) { names.add(name); } } visitBody(n); } private String createTagHandlerPoolName(String prefix, String shortName, Attributes attrs, boolean hasEmptyBody) { String poolName = null; poolName = "_jspx_tagPool_" + prefix + "_" + shortName; if (attrs != null) { String[] attrNames = new String[attrs.getLength()]; for (int i = 0; i < attrNames.length; i++) { attrNames[i] = attrs.getQName(i); } Arrays.sort(attrNames, Collections.reverseOrder()); for (int i = 0; i < attrNames.length; i++) { poolName = poolName + "_" + attrNames[i]; } } if (hasEmptyBody) { poolName = poolName + "_nobody"; } return JspUtil.makeXmlJavaIdentifier(poolName); } }); } private void declareTemporaryScriptingVars(Node.Nodes page) throws JasperException { page.visit(new Node.Visitor() { private Vector vars; public void visit(Node.CustomTag n) throws JasperException { if (n.getCustomNestingLevel() > 0) { TagVariableInfo[] tagVarInfos = n.getTagVariableInfos(); VariableInfo[] varInfos = n.getVariableInfos(); if (varInfos.length > 0) { for (int i = 0; i < varInfos.length; i++) { String varName = varInfos[i].getVarName(); String tmpVarName = "_jspx_" + varName + "_" + n.getCustomNestingLevel(); if (!vars.contains(tmpVarName)) { vars.add(tmpVarName); out.printin(varInfos[i].getClassName()); out.print(" "); out.print(tmpVarName); out.print(" = "); out.print(null); out.println(";"); } } } else { for (int i = 0; i < tagVarInfos.length; i++) { String varName = tagVarInfos[i].getNameGiven(); if (varName == null) { varName = n.getTagData().getAttributeString(tagVarInfos[i].getNameFromAttribute()); } else { if (tagVarInfos[i].getNameFromAttribute() != null) { continue; } } String tmpVarName = "_jspx_" + varName + "_" + n.getCustomNestingLevel(); if (!vars.contains(tmpVarName)) { vars.add(tmpVarName); out.printin(tagVarInfos[i].getClassName()); out.print(" "); out.print(tmpVarName); out.print(" = "); out.print(null); out.println(";"); } } } } visitBody(n); } }); } private void generateInit() { if (ctxt.isTagFile()) { out.printil("private void _jspInit(ServletConfig config) {"); } else { out.printil("public void _jspInit() {"); } out.pushIndent(); for (int i = 0; i < tagHandlerPoolNames.size(); i++) { out.printin((String)tagHandlerPoolNames.elementAt(i)); out.print(" = org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool("); if (ctxt.isTagFile()) { out.print("config"); } else { out.print("getServletConfig()"); } out.println(");"); } out.popIndent(); out.printil("}"); out.println(); } private void generateDestroy() { out.printil("public void _jspDestroy() {"); out.pushIndent(); for (int i = 0; i < tagHandlerPoolNames.size(); i++) { out.printin((String)tagHandlerPoolNames.elementAt(i)); out.println(".release();"); } out.popIndent(); out.printil("}"); out.println(); } private void genPreamblePackage(String packageName) throws JasperException { if ((!"".equals(packageName)) && (packageName != null)) { out.printil("package " + packageName + ";"); out.println(); } } private void genPreambleImports() throws JasperException { Iterator iter = pageInfo.getImports().iterator(); while (iter.hasNext()) { out.printin("import "); out.print((String)iter.next()); out.println(";"); } out.println(); } private void genPreambleStaticInitializers() throws JasperException { out.printil("private static java.util.List _jspx_dependants;"); out.println(); List dependants = pageInfo.getDependants(); Iterator iter = dependants.iterator(); if (!dependants.isEmpty()) { out.printil("static {"); out.pushIndent(); out.printin("_jspx_dependants = new java.util.ArrayList("); out.print("" + dependants.size()); out.println(");"); while (iter.hasNext()) { out.printin("_jspx_dependants.add(\""); out.print((String)iter.next()); out.println("\");"); } out.popIndent(); out.printil("}"); out.println(); } } private void genPreambleClassVariableDeclarations(String className) throws JasperException { if ((isPoolingEnabled) && (!tagHandlerPoolNames.isEmpty())) { for (int i = 0; i < tagHandlerPoolNames.size(); i++) { out.printil("private org.apache.jasper.runtime.TagHandlerPool " + tagHandlerPoolNames.elementAt(i) + ";"); } out.println(); } } private void genPreambleMethods() throws JasperException { out.printil("public Object getDependants() {"); out.pushIndent(); out.printil("return _jspx_dependants;"); out.popIndent(); out.printil("}"); out.println(); if ((isPoolingEnabled) && (!tagHandlerPoolNames.isEmpty())) { generateInit(); generateDestroy(); } } private void generatePreamble(Node.Nodes page) throws JasperException { String servletPackageName = ctxt.getServletPackageName(); String servletClassName = ctxt.getServletClassName(); String serviceMethodName = "_jspService"; genPreamblePackage(servletPackageName); genPreambleImports(); out.printin("public final class "); out.print(servletClassName); out.print(" extends "); out.println(pageInfo.getExtends()); out.printin(" implements org.apache.jasper.runtime.JspSourceDependent"); if (!pageInfo.isThreadSafe()) { out.println(","); out.printin(" SingleThreadModel"); } out.println(" {"); out.pushIndent(); generateDeclarations(page); genPreambleStaticInitializers(); genPreambleClassVariableDeclarations(servletClassName); genPreambleMethods(); out.printin("public void "); out.print(serviceMethodName); out.println("(HttpServletRequest request, HttpServletResponse response)"); out.println(" throws java.io.IOException, ServletException {"); out.pushIndent(); out.println(); out.printil("JspFactory _jspxFactory = null;"); out.printil("PageContext pageContext = null;"); if (pageInfo.isSession()) { out.printil("HttpSession session = null;"); } if (pageInfo.isErrorPage()) { out.printil("Throwable exception = org.apache.jasper.runtime.JspRuntimeLibrary.getThrowable(request);"); out.printil("if (exception != null) {"); out.pushIndent(); out.printil("response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);"); out.popIndent(); out.printil("}"); } out.printil("ServletContext application = null;"); out.printil("ServletConfig config = null;"); out.printil("JspWriter out = null;"); out.printil("Object page = this;"); out.printil("JspWriter _jspx_out = null;"); out.printil("PageContext _jspx_page_context = null;"); out.println(); declareTemporaryScriptingVars(page); out.println(); out.printil("try {"); out.pushIndent(); out.printil("_jspxFactory = JspFactory.getDefaultFactory();"); out.printin("response.setContentType("); out.print(quote(pageInfo.getContentType())); out.println(");"); if (ctxt.getOptions().isXpoweredBy()) { out.printil("response.addHeader(\"X-Powered-By\", \"JSP/2.0\");"); } out.printil("pageContext = _jspxFactory.getPageContext(this, request, response,"); out.printin("\t\t\t"); out.print(quote(pageInfo.getErrorPage())); out.print(", " + pageInfo.isSession()); out.print(", " + pageInfo.getBuffer()); out.print(", " + pageInfo.isAutoFlush()); out.println(");"); out.printil("_jspx_page_context = pageContext;"); out.printil("application = pageContext.getServletContext();"); out.printil("config = pageContext.getServletConfig();"); if (pageInfo.isSession()) { out.printil("session = pageContext.getSession();"); } out.printil("out = pageContext.getOut();"); out.printil("_jspx_out = out;"); out.println(); } private void generateXmlProlog(Node.Nodes page) { 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\");"); } String doctypeName = pageInfo.getDoctypeName(); if (doctypeName != null) { String doctypePublic = pageInfo.getDoctypePublic(); String doctypeSystem = pageInfo.getDoctypeSystem(); out.printin("out.write(\"<!DOCTYPE "); out.print(doctypeName); if (doctypePublic == null) { out.print(" SYSTEM \\\""); } else { out.print(" PUBLIC \\\""); out.print(doctypePublic); out.print("\\\" \\\""); } out.print(doctypeSystem); out.println("\\\">\\n\");"); } } private void generateConstructor(String className) { out.printil("public " + className + "() {"); out.printil("}"); out.println(); } class GenerateVisitor extends Node.Visitor { private Hashtable handlerInfos; private Hashtable tagVarNumbers; private String parent; private boolean isSimpleTagParent; private String pushBodyCountVar; private String simpleTagHandlerVar; private boolean isSimpleTagHandler; private boolean isFragment; private boolean isTagFile; private ServletWriter out; private ArrayList methodsBuffered; private Generator.FragmentHelperClass fragmentHelperClass; private int methodNesting; private TagInfo tagInfo; private ClassLoader loader; private int charArrayCount; private HashMap textMap; private static final String SINGLE_QUOTE = "'"; private static final String DOUBLE_QUOTE = "\\\""; public GenerateVisitor(boolean isTagFile, ServletWriter out, ArrayList methodsBuffered, Generator.FragmentHelperClass fragmentHelperClass, ClassLoader loader, TagInfo tagInfo) { this.isTagFile = isTagFile; this.out = out; this.methodsBuffered = methodsBuffered; this.fragmentHelperClass = fragmentHelperClass; this.loader = loader; this.tagInfo = tagInfo; methodNesting = 0; handlerInfos = new Hashtable(); tagVarNumbers = new Hashtable(); textMap = new HashMap(); } private String attributeValue(Node.JspAttribute attr, boolean encode, Class expectedType) { String v = attr.getValue(); if ((!attr.isNamedAttribute()) && (v == null)) { return ""; } if (attr.isExpression()) { if (encode) { return "org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode(String.valueOf(" + v + "), request.getCharacterEncoding())"; } return v; } if (attr.isELInterpreterInput()) { boolean replaceESC = v.indexOf('\033') > 0; v = JspUtil.interpreterCall(isTagFile, v, expectedType, attr.getEL().getMapName(), false); if (replaceESC) { v = "(" + v + ").replace(" + "'\\u001b'" + ", '$')"; } if (encode) { return "org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode(" + v + ", request.getCharacterEncoding())"; } return v; } if (attr.isNamedAttribute()) { return attr.getNamedAttributeNode().getTemporaryVariableName(); } if (encode) { return "org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode(" + Generator.quote(v) + ", request.getCharacterEncoding())"; } return Generator.quote(v); } private void printParams(Node n, String pageParam, boolean literal) throws JasperException { String sep; String sep; if (literal) { sep = pageParam.indexOf('?') > 0 ? "\"&\"" : "\"?\""; } else { sep = "((" + pageParam + ").indexOf('?')>0? '&': '?')"; } if (n.getBody() != null) { n.getBody().visit(new Generator.1ParamVisitor(this, sep)); } } public void visit(Node.Expression n) throws JasperException { n.setBeginJavaLine(out.getJavaLine()); out.printin("out.print("); out.printMultiLn(n.getText()); out.println(");"); n.setEndJavaLine(out.getJavaLine()); } public void visit(Node.Scriptlet n) throws JasperException { n.setBeginJavaLine(out.getJavaLine()); out.printMultiLn(n.getText()); out.println(); n.setEndJavaLine(out.getJavaLine()); } public void visit(Node.ELExpression n) throws JasperException { n.setBeginJavaLine(out.getJavaLine()); if (!pageInfo.isELIgnored()) { out.printil("out.write(" + JspUtil.interpreterCall(isTagFile, new StringBuffer().append("${").append(new String(n.getText())).append("}").toString(), String.class, n.getEL().getMapName(), false) + ");"); } else { out.printil("out.write(" + Generator.quote(new StringBuffer().append("${").append(new String(n.getText())).append("}").toString()) + ");"); } n.setEndJavaLine(out.getJavaLine()); } public void visit(Node.IncludeAction n) throws JasperException { String flush = n.getTextAttribute("flush"); Node.JspAttribute page = n.getPage(); boolean isFlush = false; if ("true".equals(flush)) { isFlush = true; } n.setBeginJavaLine(out.getJavaLine()); String pageParam; String pageParam; if (page.isNamedAttribute()) { pageParam = generateNamedAttributeValue(page.getNamedAttributeNode()); } else { pageParam = attributeValue(page, false, String.class); } Node jspBody = findJspBody(n); if (jspBody != null) { prepareParams(jspBody); } else { prepareParams(n); } out.printin("org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, " + pageParam); printParams(n, pageParam, page.isLiteral()); out.println(", out, " + isFlush + ");"); n.setEndJavaLine(out.getJavaLine()); } private void prepareParams(Node parent) throws JasperException { if (parent == null) { return; } Node.Nodes subelements = parent.getBody(); if (subelements != null) { for (int i = 0; i < subelements.size(); i++) { Node n = subelements.getNode(i); if ((n instanceof 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); } } } } } } private Node.JspBody findJspBody(Node parent) throws JasperException { 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; } } return result; } public void visit(Node.ForwardAction n) throws JasperException { Node.JspAttribute page = n.getPage(); n.setBeginJavaLine(out.getJavaLine()); out.printil("if (true) {"); out.pushIndent(); String pageParam; String pageParam; if (page.isNamedAttribute()) { pageParam = generateNamedAttributeValue(page.getNamedAttributeNode()); } else { pageParam = attributeValue(page, false, String.class); } Node jspBody = findJspBody(n); if (jspBody != null) { prepareParams(jspBody); } else { prepareParams(n); } out.printin("_jspx_page_context.forward("); out.print(pageParam); printParams(n, pageParam, page.isLiteral()); out.println(");"); if ((isTagFile) || (isFragment)) { out.printil("throw new SkipPageException();"); } else { out.printil(methodNesting > 0 ? "return true;" : "return;"); } out.popIndent(); out.printil("}"); n.setEndJavaLine(out.getJavaLine()); } public void visit(Node.GetProperty n) throws JasperException { String name = n.getTextAttribute("name"); String property = n.getTextAttribute("property"); n.setBeginJavaLine(out.getJavaLine()); if (beanInfo.checkVariable(name)) { Class bean = beanInfo.getBeanType(name); String beanName = JspUtil.getCanonicalName(bean); 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 + "())));"); } else { out.printil("out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString(org.apache.jasper.runtime.JspRuntimeLibrary.handleGetProperty(_jspx_page_context.getAttribute(\"" + name + "\", PageContext.PAGE_SCOPE), \"" + property + "\")));"); } n.setEndJavaLine(out.getJavaLine()); } public void visit(Node.SetProperty n) throws JasperException { String name = n.getTextAttribute("name"); String property = n.getTextAttribute("property"); String param = n.getTextAttribute("param"); Node.JspAttribute value = n.getValue(); n.setBeginJavaLine(out.getJavaLine()); if ("*".equals(property)) { out.printil("org.apache.jasper.runtime.JspRuntimeLibrary.introspect(_jspx_page_context.findAttribute(\"" + name + "\"), request);"); } else if (value == null) { if (param == null) { param = property; } out.printil("org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(_jspx_page_context.findAttribute(\"" + name + "\"), \"" + property + "\", request.getParameter(\"" + param + "\"), " + "request, \"" + param + "\", false);"); } else if (value.isExpression()) { out.printil("org.apache.jasper.runtime.JspRuntimeLibrary.handleSetProperty(_jspx_page_context.findAttribute(\"" + name + "\"), \"" + property + "\","); out.print(attributeValue(value, false, null)); out.println(");"); } else if (value.isELInterpreterInput()) { out.printil("org.apache.jasper.runtime.JspRuntimeLibrary.handleSetPropertyExpression(_jspx_page_context.findAttribute(\"" + name + "\"), \"" + property + "\", " + Generator.quote(value.getValue()) + ", " + "_jspx_page_context, " + value.getEL().getMapName() + ");"); } else if (value.isNamedAttribute()) { 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);"); } n.setEndJavaLine(out.getJavaLine()); } public void visit(Node.UseBean n) throws JasperException { 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(); boolean generateNew = false; String canonicalName = null; if (klass != null) { try { Class bean = ctxt.getClassLoader().loadClass(klass); if (klass.indexOf('$') >= 0) { canonicalName = JspUtil.getCanonicalName(bean); } else { canonicalName = klass; } int modifiers = bean.getModifiers(); if ((!Modifier.isPublic(modifiers)) || (Modifier.isInterface(modifiers)) || (Modifier.isAbstract(modifiers))) { throw new Exception("Invalid bean class modifier"); } bean.getConstructor(new Class[0]); generateNew = true; } catch (Exception e) { if (ctxt.getOptions().getErrorOnUseBeanInvalidClassAttribute()) { err.jspError(n, "jsp.error.invalid.bean", klass); } if (canonicalName == null) { canonicalName = klass.replace('$', '.'); } } if (type == null) { type = canonicalName; } } String scopename = "PageContext.PAGE_SCOPE"; String lock = "_jspx_page_context"; if ("request".equals(scope)) { scopename = "PageContext.REQUEST_SCOPE"; lock = "request"; } else if ("session".equals(scope)) { scopename = "PageContext.SESSION_SCOPE"; lock = "session"; } else if ("application".equals(scope)) { scopename = "PageContext.APPLICATION_SCOPE"; lock = "application"; } n.setBeginJavaLine(out.getJavaLine()); out.printin(type); out.print(' '); out.print(name); out.println(" = null;"); out.printin("synchronized ("); out.print(lock); out.println(") {"); out.pushIndent(); out.printin(name); out.print(" = ("); out.print(type); out.print(") _jspx_page_context.getAttribute("); out.print(Generator.quote(name)); out.print(", "); out.print(scopename); out.println(");"); out.printin("if ("); out.print(name); out.println(" == null){"); out.pushIndent(); if ((klass == null) && (beanName == null)) { out.printin("throw new java.lang.InstantiationException(\"bean "); out.print(name); out.println(" not found within scope\");"); } else { if (!generateNew) { String binaryName; String binaryName; if (beanName != null) { String binaryName; if (beanName.isNamedAttribute()) { binaryName = generateNamedAttributeValue(beanName.getNamedAttributeNode()); } else { binaryName = attributeValue(beanName, false, String.class); } } else { binaryName = Generator.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(); out.printil("} catch (ClassNotFoundException exc) {"); out.pushIndent(); out.printil("throw new InstantiationException(exc.getMessage());"); out.popIndent(); out.printil("} catch (Exception exc) {"); out.pushIndent(); out.printin("throw new ServletException("); out.print("\"Cannot create bean of class \" + "); out.print(binaryName); out.println(", exc);"); out.popIndent(); out.printil("}"); } else { out.printin(name); out.print(" = new "); out.print(canonicalName); out.println("();"); } out.printin("_jspx_page_context.setAttribute("); out.print(Generator.quote(name)); out.print(", "); out.print(name); out.print(", "); out.print(scopename); out.println(");"); visitBody(n); } out.popIndent(); out.printi Further reading...For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.New!JAR listings
|