This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new 6f627a5e5b Code clean-up - formatting. No functional change. 6f627a5e5b is described below commit 6f627a5e5bd20109c6deb198b1e2cd046c018f5e Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Mar 6 16:14:56 2025 +0000 Code clean-up - formatting. No functional change. --- .../org/apache/jasper/runtime/BodyContentImpl.java | 39 +- java/org/apache/jasper/runtime/ExceptionUtils.java | 10 +- java/org/apache/jasper/runtime/HttpJspBase.java | 12 +- .../jasper/runtime/JspApplicationContextImpl.java | 9 +- .../apache/jasper/runtime/JspContextWrapper.java | 116 +++--- java/org/apache/jasper/runtime/JspFactoryImpl.java | 54 ++- .../apache/jasper/runtime/JspFragmentHelper.java | 18 +- .../apache/jasper/runtime/JspRuntimeLibrary.java | 403 ++++++++------------- .../apache/jasper/runtime/JspSourceDependent.java | 14 +- .../apache/jasper/runtime/JspSourceDirectives.java | 5 +- .../apache/jasper/runtime/JspSourceImports.java | 8 +- java/org/apache/jasper/runtime/JspWriterImpl.java | 74 ++-- .../org/apache/jasper/runtime/PageContextImpl.java | 217 +++++------ .../jasper/runtime/ProtectedFunctionMapper.java | 78 ++-- .../runtime/ServletResponseWrapperInclude.java | 15 +- java/org/apache/jasper/runtime/TagHandlerPool.java | 29 +- 16 files changed, 455 insertions(+), 646 deletions(-) diff --git a/java/org/apache/jasper/runtime/BodyContentImpl.java b/java/org/apache/jasper/runtime/BodyContentImpl.java index 9203008aa5..f837715f2d 100644 --- a/java/org/apache/jasper/runtime/BodyContentImpl.java +++ b/java/org/apache/jasper/runtime/BodyContentImpl.java @@ -27,11 +27,8 @@ import jakarta.servlet.jsp.tagext.BodyContent; import org.apache.jasper.compiler.Localizer; /** - * Write text to a character-output stream, buffering characters so as - * to provide for the efficient writing of single characters, arrays, - * and strings. - * - * Provide support for discarding for the output that has been buffered. + * Write text to a character-output stream, buffering characters so as to provide for the efficient writing of single + * characters, arrays, and strings. Provide support for discarding for the output that has been buffered. * * @author Rajiv Mordani * @author Jan Luehe @@ -52,9 +49,10 @@ public class BodyContentImpl extends BodyContent { /** * Constructor. + * * @param enclosingWriter The wrapped writer - * @param limitBuffer <code>true</code> to discard large buffers - * @param tagBufferSize the buffer size + * @param limitBuffer <code>true</code> to discard large buffers + * @param tagBufferSize the buffer size */ public BodyContentImpl(JspWriter enclosingWriter, boolean limitBuffer, int tagBufferSize) { super(enclosingWriter); @@ -73,7 +71,7 @@ public class BodyContentImpl extends BodyContent { } else { ensureOpen(); if (nextChar >= bufferSize) { - reAllocBuff (1); + reAllocBuff(1); } cb[nextChar++] = (char) c; } @@ -86,19 +84,18 @@ public class BodyContentImpl extends BodyContent { } else { ensureOpen(); - if ((off < 0) || (off > cbuf.length) || (len < 0) || - ((off + len) > cbuf.length) || ((off + len) < 0)) { + if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return; } if (len >= bufferSize - nextChar) { - reAllocBuff (len); + reAllocBuff(len); } System.arraycopy(cbuf, off, cb, nextChar, len); - nextChar+=len; + nextChar += len; } } @@ -264,7 +261,7 @@ public class BodyContentImpl extends BodyContent { } @Override - public void println(double x) throws IOException{ + public void println(double x) throws IOException { print(x); println(); } @@ -327,12 +324,12 @@ public class BodyContentImpl extends BodyContent { @Override public int getRemaining() { - return (writer == null) ? bufferSize-nextChar : 0; + return (writer == null) ? bufferSize - nextChar : 0; } @Override public Reader getReader() { - return (writer == null) ? new CharArrayReader (cb, 0, nextChar) : null; + return (writer == null) ? new CharArrayReader(cb, 0, nextChar) : null; } @Override @@ -361,13 +358,11 @@ public class BodyContentImpl extends BodyContent { } /** - * This method shall "reset" the internal state of a BodyContentImpl, - * releasing all internal references, and preparing it for potential - * reuse by a later invocation of {@link PageContextImpl#pushBody(Writer)}. - * - * <p>Note, that BodyContentImpl instances are usually owned by a - * PageContextImpl instance, and PageContextImpl instances are recycled - * and reused. + * This method shall "reset" the internal state of a BodyContentImpl, releasing all internal references, and + * preparing it for potential reuse by a later invocation of {@link PageContextImpl#pushBody(Writer)}. + * <p> + * Note, that BodyContentImpl instances are usually owned by a PageContextImpl instance, and PageContextImpl + * instances are recycled and reused. * * @see PageContextImpl#release() */ diff --git a/java/org/apache/jasper/runtime/ExceptionUtils.java b/java/org/apache/jasper/runtime/ExceptionUtils.java index 344bce2aa5..dbfde2d278 100644 --- a/java/org/apache/jasper/runtime/ExceptionUtils.java +++ b/java/org/apache/jasper/runtime/ExceptionUtils.java @@ -25,8 +25,8 @@ import java.lang.reflect.InvocationTargetException; public class ExceptionUtils { /** - * Checks whether the supplied Throwable is one that needs to be - * rethrown and swallows all others. + * Checks whether the supplied Throwable is one that needs to be rethrown and swallows all others. + * * @param t the Throwable to check */ public static void handleThrowable(Throwable t) { @@ -44,11 +44,11 @@ public class ExceptionUtils { } /** - * Checks whether the supplied Throwable is an instance of - * <code>InvocationTargetException</code> and returns the throwable that is - * wrapped by it, if there is any. + * Checks whether the supplied Throwable is an instance of <code>InvocationTargetException</code> and returns the + * throwable that is wrapped by it, if there is any. * * @param t the Throwable to check + * * @return <code>t</code> or <code>t.getCause()</code> */ public static Throwable unwrapInvocationTargetException(Throwable t) { diff --git a/java/org/apache/jasper/runtime/HttpJspBase.java b/java/org/apache/jasper/runtime/HttpJspBase.java index 705c6f8ca9..331c5dacf3 100644 --- a/java/org/apache/jasper/runtime/HttpJspBase.java +++ b/java/org/apache/jasper/runtime/HttpJspBase.java @@ -41,9 +41,7 @@ public abstract class HttpJspBase extends HttpServlet implements HttpJspPage { } @Override - public final void init(ServletConfig config) - throws ServletException - { + public final void init(ServletConfig config) throws ServletException { super.init(config); jspInit(); _jspInit(); @@ -62,8 +60,7 @@ public abstract class HttpJspBase extends HttpServlet implements HttpJspPage { @Override public final void service(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException - { + throws ServletException, IOException { _jspService(request, response); } @@ -82,7 +79,6 @@ public abstract class HttpJspBase extends HttpServlet implements HttpJspPage { } @Override - public abstract void _jspService(HttpServletRequest request, - HttpServletResponse response) - throws ServletException, IOException; + public abstract void _jspService(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException; } diff --git a/java/org/apache/jasper/runtime/JspApplicationContextImpl.java b/java/org/apache/jasper/runtime/JspApplicationContextImpl.java index 82aa1abe22..cd90885cee 100644 --- a/java/org/apache/jasper/runtime/JspApplicationContextImpl.java +++ b/java/org/apache/jasper/runtime/JspApplicationContextImpl.java @@ -45,8 +45,7 @@ public class JspApplicationContextImpl implements JspApplicationContext { private static final String KEY = JspApplicationContextImpl.class.getName(); - private final ExpressionFactory expressionFactory = - ExpressionFactory.newInstance(); + private final ExpressionFactory expressionFactory = ExpressionFactory.newInstance(); private final List<ELContextListener> contextListeners = new ArrayList<>(); @@ -72,8 +71,7 @@ public class JspApplicationContextImpl implements JspApplicationContext { if (context == null) { throw new IllegalArgumentException(Localizer.getMessage("jsp.error.nullArgument")); } - JspApplicationContextImpl impl = (JspApplicationContextImpl) context - .getAttribute(KEY); + JspApplicationContextImpl impl = (JspApplicationContextImpl) context.getAttribute(KEY); if (impl == null) { impl = new JspApplicationContextImpl(); context.setAttribute(KEY, impl); @@ -112,8 +110,7 @@ public class JspApplicationContextImpl implements JspApplicationContext { private ELResolver createELResolver() { this.instantiated = true; if (this.resolver == null) { - CompositeELResolver r = new JasperELResolver(this.resolvers, - expressionFactory.getStreamELResolver()); + CompositeELResolver r = new JasperELResolver(this.resolvers, expressionFactory.getStreamELResolver()); this.resolver = r; } return this.resolver; diff --git a/java/org/apache/jasper/runtime/JspContextWrapper.java b/java/org/apache/jasper/runtime/JspContextWrapper.java index 9601d8161c..aace947cec 100644 --- a/java/org/apache/jasper/runtime/JspContextWrapper.java +++ b/java/org/apache/jasper/runtime/JspContextWrapper.java @@ -57,12 +57,9 @@ import jakarta.servlet.jsp.tagext.VariableInfo; import org.apache.jasper.compiler.Localizer; /** - * Implementation of a JSP Context Wrapper. - * - * The JSP Context Wrapper is a JspContext created and maintained by a tag - * handler implementation. It wraps the Invoking JSP Context, that is, the - * JspContext instance passed to the tag handler by the invoking page via - * setJspContext(). + * Implementation of a JSP Context Wrapper. The JSP Context Wrapper is a JspContext created and maintained by a tag + * handler implementation. It wraps the Invoking JSP Context, that is, the JspContext instance passed to the tag handler + * by the invoking page via setJspContext(). * * @author Kin-man Chung * @author Jan Luehe @@ -76,7 +73,7 @@ public class JspContextWrapper extends PageContext implements VariableResolver { // Invoking JSP context private final PageContext invokingJspCtxt; - private final transient HashMap<String, Object> pageAttributes; + private final transient HashMap<String,Object> pageAttributes; // ArrayList of NESTED scripting variables private final ArrayList<String> nestedVars; @@ -89,7 +86,7 @@ public class JspContextWrapper extends PageContext implements VariableResolver { private final Map<String,String> aliases; - private final HashMap<String, Object> originalNestedVars; + private final HashMap<String,Object> originalNestedVars; private ServletContext servletContext = null; @@ -97,13 +94,12 @@ public class JspContextWrapper extends PageContext implements VariableResolver { private final PageContext rootJspCtxt; - public JspContextWrapper(JspTag jspTag, JspContext jspContext, - ArrayList<String> nestedVars, ArrayList<String> atBeginVars, - ArrayList<String> atEndVars, Map<String,String> aliases) { + public JspContextWrapper(JspTag jspTag, JspContext jspContext, ArrayList<String> nestedVars, + ArrayList<String> atBeginVars, ArrayList<String> atEndVars, Map<String,String> aliases) { this.jspTag = jspTag; this.invokingJspCtxt = (PageContext) jspContext; if (jspContext instanceof JspContextWrapper) { - rootJspCtxt = ((JspContextWrapper)jspContext).rootJspCtxt; + rootJspCtxt = ((JspContextWrapper) jspContext).rootJspCtxt; } else { rootJspCtxt = invokingJspCtxt; } @@ -122,8 +118,7 @@ public class JspContextWrapper extends PageContext implements VariableResolver { } @Override - public void initialize(Servlet servlet, ServletRequest request, - ServletResponse response, String errorPageURL, + public void initialize(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush) throws IOException, IllegalStateException, IllegalArgumentException { } @@ -132,8 +127,7 @@ public class JspContextWrapper extends PageContext implements VariableResolver { public Object getAttribute(String name) { if (name == null) { - throw new NullPointerException(Localizer - .getMessage("jsp.error.attribute.null_name")); + throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); } return pageAttributes.get(name); @@ -143,8 +137,7 @@ public class JspContextWrapper extends PageContext implements VariableResolver { public Object getAttribute(String name, int scope) { if (name == null) { - throw new NullPointerException(Localizer - .getMessage("jsp.error.attribute.null_name")); + throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); } if (scope == PAGE_SCOPE) { @@ -158,8 +151,7 @@ public class JspContextWrapper extends PageContext implements VariableResolver { public void setAttribute(String name, Object value) { if (name == null) { - throw new NullPointerException(Localizer - .getMessage("jsp.error.attribute.null_name")); + throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); } if (value != null) { @@ -173,8 +165,7 @@ public class JspContextWrapper extends PageContext implements VariableResolver { public void setAttribute(String name, Object value, int scope) { if (name == null) { - throw new NullPointerException(Localizer - .getMessage("jsp.error.attribute.null_name")); + throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); } if (scope == PAGE_SCOPE) { @@ -192,8 +183,7 @@ public class JspContextWrapper extends PageContext implements VariableResolver { public Object findAttribute(String name) { if (name == null) { - throw new NullPointerException(Localizer - .getMessage("jsp.error.attribute.null_name")); + throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); } Object o = pageAttributes.get(name); @@ -221,8 +211,7 @@ public class JspContextWrapper extends PageContext implements VariableResolver { public void removeAttribute(String name) { if (name == null) { - throw new NullPointerException(Localizer - .getMessage("jsp.error.attribute.null_name")); + throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); } pageAttributes.remove(name); @@ -237,8 +226,7 @@ public class JspContextWrapper extends PageContext implements VariableResolver { public void removeAttribute(String name, int scope) { if (name == null) { - throw new NullPointerException(Localizer - .getMessage("jsp.error.attribute.null_name")); + throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); } if (scope == PAGE_SCOPE) { @@ -252,8 +240,7 @@ public class JspContextWrapper extends PageContext implements VariableResolver { public int getAttributesScope(String name) { if (name == null) { - throw new NullPointerException(Localizer - .getMessage("jsp.error.attribute.null_name")); + throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name")); } if (pageAttributes.get(name) != null) { @@ -321,20 +308,17 @@ public class JspContextWrapper extends PageContext implements VariableResolver { } @Override - public void forward(String relativeUrlPath) throws ServletException, - IOException { + public void forward(String relativeUrlPath) throws ServletException, IOException { invokingJspCtxt.forward(relativeUrlPath); } @Override - public void include(String relativeUrlPath) throws ServletException, - IOException { + public void include(String relativeUrlPath) throws ServletException, IOException { invokingJspCtxt.include(relativeUrlPath); } @Override - public void include(String relativeUrlPath, boolean flush) - throws ServletException, IOException { + public void include(String relativeUrlPath, boolean flush) throws ServletException, IOException { invokingJspCtxt.include(relativeUrlPath, false); } @@ -366,16 +350,14 @@ public class JspContextWrapper extends PageContext implements VariableResolver { } @Override - public void handlePageException(Exception ex) throws IOException, - ServletException { + public void handlePageException(Exception ex) throws IOException, ServletException { // Should never be called since handleException() called with a // Throwable in the generated servlet. handlePageException((Throwable) ex); } @Override - public void handlePageException(Throwable t) throws IOException, - ServletException { + public void handlePageException(Throwable t) throws IOException, ServletException { invokingJspCtxt.handlePageException(t); } @@ -414,31 +396,30 @@ public class JspContextWrapper extends PageContext implements VariableResolver { } /** - * Copies the variables of the given scope from the virtual page scope of - * this JSP context wrapper to the page scope of the invoking JSP context. + * Copies the variables of the given scope from the virtual page scope of this JSP context wrapper to the page scope + * of the invoking JSP context. * - * @param scope - * variable scope (one of NESTED, AT_BEGIN, or AT_END) + * @param scope variable scope (one of NESTED, AT_BEGIN, or AT_END) */ private void copyTagToPageScope(int scope) { Iterator<String> iter = null; switch (scope) { - case VariableInfo.NESTED: - if (nestedVars != null) { - iter = nestedVars.iterator(); - } - break; - case VariableInfo.AT_BEGIN: - if (atBeginVars != null) { - iter = atBeginVars.iterator(); - } - break; - case VariableInfo.AT_END: - if (atEndVars != null) { - iter = atEndVars.iterator(); - } - break; + case VariableInfo.NESTED: + if (nestedVars != null) { + iter = nestedVars.iterator(); + } + break; + case VariableInfo.AT_BEGIN: + if (atBeginVars != null) { + iter = atBeginVars.iterator(); + } + break; + case VariableInfo.AT_END: + if (atEndVars != null) { + iter = atEndVars.iterator(); + } + break; } while ((iter != null) && iter.hasNext()) { @@ -454,8 +435,8 @@ public class JspContextWrapper extends PageContext implements VariableResolver { } /** - * Saves the values of any NESTED variables that are present in the invoking - * JSP context, so they can later be restored. + * Saves the values of any NESTED variables that are present in the invoking JSP context, so they can later be + * restored. */ private void saveNestedVariables() { if (nestedVars != null) { @@ -487,13 +468,12 @@ public class JspContextWrapper extends PageContext implements VariableResolver { } /** - * Checks to see if the given variable name is used as an alias, and if so, - * returns the variable name for which it is used as an alias. + * Checks to see if the given variable name is used as an alias, and if so, returns the variable name for which it + * is used as an alias. + * + * @param varName The variable name to check * - * @param varName - * The variable name to check - * @return The variable name for which varName is used as an alias, or - * varName if it is not being used as an alias + * @return The variable name for which varName is used as an alias, or varName if it is not being used as an alias */ private String findAlias(String varName) { @@ -646,7 +626,7 @@ public class JspContextWrapper extends PageContext implements VariableResolver { } @Override - public void enterLambdaScope(Map<String, Object> arguments) { + public void enterLambdaScope(Map<String,Object> arguments) { wrapped.enterLambdaScope(arguments); } diff --git a/java/org/apache/jasper/runtime/JspFactoryImpl.java b/java/org/apache/jasper/runtime/JspFactoryImpl.java index c84028c010..957ea739a6 100644 --- a/java/org/apache/jasper/runtime/JspFactoryImpl.java +++ b/java/org/apache/jasper/runtime/JspFactoryImpl.java @@ -42,30 +42,26 @@ public class JspFactoryImpl extends JspFactory { private int poolSize = -1; @Override - public PageContext getPageContext(Servlet servlet, ServletRequest request, - ServletResponse response, String errorPageURL, boolean needsSession, - int bufferSize, boolean autoflush) { + public PageContext getPageContext(Servlet servlet, ServletRequest request, ServletResponse response, + String errorPageURL, boolean needsSession, int bufferSize, boolean autoflush) { - if( Constants.IS_SECURITY_ENABLED ) { - PrivilegedGetPageContext dp = new PrivilegedGetPageContext( - this, servlet, request, response, errorPageURL, + if (Constants.IS_SECURITY_ENABLED) { + PrivilegedGetPageContext dp = new PrivilegedGetPageContext(this, servlet, request, response, errorPageURL, needsSession, bufferSize, autoflush); return AccessController.doPrivileged(dp); } else { - return internalGetPageContext(servlet, request, response, - errorPageURL, needsSession, - bufferSize, autoflush); + return internalGetPageContext(servlet, request, response, errorPageURL, needsSession, bufferSize, + autoflush); } } @Override public void releasePageContext(PageContext pc) { - if( pc == null ) { + if (pc == null) { return; } - if( Constants.IS_SECURITY_ENABLED ) { - PrivilegedReleasePageContext dp = new PrivilegedReleasePageContext( - this,pc); + if (Constants.IS_SECURITY_ENABLED) { + PrivilegedReleasePageContext dp = new PrivilegedReleasePageContext(this, pc); AccessController.doPrivileged(dp); } else { internalReleasePageContext(pc); @@ -86,9 +82,8 @@ public class JspFactoryImpl extends JspFactory { this.poolSize = poolSize; } - private PageContext internalGetPageContext(Servlet servlet, ServletRequest request, - ServletResponse response, String errorPageURL, boolean needsSession, - int bufferSize, boolean autoflush) { + private PageContext internalGetPageContext(Servlet servlet, ServletRequest request, ServletResponse response, + String errorPageURL, boolean needsSession, int bufferSize, boolean autoflush) { PageContext pc; if (poolSize > 0) { @@ -106,8 +101,7 @@ public class JspFactoryImpl extends JspFactory { } try { - pc.initialize(servlet, request, response, errorPageURL, - needsSession, bufferSize, autoflush); + pc.initialize(servlet, request, response, errorPageURL, needsSession, bufferSize, autoflush); } catch (IOException ioe) { // Implementation never throws IOE but can't change the signature // since it is part of the JSP API @@ -123,8 +117,7 @@ public class JspFactoryImpl extends JspFactory { } } - private static class PrivilegedGetPageContext - implements PrivilegedAction<PageContext> { + private static class PrivilegedGetPageContext implements PrivilegedAction<PageContext> { private JspFactoryImpl factory; private Servlet servlet; @@ -135,9 +128,9 @@ public class JspFactoryImpl extends JspFactory { private int bufferSize; private boolean autoflush; - PrivilegedGetPageContext(JspFactoryImpl factory, Servlet servlet, - ServletRequest request, ServletResponse response, String errorPageURL, - boolean needsSession, int bufferSize, boolean autoflush) { + PrivilegedGetPageContext(JspFactoryImpl factory, Servlet servlet, ServletRequest request, + ServletResponse response, String errorPageURL, boolean needsSession, int bufferSize, + boolean autoflush) { this.factory = factory; this.servlet = servlet; this.request = request; @@ -150,19 +143,17 @@ public class JspFactoryImpl extends JspFactory { @Override public PageContext run() { - return factory.internalGetPageContext(servlet, request, response, - errorPageURL, needsSession, bufferSize, autoflush); + return factory.internalGetPageContext(servlet, request, response, errorPageURL, needsSession, bufferSize, + autoflush); } } - private static class PrivilegedReleasePageContext - implements PrivilegedAction<Void> { + private static class PrivilegedReleasePageContext implements PrivilegedAction<Void> { private JspFactoryImpl factory; private PageContext pageContext; - PrivilegedReleasePageContext(JspFactoryImpl factory, - PageContext pageContext) { + PrivilegedReleasePageContext(JspFactoryImpl factory, PageContext pageContext) { this.factory = factory; this.pageContext = pageContext; } @@ -174,7 +165,7 @@ public class JspFactoryImpl extends JspFactory { } } - private static final class PageContextPool { + private static final class PageContextPool { private final PageContext[] pool; @@ -203,8 +194,7 @@ public class JspFactoryImpl extends JspFactory { } @Override - public JspApplicationContext getJspApplicationContext( - final ServletContext context) { + public JspApplicationContext getJspApplicationContext(final ServletContext context) { if (Constants.IS_SECURITY_ENABLED) { return AccessController.doPrivileged( (PrivilegedAction<JspApplicationContext>) () -> JspApplicationContextImpl.getInstance(context)); diff --git a/java/org/apache/jasper/runtime/JspFragmentHelper.java b/java/org/apache/jasper/runtime/JspFragmentHelper.java index 41d1752d1d..942e0a10c3 100644 --- a/java/org/apache/jasper/runtime/JspFragmentHelper.java +++ b/java/org/apache/jasper/runtime/JspFragmentHelper.java @@ -22,13 +22,11 @@ import jakarta.servlet.jsp.tagext.JspFragment; import jakarta.servlet.jsp.tagext.JspTag; /** - * Helper class from which all Jsp Fragment helper classes extend. - * This class allows for the emulation of numerous fragments within - * a single class, which in turn reduces the load on the class loader - * since there are potentially many JspFragments in a single page. + * Helper class from which all Jsp Fragment helper classes extend. This class allows for the emulation of numerous + * fragments within a single class, which in turn reduces the load on the class loader since there are potentially many + * JspFragments in a single page. * <p> - * The class also provides various utility methods for JspFragment - * implementations. + * The class also provides various utility methods for JspFragment implementations. * * @author Mark Roth */ @@ -39,13 +37,11 @@ public abstract class JspFragmentHelper extends JspFragment { protected final PageContext _jspx_page_context; protected final JspTag parentTag; - public JspFragmentHelper( int discriminator, JspContext jspContext, - JspTag parentTag ) - { + public JspFragmentHelper(int discriminator, JspContext jspContext, JspTag parentTag) { this.discriminator = discriminator; this.jspContext = jspContext; - if(jspContext instanceof PageContext) { - _jspx_page_context = (PageContext)jspContext; + if (jspContext instanceof PageContext) { + _jspx_page_context = (PageContext) jspContext; } else { _jspx_page_context = null; } diff --git a/java/org/apache/jasper/runtime/JspRuntimeLibrary.java b/java/org/apache/jasper/runtime/JspRuntimeLibrary.java index 19a7599def..16eff406e6 100644 --- a/java/org/apache/jasper/runtime/JspRuntimeLibrary.java +++ b/java/org/apache/jasper/runtime/JspRuntimeLibrary.java @@ -44,8 +44,7 @@ import org.apache.juli.logging.LogFactory; import org.apache.tomcat.InstanceManager; /** - * Bunch of util methods that are used by code generated for useBean, - * getProperty and setProperty. + * Bunch of util methods that are used by code generated for useBean, getProperty and setProperty. * * @author Mandar Raje * @author Shawn Bayern @@ -69,28 +68,24 @@ public class JspRuntimeLibrary { } /** - * Returns the value of the jakarta.servlet.error.exception request - * attribute value, if present, otherwise the value of the - * jakarta.servlet.jsp.jspException request attribute value. + * Returns the value of the jakarta.servlet.error.exception request attribute value, if present, otherwise the value + * of the jakarta.servlet.jsp.jspException request attribute value. This method is called at the beginning of the + * generated servlet code for a JSP error page, when the "exception" implicit scripting language variable is + * initialized. * - * This method is called at the beginning of the generated servlet code - * for a JSP error page, when the "exception" implicit scripting language - * variable is initialized. * @param request The Servlet request + * * @return the throwable in the error attribute if any */ public static Throwable getThrowable(ServletRequest request) { - Throwable error = (Throwable) request.getAttribute( - RequestDispatcher.ERROR_EXCEPTION); + Throwable error = (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); if (error == null) { error = (Throwable) request.getAttribute(PageContext.EXCEPTION); if (error != null) { /* - * The only place that sets JSP_EXCEPTION is - * PageContextImpl.handlePageException(). It really should set - * SERVLET_EXCEPTION, but that would interfere with the - * ErrorReportValve. Therefore, if JSP_EXCEPTION is set, we - * need to set SERVLET_EXCEPTION. + * The only place that sets JSP_EXCEPTION is PageContextImpl.handlePageException(). It really should set + * SERVLET_EXCEPTION, but that would interfere with the ErrorReportValve. Therefore, if JSP_EXCEPTION is + * set, we need to set SERVLET_EXCEPTION. */ request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, error); } @@ -222,10 +217,8 @@ public class JspRuntimeLibrary { } - public static Object convert(String propertyName, String s, Class<?> t, - Class<?> propertyEditorClass) - throws JasperException - { + public static Object convert(String propertyName, String s, Class<?> t, Class<?> propertyEditorClass) + throws JasperException { try { if (s == null) { if (t.equals(Boolean.class) || t.equals(Boolean.TYPE)) { @@ -235,13 +228,12 @@ public class JspRuntimeLibrary { } } if (propertyEditorClass != null) { - return getValueFromBeanInfoPropertyEditor( - t, propertyName, s, propertyEditorClass); + return getValueFromBeanInfoPropertyEditor(t, propertyName, s, propertyEditorClass); } else if (t.equals(Boolean.class) || t.equals(Boolean.TYPE)) { return Boolean.valueOf(s); } else if (t.equals(Byte.class) || t.equals(Byte.TYPE)) { if (s.length() == 0) { - return Byte.valueOf((byte)0); + return Byte.valueOf((byte) 0); } else { return Byte.valueOf(s); } @@ -281,13 +273,12 @@ public class JspRuntimeLibrary { } else { return Short.valueOf(s); } - } else if ( t.equals(String.class) ) { + } else if (t.equals(String.class)) { return s; } else if (t.getName().equals("java.lang.Object")) { return new String(s); } else { - return getValueFromPropertyEditorManager( - t, propertyName, s); + return getValueFromPropertyEditorManager(t, propertyName, s); } } catch (Exception ex) { throw new JasperException(ex); @@ -295,22 +286,18 @@ public class JspRuntimeLibrary { } - public static void introspect(Object bean, ServletRequest request) - throws JasperException - { + public static void introspect(Object bean, ServletRequest request) throws JasperException { Enumeration<String> e = request.getParameterNames(); - while ( e.hasMoreElements() ) { - String name = e.nextElement(); + while (e.hasMoreElements()) { + String name = e.nextElement(); String value = request.getParameter(name); introspecthelper(bean, name, value, request, name, true); } } - public static void introspecthelper(Object bean, String prop, - String value, ServletRequest request, - String param, boolean ignoreMethodNF) - throws JasperException { + public static void introspecthelper(Object bean, String prop, String value, ServletRequest request, String param, + boolean ignoreMethodNF) throws JasperException { Method method = null; Class<?> type = null; Class<?> propertyEditorClass = null; @@ -321,11 +308,9 @@ public class JspRuntimeLibrary { type = method.getParameterTypes()[0]; } } else { - java.beans.BeanInfo info - = java.beans.Introspector.getBeanInfo(bean.getClass()); - if ( info != null ) { - java.beans.PropertyDescriptor pd[] - = info.getPropertyDescriptors(); + java.beans.BeanInfo info = java.beans.Introspector.getBeanInfo(bean.getClass()); + if (info != null) { + java.beans.PropertyDescriptor pd[] = info.getPropertyDescriptors(); for (java.beans.PropertyDescriptor propertyDescriptor : pd) { if (propertyDescriptor.getName().equals(prop)) { method = propertyDescriptor.getWriteMethod(); @@ -339,27 +324,25 @@ public class JspRuntimeLibrary { if (method != null && type != null) { if (type.isArray()) { if (request == null) { - throw new JasperException( - Localizer.getMessage("jsp.error.beans.setproperty.noindexset")); + throw new JasperException(Localizer.getMessage("jsp.error.beans.setproperty.noindexset")); } Class<?> t = type.getComponentType(); String[] values = request.getParameterValues(param); - //XXX Please check. - if(values == null) { + // XXX Please check. + if (values == null) { return; } - if(t.equals(String.class)) { + if (t.equals(String.class)) { method.invoke(bean, new Object[] { values }); } else { - createTypedArray (prop, bean, method, values, t, - propertyEditorClass); + createTypedArray(prop, bean, method, values, t, propertyEditorClass); } } else { - if(value == null || (param != null && value.equals(""))) { + if (value == null || (param != null && value.equals(""))) { return; } Object oval = convert(prop, value, type, propertyEditorClass); - if ( oval != null ) { + if (oval != null) { method.invoke(bean, new Object[] { oval }); } } @@ -372,23 +355,18 @@ public class JspRuntimeLibrary { if (!ignoreMethodNF && (method == null)) { if (type == null) { throw new JasperException( - Localizer.getMessage("jsp.error.beans.noproperty", - prop, - bean.getClass().getName())); + Localizer.getMessage("jsp.error.beans.noproperty", prop, bean.getClass().getName())); } else { - throw new JasperException( - Localizer.getMessage("jsp.error.beans.nomethod.setproperty", - prop, - type.getName(), - bean.getClass().getName())); + throw new JasperException(Localizer.getMessage("jsp.error.beans.nomethod.setproperty", prop, + type.getName(), bean.getClass().getName())); } } } - //------------------------------------------------------------------- + // ------------------------------------------------------------------- // functions to convert builtin Java data types to string. - //------------------------------------------------------------------- + // ------------------------------------------------------------------- public static String toString(Object o) { return String.valueOf(o); } @@ -427,148 +405,143 @@ public class JspRuntimeLibrary { /** - * Create a typed array. - * This is a special case where params are passed through - * the request and the property is indexed. - * @param propertyName The property name - * @param bean The bean - * @param method The method - * @param values Array values - * @param t The class + * Create a typed array. This is a special case where params are passed through the request and the property is + * indexed. + * + * @param propertyName The property name + * @param bean The bean + * @param method The method + * @param values Array values + * @param t The class * @param propertyEditorClass The editor for the property + * * @throws JasperException An error occurred */ - public static void createTypedArray(String propertyName, - Object bean, - Method method, - String[] values, - Class<?> t, - Class<?> propertyEditorClass) - throws JasperException { + public static void createTypedArray(String propertyName, Object bean, Method method, String[] values, Class<?> t, + Class<?> propertyEditorClass) throws JasperException { try { if (propertyEditorClass != null) { Object[] tmpval = new Integer[values.length]; - for (int i=0; i<values.length; i++) { - tmpval[i] = getValueFromBeanInfoPropertyEditor( - t, propertyName, values[i], propertyEditorClass); + for (int i = 0; i < values.length; i++) { + tmpval[i] = getValueFromBeanInfoPropertyEditor(t, propertyName, values[i], propertyEditorClass); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(Integer.class)) { - Integer []tmpval = new Integer[values.length]; - for (int i = 0 ; i < values.length; i++) { - tmpval[i] = Integer.valueOf(values[i]); + Integer[] tmpval = new Integer[values.length]; + for (int i = 0; i < values.length; i++) { + tmpval[i] = Integer.valueOf(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(Byte.class)) { Byte[] tmpval = new Byte[values.length]; - for (int i = 0 ; i < values.length; i++) { + for (int i = 0; i < values.length; i++) { tmpval[i] = Byte.valueOf(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(Boolean.class)) { Boolean[] tmpval = new Boolean[values.length]; - for (int i = 0 ; i < values.length; i++) { + for (int i = 0; i < values.length; i++) { tmpval[i] = Boolean.valueOf(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(Short.class)) { Short[] tmpval = new Short[values.length]; - for (int i = 0 ; i < values.length; i++) { + for (int i = 0; i < values.length; i++) { tmpval[i] = Short.valueOf(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(Long.class)) { Long[] tmpval = new Long[values.length]; - for (int i = 0 ; i < values.length; i++) { + for (int i = 0; i < values.length; i++) { tmpval[i] = Long.valueOf(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(Double.class)) { Double[] tmpval = new Double[values.length]; - for (int i = 0 ; i < values.length; i++) { + for (int i = 0; i < values.length; i++) { tmpval[i] = Double.valueOf(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(Float.class)) { Float[] tmpval = new Float[values.length]; - for (int i = 0 ; i < values.length; i++) { + for (int i = 0; i < values.length; i++) { tmpval[i] = Float.valueOf(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(Character.class)) { Character[] tmpval = new Character[values.length]; - for (int i = 0 ; i < values.length; i++) { + for (int i = 0; i < values.length; i++) { tmpval[i] = Character.valueOf(values[i].charAt(0)); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(int.class)) { - int []tmpval = new int[values.length]; - for (int i = 0 ; i < values.length; i++) { - tmpval[i] = Integer.parseInt (values[i]); + int[] tmpval = new int[values.length]; + for (int i = 0; i < values.length; i++) { + tmpval[i] = Integer.parseInt(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(byte.class)) { byte[] tmpval = new byte[values.length]; - for (int i = 0 ; i < values.length; i++) { - tmpval[i] = Byte.parseByte (values[i]); + for (int i = 0; i < values.length; i++) { + tmpval[i] = Byte.parseByte(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(boolean.class)) { boolean[] tmpval = new boolean[values.length]; - for (int i = 0 ; i < values.length; i++) { + for (int i = 0; i < values.length; i++) { tmpval[i] = Boolean.parseBoolean(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(short.class)) { short[] tmpval = new short[values.length]; - for (int i = 0 ; i < values.length; i++) { - tmpval[i] = Short.parseShort (values[i]); + for (int i = 0; i < values.length; i++) { + tmpval[i] = Short.parseShort(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(long.class)) { long[] tmpval = new long[values.length]; - for (int i = 0 ; i < values.length; i++) { - tmpval[i] = Long.parseLong (values[i]); + for (int i = 0; i < values.length; i++) { + tmpval[i] = Long.parseLong(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(double.class)) { double[] tmpval = new double[values.length]; - for (int i = 0 ; i < values.length; i++) { + for (int i = 0; i < values.length; i++) { tmpval[i] = Double.parseDouble(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(float.class)) { float[] tmpval = new float[values.length]; - for (int i = 0 ; i < values.length; i++) { + for (int i = 0; i < values.length; i++) { tmpval[i] = Float.parseFloat(values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else if (t.equals(char.class)) { char[] tmpval = new char[values.length]; - for (int i = 0 ; i < values.length; i++) { + for (int i = 0; i < values.length; i++) { tmpval[i] = values[i].charAt(0); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } else { Object[] tmpval = new Integer[values.length]; - for (int i=0; i<values.length; i++) { - tmpval[i] = - getValueFromPropertyEditorManager( - t, propertyName, values[i]); + for (int i = 0; i < values.length; i++) { + tmpval[i] = getValueFromPropertyEditorManager(t, propertyName, values[i]); } - method.invoke (bean, new Object[] {tmpval}); + method.invoke(bean, new Object[] { tmpval }); } } catch (RuntimeException | ReflectiveOperationException ex) { Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex); ExceptionUtils.handleThrowable(thr); - throw new JasperException ("error in invoking method", ex); + throw new JasperException("error in invoking method", ex); } } /** * Escape special shell characters. + * * @param unescString The string to shell-escape + * * @return The escaped shell string. */ public static String escapeQueryString(String unescString) { @@ -592,11 +565,9 @@ public class JspRuntimeLibrary { } - public static Object handleGetProperty(Object o, String prop) - throws JasperException { + public static Object handleGetProperty(Object o, String prop) throws JasperException { if (o == null) { - throw new JasperException( - Localizer.getMessage("jsp.error.beans.nullbean")); + throw new JasperException(Localizer.getMessage("jsp.error.beans.nullbean")); } Object value = null; try { @@ -605,26 +576,18 @@ public class JspRuntimeLibrary { } catch (Exception ex) { Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex); ExceptionUtils.handleThrowable(thr); - throw new JasperException (ex); + throw new JasperException(ex); } return value; } // handles <jsp:setProperty> with EL expression for 'value' attribute - public static void handleSetPropertyExpression(Object bean, - String prop, String expression, PageContext pageContext, - ProtectedFunctionMapper functionMapper ) - throws JasperException - { + public static void handleSetPropertyExpression(Object bean, String prop, String expression, PageContext pageContext, + ProtectedFunctionMapper functionMapper) throws JasperException { try { Method method = getWriteMethod(bean.getClass(), prop); - method.invoke(bean, new Object[] { - PageContextImpl.proprietaryEvaluate( - expression, - method.getParameterTypes()[0], - pageContext, - functionMapper) - }); + method.invoke(bean, new Object[] { PageContextImpl.proprietaryEvaluate(expression, + method.getParameterTypes()[0], pageContext, functionMapper) }); } catch (Exception ex) { Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex); ExceptionUtils.handleThrowable(thr); @@ -632,10 +595,7 @@ public class JspRuntimeLibrary { } } - public static void handleSetProperty(Object bean, String prop, - Object value) - throws JasperException - { + public static void handleSetProperty(Object bean, String prop, Object value) throws JasperException { try { Method method = getWriteMethod(bean.getClass(), prop); method.invoke(bean, new Object[] { value }); @@ -646,10 +606,7 @@ public class JspRuntimeLibrary { } } - public static void handleSetProperty(Object bean, String prop, - int value) - throws JasperException - { + public static void handleSetProperty(Object bean, String prop, int value) throws JasperException { try { Method method = getWriteMethod(bean.getClass(), prop); method.invoke(bean, new Object[] { Integer.valueOf(value) }); @@ -660,10 +617,7 @@ public class JspRuntimeLibrary { } } - public static void handleSetProperty(Object bean, String prop, - short value) - throws JasperException - { + public static void handleSetProperty(Object bean, String prop, short value) throws JasperException { try { Method method = getWriteMethod(bean.getClass(), prop); method.invoke(bean, new Object[] { Short.valueOf(value) }); @@ -674,10 +628,7 @@ public class JspRuntimeLibrary { } } - public static void handleSetProperty(Object bean, String prop, - long value) - throws JasperException - { + public static void handleSetProperty(Object bean, String prop, long value) throws JasperException { try { Method method = getWriteMethod(bean.getClass(), prop); method.invoke(bean, new Object[] { Long.valueOf(value) }); @@ -688,10 +639,7 @@ public class JspRuntimeLibrary { } } - public static void handleSetProperty(Object bean, String prop, - double value) - throws JasperException - { + public static void handleSetProperty(Object bean, String prop, double value) throws JasperException { try { Method method = getWriteMethod(bean.getClass(), prop); method.invoke(bean, new Object[] { Double.valueOf(value) }); @@ -702,10 +650,7 @@ public class JspRuntimeLibrary { } } - public static void handleSetProperty(Object bean, String prop, - float value) - throws JasperException - { + public static void handleSetProperty(Object bean, String prop, float value) throws JasperException { try { Method method = getWriteMethod(bean.getClass(), prop); method.invoke(bean, new Object[] { Float.valueOf(value) }); @@ -716,10 +661,7 @@ public class JspRuntimeLibrary { } } - public static void handleSetProperty(Object bean, String prop, - char value) - throws JasperException - { + public static void handleSetProperty(Object bean, String prop, char value) throws JasperException { try { Method method = getWriteMethod(bean.getClass(), prop); method.invoke(bean, new Object[] { Character.valueOf(value) }); @@ -730,10 +672,7 @@ public class JspRuntimeLibrary { } } - public static void handleSetProperty(Object bean, String prop, - byte value) - throws JasperException - { + public static void handleSetProperty(Object bean, String prop, byte value) throws JasperException { try { Method method = getWriteMethod(bean.getClass(), prop); method.invoke(bean, new Object[] { Byte.valueOf(value) }); @@ -744,10 +683,7 @@ public class JspRuntimeLibrary { } } - public static void handleSetProperty(Object bean, String prop, - boolean value) - throws JasperException - { + public static void handleSetProperty(Object bean, String prop, boolean value) throws JasperException { try { Method method = getWriteMethod(bean.getClass(), prop); method.invoke(bean, new Object[] { Boolean.valueOf(value) }); @@ -760,7 +696,9 @@ public class JspRuntimeLibrary { /** * Reverse of Introspector.decapitalize. + * * @param name The name + * * @return the capitalized string */ public static String capitalize(String name) { @@ -772,8 +710,7 @@ public class JspRuntimeLibrary { return new String(chars); } - public static Method getWriteMethod(Class<?> beanClass, String prop) - throws JasperException { + public static Method getWriteMethod(Class<?> beanClass, String prop) throws JasperException { Method result = null; Class<?> type = null; if (GRAAL) { @@ -796,24 +733,22 @@ public class JspRuntimeLibrary { } } } catch (Exception ex) { - throw new JasperException (ex); + throw new JasperException(ex); } } if (result == null) { if (type == null) { - throw new JasperException(Localizer.getMessage( - "jsp.error.beans.noproperty", prop, beanClass.getName())); + throw new JasperException( + Localizer.getMessage("jsp.error.beans.noproperty", prop, beanClass.getName())); } else { - throw new JasperException(Localizer.getMessage( - "jsp.error.beans.nomethod.setproperty", - prop, type.getName(), beanClass.getName())); + throw new JasperException(Localizer.getMessage("jsp.error.beans.nomethod.setproperty", prop, + type.getName(), beanClass.getName())); } } return result; } - public static Method getReadMethod(Class<?> beanClass, String prop) - throws JasperException { + public static Method getReadMethod(Class<?> beanClass, String prop) throws JasperException { Method result = null; Class<?> type = null; if (GRAAL) { @@ -836,52 +771,43 @@ public class JspRuntimeLibrary { } } } catch (Exception ex) { - throw new JasperException (ex); + throw new JasperException(ex); } } if (result == null) { if (type == null) { - throw new JasperException(Localizer.getMessage( - "jsp.error.beans.noproperty", prop, beanClass.getName())); + throw new JasperException( + Localizer.getMessage("jsp.error.beans.noproperty", prop, beanClass.getName())); } else { - throw new JasperException(Localizer.getMessage( - "jsp.error.beans.nomethod", prop, beanClass.getName())); + throw new JasperException(Localizer.getMessage("jsp.error.beans.nomethod", prop, beanClass.getName())); } } return result; } - //********************************************************************* + // ********************************************************************* // PropertyEditor Support - public static Object getValueFromBeanInfoPropertyEditor( - Class<?> attrClass, String attrName, String attrValue, - Class<?> propertyEditorClass) - throws JasperException - { + public static Object getValueFromBeanInfoPropertyEditor(Class<?> attrClass, String attrName, String attrValue, + Class<?> propertyEditorClass) throws JasperException { try { - PropertyEditor pe = (PropertyEditor)propertyEditorClass.getConstructor().newInstance(); + PropertyEditor pe = (PropertyEditor) propertyEditorClass.getConstructor().newInstance(); pe.setAsText(attrValue); return pe.getValue(); } catch (Exception ex) { if (attrValue.length() == 0) { return null; } else { - throw new JasperException( - Localizer.getMessage("jsp.error.beans.property.conversion", - attrValue, attrClass.getName(), attrName, - ex.getMessage())); + throw new JasperException(Localizer.getMessage("jsp.error.beans.property.conversion", attrValue, + attrClass.getName(), attrName, ex.getMessage())); } } } - public static Object getValueFromPropertyEditorManager( - Class<?> attrClass, String attrName, String attrValue) - throws JasperException - { + public static Object getValueFromPropertyEditorManager(Class<?> attrClass, String attrName, String attrValue) + throws JasperException { try { - PropertyEditor propEditor = - PropertyEditorManager.findEditor(attrClass); + PropertyEditor propEditor = PropertyEditorManager.findEditor(attrClass); if (propEditor != null) { propEditor.setAsText(attrValue); return propEditor.getValue(); @@ -889,16 +815,14 @@ public class JspRuntimeLibrary { return null; } else { throw new IllegalArgumentException( - Localizer.getMessage("jsp.error.beans.propertyeditor.notregistered")); + Localizer.getMessage("jsp.error.beans.propertyeditor.notregistered")); } } catch (IllegalArgumentException ex) { if (attrValue.length() == 0) { return null; } else { - throw new JasperException( - Localizer.getMessage("jsp.error.beans.property.conversion", - attrValue, attrClass.getName(), attrName, - ex.getMessage())); + throw new JasperException(Localizer.getMessage("jsp.error.beans.property.conversion", attrValue, + attrClass.getName(), attrName, ex.getMessage())); } } } @@ -910,15 +834,14 @@ public class JspRuntimeLibrary { /** - * Convert a possibly relative resource path into a context-relative - * resource path that starts with a '/'. + * Convert a possibly relative resource path into a context-relative resource path that starts with a '/'. * - * @param request The servlet request we are processing + * @param request The servlet request we are processing * @param relativePath The possibly relative resource path + * * @return an absolute path */ - public static String getContextRelativePath(ServletRequest request, - String relativePath) { + public static String getContextRelativePath(ServletRequest request, String relativePath) { if (relativePath.startsWith("/")) { return relativePath; @@ -927,11 +850,9 @@ public class JspRuntimeLibrary { return relativePath; } HttpServletRequest hrequest = (HttpServletRequest) request; - String uri = (String) request.getAttribute( - RequestDispatcher.INCLUDE_SERVLET_PATH); + String uri = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH); if (uri != null) { - String pathInfo = (String) - request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO); + String pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO); if (pathInfo == null) { if (uri.lastIndexOf('/') >= 0) { uri = uri.substring(0, uri.lastIndexOf('/')); @@ -949,24 +870,19 @@ public class JspRuntimeLibrary { /** - * Perform a RequestDispatcher.include() operation, with optional flushing - * of the response beforehand. + * Perform a RequestDispatcher.include() operation, with optional flushing of the response beforehand. * - * @param request The servlet request we are processing - * @param response The servlet response we are processing + * @param request The servlet request we are processing + * @param response The servlet response we are processing * @param relativePath The relative path of the resource to be included - * @param out The Writer to whom we are currently writing - * @param flush Should we flush before the include is processed? + * @param out The Writer to whom we are currently writing + * @param flush Should we flush before the include is processed? * - * @exception IOException if thrown by the included servlet + * @exception IOException if thrown by the included servlet * @exception ServletException if thrown by the included servlet */ - public static void include(ServletRequest request, - ServletResponse response, - String relativePath, - JspWriter out, - boolean flush) - throws IOException, ServletException { + public static void include(ServletRequest request, ServletResponse response, String relativePath, JspWriter out, + boolean flush) throws IOException, ServletException { if (flush && !(out instanceof BodyContent)) { out.flush(); @@ -975,26 +891,26 @@ public class JspRuntimeLibrary { // FIXME - It is tempting to use request.getRequestDispatcher() to // resolve a relative path directly, but Catalina currently does not // take into account whether the caller is inside a RequestDispatcher - // include or not. Whether Catalina *should* take that into account - // is a spec issue currently under review. In the mean time, + // include or not. Whether Catalina *should* take that into account + // is a spec issue currently under review. In the mean time, // replicate Jasper's previous behavior String resourcePath = getContextRelativePath(request, relativePath); RequestDispatcher rd = request.getRequestDispatcher(resourcePath); if (rd != null) { - rd.include(request, - new ServletResponseWrapperInclude(response, out)); + rd.include(request, new ServletResponseWrapperInclude(response, out)); } else { - throw new JasperException( - Localizer.getMessage("jsp.error.include.exception", resourcePath)); + throw new JasperException(Localizer.getMessage("jsp.error.include.exception", resourcePath)); } } /** * URL encodes a string, based on the supplied character encoding. - * @param s The String to be URL encoded. + * + * @param s The String to be URL encoded. * @param enc The character encoding + * * @return The URL encoded String */ public static String URLEncode(String s, String enc) { @@ -1002,7 +918,7 @@ public class JspRuntimeLibrary { return "null"; } if (enc == null) { - enc = "ISO-8859-1"; // The default request encoding + enc = "ISO-8859-1"; // The default request encoding } Charset cs = null; try { @@ -1015,8 +931,7 @@ public class JspRuntimeLibrary { } - public static JspWriter startBufferedBody(PageContext pageContext, BodyTag tag) - throws JspException { + public static JspWriter startBufferedBody(PageContext pageContext, BodyTag tag) throws JspException { BodyContent out = pageContext.pushBody(); tag.setBodyContent(out); tag.doInitBody(); diff --git a/java/org/apache/jasper/runtime/JspSourceDependent.java b/java/org/apache/jasper/runtime/JspSourceDependent.java index f6d9fa093a..bc863e5405 100644 --- a/java/org/apache/jasper/runtime/JspSourceDependent.java +++ b/java/org/apache/jasper/runtime/JspSourceDependent.java @@ -19,8 +19,8 @@ package org.apache.jasper.runtime; import java.util.Map; /** - * Interface for tracking the source files dependencies, for the purpose - * of compiling out of date pages. This is used for: + * Interface for tracking the source files dependencies, for the purpose of compiling out of date pages. This is used + * for: * <ul> * <li>files that are included by page directives</li> * <li>files that are included by include-prelude and include-coda in jsp:config</li> @@ -31,10 +31,10 @@ import java.util.Map; public interface JspSourceDependent { - /** - * Returns a map of file names and last modified time where the current page - * has a source dependency on the file. - * @return the map of dependent resources - */ + /** + * Returns a map of file names and last modified time where the current page has a source dependency on the file. + * + * @return the map of dependent resources + */ Map<String,Long> getDependants(); } \ No newline at end of file diff --git a/java/org/apache/jasper/runtime/JspSourceDirectives.java b/java/org/apache/jasper/runtime/JspSourceDirectives.java index a9fb46ceb2..c1fade3d17 100644 --- a/java/org/apache/jasper/runtime/JspSourceDirectives.java +++ b/java/org/apache/jasper/runtime/JspSourceDirectives.java @@ -17,9 +17,8 @@ package org.apache.jasper.runtime; /** - * Provides runtime access to selected compile time directives. Page directives - * are not added to this interface until there is a requirement to access them - * at runtime. + * Provides runtime access to selected compile time directives. Page directives are not added to this interface until + * there is a requirement to access them at runtime. */ public interface JspSourceDirectives { diff --git a/java/org/apache/jasper/runtime/JspSourceImports.java b/java/org/apache/jasper/runtime/JspSourceImports.java index 09f58d822b..d65e8bd757 100644 --- a/java/org/apache/jasper/runtime/JspSourceImports.java +++ b/java/org/apache/jasper/runtime/JspSourceImports.java @@ -19,12 +19,12 @@ package org.apache.jasper.runtime; import java.util.Set; /** - * The EL engine needs access to the imports used in the JSP page to configure - * the ELContext. The imports are available at compile time but the ELContext - * is created lazily per page. This interface exposes the imports at runtime so - * that they may be added to the ELContext when it is created. + * The EL engine needs access to the imports used in the JSP page to configure the ELContext. The imports are available + * at compile time but the ELContext is created lazily per page. This interface exposes the imports at runtime so that + * they may be added to the ELContext when it is created. */ public interface JspSourceImports { Set<String> getPackageImports(); + Set<String> getClassImports(); } diff --git a/java/org/apache/jasper/runtime/JspWriterImpl.java b/java/org/apache/jasper/runtime/JspWriterImpl.java index 0415492a07..0a1afd48ef 100644 --- a/java/org/apache/jasper/runtime/JspWriterImpl.java +++ b/java/org/apache/jasper/runtime/JspWriterImpl.java @@ -27,15 +27,9 @@ import org.apache.jasper.Constants; import org.apache.jasper.compiler.Localizer; /** - * Write text to a character-output stream, buffering characters so as - * to provide for the efficient writing of single characters, arrays, - * and strings. - * - * Provide support for discarding for the output that has been - * buffered. - * - * This needs revisiting when the buffering problems in the JSP spec - * are fixed -akv + * Write text to a character-output stream, buffering characters so as to provide for the efficient writing of single + * characters, arrays, and strings. Provide support for discarding for the output that has been buffered. This needs + * revisiting when the buffering problems in the JSP spec are fixed -akv * * @author Anil K. Vijendran */ @@ -49,21 +43,20 @@ public class JspWriterImpl extends JspWriter { private boolean closed = false; public JspWriterImpl() { - super( Constants.DEFAULT_BUFFER_SIZE, true ); + super(Constants.DEFAULT_BUFFER_SIZE, true); } /** - * Create a new buffered character-output stream that uses an output - * buffer of the given size. + * Create a new buffered character-output stream that uses an output buffer of the given size. + * + * @param response A Servlet Response + * @param sz Output-buffer size, a positive integer + * @param autoFlush <code>true</code> to automatically flush on buffer full, <code>false</code> to throw an overflow + * exception in that case * - * @param response A Servlet Response - * @param sz Output-buffer size, a positive integer - * @param autoFlush <code>true</code> to automatically flush on buffer - * full, <code>false</code> to throw an overflow exception in that case - * @exception IllegalArgumentException If sz is <= 0 + * @exception IllegalArgumentException If sz is <= 0 */ - public JspWriterImpl(ServletResponse response, int sz, - boolean autoFlush) { + public JspWriterImpl(ServletResponse response, int sz, boolean autoFlush) { super(sz, autoFlush); if (sz < 0) { throw new IllegalArgumentException(Localizer.getMessage("jsp.error.negativeBufferSize")); @@ -73,14 +66,14 @@ public class JspWriterImpl extends JspWriter { nextChar = 0; } - void init( ServletResponse response, int sz, boolean autoFlush ) { - this.response= response; - if( sz > 0 && ( cb == null || sz > cb.length ) ) { - cb=new char[sz]; + void init(ServletResponse response, int sz, boolean autoFlush) { + this.response = response; + if (sz > 0 && (cb == null || sz > cb.length)) { + cb = new char[sz]; } nextChar = 0; - this.autoFlush=autoFlush; - this.bufferSize=sz; + this.autoFlush = autoFlush; + this.bufferSize = sz; } /** @@ -95,9 +88,9 @@ public class JspWriterImpl extends JspWriter { } /** - * Flush the output buffer to the underlying character stream, without - * flushing the stream itself. This method is non-private only so that it - * may be invoked by PrintStream. + * Flush the output buffer to the underlying character stream, without flushing the stream itself. This method is + * non-private only so that it may be invoked by PrintStream. + * * @throws IOException Error writing buffered data */ protected final void flushBuffer() throws IOException { @@ -133,12 +126,10 @@ public class JspWriterImpl extends JspWriter { public final void clear() throws IOException { if ((bufferSize == 0) && (out != null)) { // clear() is illegal after any unbuffered output (JSP.5.5) - throw new IllegalStateException( - Localizer.getMessage("jsp.error.ise_on_clear")); + throw new IllegalStateException(Localizer.getMessage("jsp.error.ise_on_clear")); } if (flushed) { - throw new IOException( - Localizer.getMessage("jsp.error.attempt_to_clear_flushed_buffer")); + throw new IOException(Localizer.getMessage("jsp.error.attempt_to_clear_flushed_buffer")); } ensureOpen(); nextChar = 0; @@ -147,8 +138,7 @@ public class JspWriterImpl extends JspWriter { @Override public void clearBuffer() throws IOException { if (bufferSize == 0) { - throw new IllegalStateException( - Localizer.getMessage("jsp.error.ise_on_clear")); + throw new IllegalStateException(Localizer.getMessage("jsp.error.ise_on_clear")); } ensureOpen(); nextChar = 0; @@ -159,7 +149,7 @@ public class JspWriterImpl extends JspWriter { } @Override - public void flush() throws IOException { + public void flush() throws IOException { flushBuffer(); if (out != null) { out.flush(); @@ -212,8 +202,8 @@ public class JspWriterImpl extends JspWriter { } /** - * Our own little min method, to avoid loading java.lang.Math if we've run - * out of file descriptors and we're trying to print a stack trace. + * Our own little min method, to avoid loading java.lang.Math if we've run out of file descriptors and we're trying + * to print a stack trace. */ private static int min(int a, int b) { if (a < b) { @@ -232,17 +222,17 @@ public class JspWriterImpl extends JspWriter { return; } - if ((off < 0) || (off > cbuf.length) || (len < 0) || - ((off + len) > cbuf.length) || ((off + len) < 0)) { + if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return; } if (len >= bufferSize) { - /* If the request length exceeds the size of the output buffer, - flush the buffer and then write the data directly. In this - way buffered streams will cascade harmlessly. */ + /* + * If the request length exceeds the size of the output buffer, flush the buffer and then write the data + * directly. In this way buffered streams will cascade harmlessly. + */ if (autoFlush) { flushBuffer(); } else { diff --git a/java/org/apache/jasper/runtime/PageContextImpl.java b/java/org/apache/jasper/runtime/PageContextImpl.java index 604f0dc21e..cfc7968a5d 100644 --- a/java/org/apache/jasper/runtime/PageContextImpl.java +++ b/java/org/apache/jasper/runtime/PageContextImpl.java @@ -52,8 +52,7 @@ import org.apache.jasper.el.ELContextImpl; import org.apache.jasper.runtime.JspContextWrapper.ELContextWrapper; /** - * Implementation of the PageContext class from the JSP spec. Also doubles as a - * VariableResolver for the EL. + * Implementation of the PageContext class from the JSP spec. Also doubles as a VariableResolver for the EL. * * @author Anil K. Vijendran * @author Larry Cable @@ -89,7 +88,7 @@ public class PageContextImpl extends PageContext { private int bodyContentTagBufferSize = Constants.DEFAULT_TAG_BUFFER_SIZE; // page-scope attributes - private final transient HashMap<String, Object> attributes; + private final transient HashMap<String,Object> attributes; // per-request state private transient ServletRequest request; @@ -113,10 +112,8 @@ public class PageContextImpl extends PageContext { } @Override - public void initialize(Servlet servlet, ServletRequest request, - ServletResponse response, String errorPageURL, - boolean needsSession, int bufferSize, boolean autoFlush) - throws IOException { + public void initialize(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL, + boolean needsSession, int bufferSize, boolean autoFlush) throws IOException { // initialize state this.servlet = servlet; @@ -191,7 +188,7 @@ public class PageContextImpl extends PageContext { baseOut.recycle(); session = null; attributes.clear(); - for (BodyContentImpl body: outs) { + for (BodyContentImpl body : outs) { body.recycle(); } } @@ -210,23 +207,23 @@ public class PageContextImpl extends PageContext { } switch (scope) { - case PAGE_SCOPE: - return attributes.get(name); + case PAGE_SCOPE: + return attributes.get(name); - case REQUEST_SCOPE: - return request.getAttribute(name); + case REQUEST_SCOPE: + return request.getAttribute(name); - case SESSION_SCOPE: - if (session == null) { - throw new IllegalStateException(Localizer.getMessage("jsp.error.page.noSession")); - } - return session.getAttribute(name); + case SESSION_SCOPE: + if (session == null) { + throw new IllegalStateException(Localizer.getMessage("jsp.error.page.noSession")); + } + return session.getAttribute(name); - case APPLICATION_SCOPE: - return context.getAttribute(name); + case APPLICATION_SCOPE: + return context.getAttribute(name); - default: - throw new IllegalArgumentException(Localizer.getMessage("jsp.error.page.invalid.scope")); + default: + throw new IllegalArgumentException(Localizer.getMessage("jsp.error.page.invalid.scope")); } } @@ -246,28 +243,27 @@ public class PageContextImpl extends PageContext { removeAttribute(name, scope); } else { switch (scope) { - case PAGE_SCOPE: - attributes.put(name, o); - break; + case PAGE_SCOPE: + attributes.put(name, o); + break; - case REQUEST_SCOPE: - request.setAttribute(name, o); - break; + case REQUEST_SCOPE: + request.setAttribute(name, o); + break; - case SESSION_SCOPE: - if (session == null) { - throw new IllegalStateException(Localizer - .getMessage("jsp.error.page.noSession")); - } - session.setAttribute(name, o); - break; + case SESSION_SCOPE: + if (session == null) { + throw new IllegalStateException(Localizer.getMessage("jsp.error.page.noSession")); + } + session.setAttribute(name, o); + break; - case APPLICATION_SCOPE: - context.setAttribute(name, o); - break; + case APPLICATION_SCOPE: + context.setAttribute(name, o); + break; - default: - throw new IllegalArgumentException(Localizer.getMessage("jsp.error.page.invalid.scope")); + default: + throw new IllegalArgumentException(Localizer.getMessage("jsp.error.page.invalid.scope")); } } } @@ -280,27 +276,27 @@ public class PageContextImpl extends PageContext { } switch (scope) { - case PAGE_SCOPE: - attributes.remove(name); - break; + case PAGE_SCOPE: + attributes.remove(name); + break; - case REQUEST_SCOPE: - request.removeAttribute(name); - break; + case REQUEST_SCOPE: + request.removeAttribute(name); + break; - case SESSION_SCOPE: - if (session == null) { - throw new IllegalStateException(Localizer.getMessage("jsp.error.page.noSession")); - } - session.removeAttribute(name); - break; + case SESSION_SCOPE: + if (session == null) { + throw new IllegalStateException(Localizer.getMessage("jsp.error.page.noSession")); + } + session.removeAttribute(name); + break; - case APPLICATION_SCOPE: - context.removeAttribute(name); - break; + case APPLICATION_SCOPE: + context.removeAttribute(name); + break; - default: - throw new IllegalArgumentException(Localizer.getMessage("jsp.error.page.invalid.scope")); + default: + throw new IllegalArgumentException(Localizer.getMessage("jsp.error.page.invalid.scope")); } } @@ -324,7 +320,7 @@ public class PageContextImpl extends PageContext { if (session.getAttribute(name) != null) { return SESSION_SCOPE; } - } catch(IllegalStateException ise) { + } catch (IllegalStateException ise) { // Session has been invalidated. // Ignore and fall through to application scope. } @@ -356,7 +352,7 @@ public class PageContextImpl extends PageContext { if (session != null) { try { o = session.getAttribute(name); - } catch(IllegalStateException ise) { + } catch (IllegalStateException ise) { // Session has been invalidated. // Ignore and fall through to application scope. } @@ -371,23 +367,23 @@ public class PageContextImpl extends PageContext { @Override public Enumeration<String> getAttributeNamesInScope(final int scope) { switch (scope) { - case PAGE_SCOPE: - return Collections.enumeration(attributes.keySet()); + case PAGE_SCOPE: + return Collections.enumeration(attributes.keySet()); - case REQUEST_SCOPE: - return request.getAttributeNames(); + case REQUEST_SCOPE: + return request.getAttributeNames(); - case SESSION_SCOPE: - if (session == null) { - throw new IllegalStateException(Localizer.getMessage("jsp.error.page.noSession")); - } - return session.getAttributeNames(); + case SESSION_SCOPE: + if (session == null) { + throw new IllegalStateException(Localizer.getMessage("jsp.error.page.noSession")); + } + return session.getAttributeNames(); - case APPLICATION_SCOPE: - return context.getAttributeNames(); + case APPLICATION_SCOPE: + return context.getAttributeNames(); - default: - throw new IllegalArgumentException(Localizer.getMessage("jsp.error.page.invalid.scope")); + default: + throw new IllegalArgumentException(Localizer.getMessage("jsp.error.page.invalid.scope")); } } @@ -400,10 +396,10 @@ public class PageContextImpl extends PageContext { removeAttribute(name, PAGE_SCOPE); removeAttribute(name, REQUEST_SCOPE); - if( session != null ) { + if (session != null) { try { removeAttribute(name, SESSION_SCOPE); - } catch(IllegalStateException ise) { + } catch (IllegalStateException ise) { // Session has been invalidated. // Ignore and fall throw to application scope. } @@ -444,8 +440,7 @@ public class PageContextImpl extends PageContext { /** * Returns the exception associated with this page context, if any. * <p> - * Added wrapping for Throwables to avoid ClassCastException: see Bugzilla - * 31171 for details. + * Added wrapping for Throwables to avoid ClassCastException: see Bugzilla 31171 for details. * * @return The Exception associated with this page context, if any. */ @@ -470,8 +465,7 @@ public class PageContextImpl extends PageContext { String path = relativeUrlPath; if (!path.startsWith("/")) { - String uri = (String) request.getAttribute( - RequestDispatcher.INCLUDE_SERVLET_PATH); + String uri = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH); if (uri == null) { uri = ((HttpServletRequest) request).getServletPath(); } @@ -483,23 +477,19 @@ public class PageContextImpl extends PageContext { } @Override - public void include(String relativeUrlPath) throws ServletException, - IOException { - JspRuntimeLibrary - .include(request, response, relativeUrlPath, out, true); + public void include(String relativeUrlPath) throws ServletException, IOException { + JspRuntimeLibrary.include(request, response, relativeUrlPath, out, true); } @Override - public void include(final String relativeUrlPath, final boolean flush) - throws ServletException, IOException { + public void include(final String relativeUrlPath, final boolean flush) throws ServletException, IOException { JspRuntimeLibrary.include(request, response, relativeUrlPath, out, flush); } @Override @Deprecated public jakarta.servlet.jsp.el.VariableResolver getVariableResolver() { - return new org.apache.jasper.el.VariableResolverImpl( - this.getELContext()); + return new org.apache.jasper.el.VariableResolverImpl(this.getELContext()); } @Override @@ -509,8 +499,7 @@ public class PageContextImpl extends PageContext { out.clear(); baseOut.clear(); } catch (IOException ex) { - throw new IllegalStateException(Localizer.getMessage( - "jsp.error.attempt_to_clear_flushed_buffer"), ex); + throw new IllegalStateException(Localizer.getMessage("jsp.error.attempt_to_clear_flushed_buffer"), ex); } // Make sure that the response object is not the wrapper for include @@ -574,20 +563,17 @@ public class PageContextImpl extends PageContext { } /** - * Provides programmatic access to the ExpressionEvaluator. The JSP - * Container must return a valid instance of an ExpressionEvaluator that can - * parse EL expressions. + * Provides programmatic access to the ExpressionEvaluator. The JSP Container must return a valid instance of an + * ExpressionEvaluator that can parse EL expressions. */ @Override @Deprecated public jakarta.servlet.jsp.el.ExpressionEvaluator getExpressionEvaluator() { - return new org.apache.jasper.el.ExpressionEvaluatorImpl( - this.applicationContext.getExpressionFactory()); + return new org.apache.jasper.el.ExpressionEvaluatorImpl(this.applicationContext.getExpressionFactory()); } @Override - public void handlePageException(Exception ex) throws IOException, - ServletException { + public void handlePageException(Exception ex) throws IOException, ServletException { // Should never be called since handleException() called with a // Throwable in the generated servlet. handlePageException((Throwable) ex); @@ -603,13 +589,10 @@ public class PageContextImpl extends PageContext { if (errorPageURL != null && !errorPageURL.equals("")) { /* - * Set request attributes. Do not set the - * jakarta.servlet.error.exception attribute here (instead, set in the - * generated servlet code for the error page) in order to prevent - * the ErrorReportValve, which is invoked as part of forwarding the - * request to the error page, from throwing it if the response has - * not been committed (the response will have been committed if the - * error page is a JSP page). + * Set request attributes. Do not set the jakarta.servlet.error.exception attribute here (instead, set in + * the generated servlet code for the error page) in order to prevent the ErrorReportValve, which is invoked + * as part of forwarding the request to the error page, from throwing it if the response has not been + * committed (the response will have been committed if the error page is a JSP page). */ request.setAttribute(EXCEPTION, t); request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, @@ -658,8 +641,7 @@ public class PageContextImpl extends PageContext { } if (rootCause != null) { - throw new ServletException( - t.getClass().getName() + ": " + t.getMessage(), rootCause); + throw new ServletException(t.getClass().getName() + ": " + t.getMessage(), rootCause); } throw new ServletException(t); @@ -667,27 +649,22 @@ public class PageContextImpl extends PageContext { } /** - * Proprietary method to evaluate EL expressions. XXX - This method should - * go away once the EL interpreter moves out of JSTL and into its own - * project. For now, this is necessary because the standard machinery is too - * slow. + * Proprietary method to evaluate EL expressions. XXX - This method should go away once the EL interpreter moves out + * of JSTL and into its own project. For now, this is necessary because the standard machinery is too slow. + * + * @param expression The expression to be evaluated + * @param expectedType The expected resulting type + * @param pageContext The page context + * @param functionMap Maps prefix and name to Method * - * @param expression - * The expression to be evaluated - * @param expectedType - * The expected resulting type - * @param pageContext - * The page context - * @param functionMap - * Maps prefix and name to Method * @return The result of the evaluation + * * @throws ELException If an error occurs during the evaluation */ - public static Object proprietaryEvaluate(final String expression, - final Class<?> expectedType, final PageContext pageContext, - final ProtectedFunctionMapper functionMap) - throws ELException { - final ExpressionFactory exprFactory = jspf.getJspApplicationContext(pageContext.getServletContext()).getExpressionFactory(); + public static Object proprietaryEvaluate(final String expression, final Class<?> expectedType, + final PageContext pageContext, final ProtectedFunctionMapper functionMap) throws ELException { + final ExpressionFactory exprFactory = + jspf.getJspApplicationContext(pageContext.getServletContext()).getExpressionFactory(); ELContext ctx = pageContext.getELContext(); ELContextImpl ctxImpl; if (ctx instanceof ELContextWrapper) { diff --git a/java/org/apache/jasper/runtime/ProtectedFunctionMapper.java b/java/org/apache/jasper/runtime/ProtectedFunctionMapper.java index 4c02395099..7eef529e3f 100644 --- a/java/org/apache/jasper/runtime/ProtectedFunctionMapper.java +++ b/java/org/apache/jasper/runtime/ProtectedFunctionMapper.java @@ -22,15 +22,14 @@ import java.util.HashMap; import jakarta.servlet.jsp.el.FunctionMapper; /** - * Maps EL functions to their Java method counterparts. Keeps the actual Method - * objects protected so that JSP pages can't indirectly do reflection. + * Maps EL functions to their Java method counterparts. Keeps the actual Method objects protected so that JSP pages + * can't indirectly do reflection. * * @author Mark Roth * @author Kin-man Chung */ @SuppressWarnings("deprecation") // Have to support old JSP EL API -public final class ProtectedFunctionMapper extends jakarta.el.FunctionMapper - implements FunctionMapper { +public final class ProtectedFunctionMapper extends jakarta.el.FunctionMapper implements FunctionMapper { /** * Maps "prefix:name" to java.lang.Method objects. @@ -49,8 +48,8 @@ public final class ProtectedFunctionMapper extends jakarta.el.FunctionMapper } /** - * Generated Servlet and Tag Handler implementations call this method to - * retrieve an instance of the ProtectedFunctionMapper. + * Generated Servlet and Tag Handler implementations call this method to retrieve an instance of the + * ProtectedFunctionMapper. * * @return A new protected function mapper. */ @@ -61,22 +60,16 @@ public final class ProtectedFunctionMapper extends jakarta.el.FunctionMapper } /** - * Stores a mapping from the given EL function prefix and name to the given - * Java method. + * Stores a mapping from the given EL function prefix and name to the given Java method. * - * @param fnQName - * The EL function qualified name (including prefix) - * @param c - * The class containing the Java method - * @param methodName - * The name of the Java method - * @param args - * The arguments of the Java method - * @throws RuntimeException - * if no method with the given signature could be found. + * @param fnQName The EL function qualified name (including prefix) + * @param c The class containing the Java method + * @param methodName The name of the Java method + * @param args The arguments of the Java method + * + * @throws RuntimeException if no method with the given signature could be found. */ - public void mapFunction(String fnQName, final Class<?> c, - final String methodName, final Class<?>[] args) { + public void mapFunction(String fnQName, final Class<?> c, final String methodName, final Class<?>[] args) { // Skip if null values were passed in. They indicate a function // added via a lambda or ImportHandler; nether of which need to be // placed in the Map. @@ -87,33 +80,27 @@ public final class ProtectedFunctionMapper extends jakarta.el.FunctionMapper try { method = c.getMethod(methodName, args); } catch (NoSuchMethodException e) { - throw new RuntimeException( - "Invalid function mapping - no such method: " - + e.getMessage()); + throw new RuntimeException("Invalid function mapping - no such method: " + e.getMessage()); } this.fnmap.put(fnQName, method); } /** - * Creates an instance for this class, and stores the Method for the given - * EL function prefix and name. This method is used for the case when there - * is only one function in the EL expression. + * Creates an instance for this class, and stores the Method for the given EL function prefix and name. This method + * is used for the case when there is only one function in the EL expression. + * + * @param fnQName The EL function qualified name (including prefix) + * @param c The class containing the Java method + * @param methodName The name of the Java method + * @param args The arguments of the Java method + * + * @throws RuntimeException if no method with the given signature could be found. * - * @param fnQName - * The EL function qualified name (including prefix) - * @param c - * The class containing the Java method - * @param methodName - * The name of the Java method - * @param args - * The arguments of the Java method - * @throws RuntimeException - * if no method with the given signature could be found. * @return the mapped function */ - public static ProtectedFunctionMapper getMapForFunction(String fnQName, - final Class<?> c, final String methodName, final Class<?>[] args) { + public static ProtectedFunctionMapper getMapForFunction(String fnQName, final Class<?> c, final String methodName, + final Class<?>[] args) { Method method = null; ProtectedFunctionMapper funcMapper = new ProtectedFunctionMapper(); // Skip if null values were passed in. They indicate a function @@ -123,9 +110,7 @@ public final class ProtectedFunctionMapper extends jakarta.el.FunctionMapper try { method = c.getMethod(methodName, args); } catch (NoSuchMethodException e) { - throw new RuntimeException( - "Invalid function mapping - no such method: " - + e.getMessage()); + throw new RuntimeException("Invalid function mapping - no such method: " + e.getMessage()); } } funcMapper.theMethod = method; @@ -133,13 +118,12 @@ public final class ProtectedFunctionMapper extends jakarta.el.FunctionMapper } /** - * Resolves the specified local name and prefix into a Java.lang.Method. - * Returns null if the prefix and local name are not found. + * Resolves the specified local name and prefix into a Java.lang.Method. Returns null if the prefix and local name + * are not found. + * + * @param prefix the prefix of the function + * @param localName the short name of the function * - * @param prefix - * the prefix of the function - * @param localName - * the short name of the function * @return the result of the method mapping. Null means no entry found. */ @Override diff --git a/java/org/apache/jasper/runtime/ServletResponseWrapperInclude.java b/java/org/apache/jasper/runtime/ServletResponseWrapperInclude.java index 4083ec203c..2ab21b8cd2 100644 --- a/java/org/apache/jasper/runtime/ServletResponseWrapperInclude.java +++ b/java/org/apache/jasper/runtime/ServletResponseWrapperInclude.java @@ -26,11 +26,8 @@ import jakarta.servlet.http.HttpServletResponseWrapper; import jakarta.servlet.jsp.JspWriter; /** - * ServletResponseWrapper used by the JSP 'include' action. - * - * This wrapper response object is passed to RequestDispatcher.include(), so - * that the output of the included resource is appended to that of the - * including page. + * ServletResponseWrapper used by the JSP 'include' action. This wrapper response object is passed to + * RequestDispatcher.include(), so that the output of the included resource is appended to that of the including page. * * @author Pierre Delisle */ @@ -44,9 +41,8 @@ public class ServletResponseWrapperInclude extends HttpServletResponseWrapper { private final JspWriter jspWriter; - public ServletResponseWrapperInclude(ServletResponse response, - JspWriter jspWriter) { - super((HttpServletResponse)response); + public ServletResponseWrapperInclude(ServletResponse response, JspWriter jspWriter) { + super((HttpServletResponse) response); this.printWriter = new PrintWriter(jspWriter); this.jspWriter = jspWriter; } @@ -65,8 +61,7 @@ public class ServletResponseWrapperInclude extends HttpServletResponseWrapper { } /** - * Clears the output buffer of the JspWriter associated with the including - * page. + * Clears the output buffer of the JspWriter associated with the including page. */ @Override public void resetBuffer() { diff --git a/java/org/apache/jasper/runtime/TagHandlerPool.java b/java/org/apache/jasper/runtime/TagHandlerPool.java index c501cee820..cca03d7c5d 100644 --- a/java/org/apache/jasper/runtime/TagHandlerPool.java +++ b/java/org/apache/jasper/runtime/TagHandlerPool.java @@ -93,14 +93,14 @@ public class TagHandlerPool { } /** - * Gets the next available tag handler from this tag handler pool, - * instantiating one if this tag handler pool is empty. + * Gets the next available tag handler from this tag handler pool, instantiating one if this tag handler pool is + * empty. + * + * @param handlerClass Tag handler class * - * @param handlerClass - * Tag handler class * @return Reused or newly instantiated tag handler - * @throws JspException - * if a tag handler cannot be instantiated + * + * @throws JspException if a tag handler cannot be instantiated */ public Tag get(Class<? extends Tag> handlerClass) throws JspException { Tag handler; @@ -115,8 +115,7 @@ public class TagHandlerPool { // wait for us to construct a tag for this thread. try { if (useInstanceManagerForTags) { - return (Tag) instanceManager.newInstance( - handlerClass.getName(), handlerClass.getClassLoader()); + return (Tag) instanceManager.newInstance(handlerClass.getName(), handlerClass.getClassLoader()); } else { Tag instance = handlerClass.getConstructor().newInstance(); instanceManager.newInstance(instance); @@ -130,12 +129,10 @@ public class TagHandlerPool { } /** - * Adds the given tag handler to this tag handler pool, unless this tag - * handler pool has already reached its capacity, in which case the tag - * handler's release() method is called. + * Adds the given tag handler to this tag handler pool, unless this tag handler pool has already reached its + * capacity, in which case the tag handler's release() method is called. * - * @param handler - * Tag handler to add to this tag handler pool + * @param handler Tag handler to add to this tag handler pool */ public void reuse(Tag handler) { synchronized (this) { @@ -149,8 +146,7 @@ public class TagHandlerPool { } /** - * Calls the release() method of all available tag handlers in this tag - * handler pool. + * Calls the release() method of all available tag handlers in this tag handler pool. */ public synchronized void release() { for (int i = current; i >= 0; i--) { @@ -159,8 +155,7 @@ public class TagHandlerPool { } - protected static String getOption(ServletConfig config, String name, - String defaultV) { + protected static String getOption(ServletConfig config, String name, String defaultV) { if (config == null) { return defaultV; } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org