This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 7443c353cc Code clean-up - formatting. No functional change.
7443c353cc is described below
commit 7443c353cc937943e3834780bed5e8df97c22b94
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Mar 17 16:26:09 2025 +0000
Code clean-up - formatting. No functional change.
---
.../apache/jasper/servlet/JasperInitializer.java | 19 ++-
java/org/apache/jasper/servlet/JasperLoader.java | 44 +++----
.../apache/jasper/servlet/JspCServletContext.java | 73 +++++------
java/org/apache/jasper/servlet/JspServlet.java | 123 ++++++++-----------
.../apache/jasper/servlet/JspServletWrapper.java | 134 +++++++++------------
java/org/apache/jasper/servlet/TldPreScanned.java | 8 +-
java/org/apache/jasper/servlet/TldScanner.java | 87 +++++--------
7 files changed, 194 insertions(+), 294 deletions(-)
diff --git a/java/org/apache/jasper/servlet/JasperInitializer.java
b/java/org/apache/jasper/servlet/JasperInitializer.java
index a39f015348..9d41424d8e 100644
--- a/java/org/apache/jasper/servlet/JasperInitializer.java
+++ b/java/org/apache/jasper/servlet/JasperInitializer.java
@@ -43,8 +43,8 @@ public class JasperInitializer implements
ServletContainerInitializer {
private final Log log = LogFactory.getLog(JasperInitializer.class); //
must not be static
/*
- * Preload classes required at runtime by a JSP servlet so that
- * we don't get a defineClassInPackage security exception.
+ * Preload classes required at runtime by a JSP servlet so that we don't
get a defineClassInPackage security
+ * exception.
*/
static {
JspFactoryImpl factory = new JspFactoryImpl();
@@ -60,14 +60,12 @@ public class JasperInitializer implements
ServletContainerInitializer {
}
// Setup a simple default Instance Manager
- if (context.getAttribute(InstanceManager.class.getName())==null) {
+ if (context.getAttribute(InstanceManager.class.getName()) == null) {
context.setAttribute(InstanceManager.class.getName(), new
SimpleInstanceManager());
}
- boolean validate = Boolean.parseBoolean(
-
context.getInitParameter(Constants.XML_VALIDATION_TLD_INIT_PARAM));
- String blockExternalString = context.getInitParameter(
- Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
+ boolean validate =
Boolean.parseBoolean(context.getInitParameter(Constants.XML_VALIDATION_TLD_INIT_PARAM));
+ String blockExternalString =
context.getInitParameter(Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
boolean blockExternal;
if (blockExternalString == null) {
blockExternal = true;
@@ -89,8 +87,7 @@ public class JasperInitializer implements
ServletContainerInitializer {
}
context.setAttribute(TldCache.SERVLET_CONTEXT_ATTRIBUTE_NAME,
- new TldCache(context, scanner.getUriTldResourcePathMap(),
- scanner.getTldResourcePathTaglibXmlMap()));
+ new TldCache(context, scanner.getUriTldResourcePathMap(),
scanner.getTldResourcePathTaglibXmlMap()));
String poolSizeValue =
context.getInitParameter(Constants.JSP_FACTORY_POOL_SIZE_INIT_PARAM);
int poolSize = 8;
@@ -108,8 +105,8 @@ public class JasperInitializer implements
ServletContainerInitializer {
}
- protected TldScanner newTldScanner(ServletContext context, boolean
namespaceAware,
- boolean validate, boolean blockExternal) {
+ protected TldScanner newTldScanner(ServletContext context, boolean
namespaceAware, boolean validate,
+ boolean blockExternal) {
return new TldScanner(context, namespaceAware, validate,
blockExternal);
}
}
diff --git a/java/org/apache/jasper/servlet/JasperLoader.java
b/java/org/apache/jasper/servlet/JasperLoader.java
index d500c0aeca..2bf30b82e7 100644
--- a/java/org/apache/jasper/servlet/JasperLoader.java
+++ b/java/org/apache/jasper/servlet/JasperLoader.java
@@ -22,8 +22,8 @@ import java.net.URL;
import java.net.URLClassLoader;
/**
- * Class loader for loading servlet class files (corresponding to JSP files)
- * and tag handler class files (corresponding to tag files).
+ * Class loader for loading servlet class files (corresponding to JSP files)
and tag handler class files (corresponding
+ * to tag files).
*
* @author Anil K. Vijendran
* @author Harish Prabandham
@@ -38,9 +38,8 @@ public class JasperLoader extends URLClassLoader {
}
/**
- * Load the class with the specified name. This method searches for
- * classes in the same manner as <code>loadClass(String, boolean)</code>
- * with <code>false</code> as the second argument.
+ * Load the class with the specified name. This method searches for
classes in the same manner as
+ * <code>loadClass(String, boolean)</code> with <code>false</code> as the
second argument.
*
* @param name Name of the class to be loaded
*
@@ -52,33 +51,26 @@ public class JasperLoader extends URLClassLoader {
}
/**
- * Load the class with the specified name, searching using the following
- * algorithm until it finds and returns the class. If the class cannot
- * be found, returns <code>ClassNotFoundException</code>.
+ * Load the class with the specified name, searching using the following
algorithm until it finds and returns the
+ * class. If the class cannot be found, returns
<code>ClassNotFoundException</code>.
* <ul>
- * <li>Call <code>findLoadedClass(String)</code> to check if the
- * class has already been loaded. If it has, the same
- * <code>Class</code> object is returned.</li>
- * <li>If the <code>delegate</code> property is set to <code>true</code>,
- * call the <code>loadClass()</code> method of the parent class
- * loader, if any.</li>
- * <li>Call <code>findClass()</code> to find this class in our locally
- * defined repositories.</li>
- * <li>Call the <code>loadClass()</code> method of our parent
- * class loader, if any.</li>
+ * <li>Call <code>findLoadedClass(String)</code> to check if the class has
already been loaded. If it has, the same
+ * <code>Class</code> object is returned.</li>
+ * <li>If the <code>delegate</code> property is set to <code>true</code>,
call the <code>loadClass()</code> method
+ * of the parent class loader, if any.</li>
+ * <li>Call <code>findClass()</code> to find this class in our locally
defined repositories.</li>
+ * <li>Call the <code>loadClass()</code> method of our parent class
loader, if any.</li>
* </ul>
- * If the class was found using the above steps, and the
- * <code>resolve</code> flag is <code>true</code>, this method will then
- * call <code>resolveClass(Class)</code> on the resulting Class object.
+ * If the class was found using the above steps, and the
<code>resolve</code> flag is <code>true</code>, this method
+ * will then call <code>resolveClass(Class)</code> on the resulting Class
object.
*
- * @param name Name of the class to be loaded
+ * @param name Name of the class to be loaded
* @param resolve If <code>true</code> then resolve the class
*
* @exception ClassNotFoundException if the class was not found
*/
@Override
- public synchronized Class<?> loadClass(final String name, boolean resolve)
- throws ClassNotFoundException {
+ public synchronized Class<?> loadClass(final String name, boolean resolve)
throws ClassNotFoundException {
Class<?> clazz = null;
@@ -91,11 +83,11 @@ public class JasperLoader extends URLClassLoader {
return clazz;
}
- if( !name.startsWith(packageName + '.') ) {
+ if (!name.startsWith(packageName + '.')) {
// Class is not in org.apache.jsp, therefore, have our
// parent load it
clazz = getParent().loadClass(name);
- if( resolve ) {
+ if (resolve) {
resolveClass(clazz);
}
return clazz;
diff --git a/java/org/apache/jasper/servlet/JspCServletContext.java
b/java/org/apache/jasper/servlet/JspCServletContext.java
index c04a8c37eb..b316cbd19f 100644
--- a/java/org/apache/jasper/servlet/JspCServletContext.java
+++ b/java/org/apache/jasper/servlet/JspCServletContext.java
@@ -65,8 +65,7 @@ import org.apache.tomcat.util.scan.StandardJarScanner;
/**
- * Simple <code>ServletContext</code> implementation without
- * HTTP-specific methods.
+ * Simple <code>ServletContext</code> implementation without HTTP-specific
methods.
*
* @author Peter Rossbach ([email protected])
*/
@@ -124,21 +123,19 @@ public class JspCServletContext implements ServletContext
{
/**
* Create a new instance of this ServletContext implementation.
*
- * @param aLogWriter PrintWriter which is used for <code>log()</code> calls
+ * @param aLogWriter PrintWriter which is used for
<code>log()</code> calls
* @param aResourceBaseURL Resource base URL
- * @param classLoader Class loader for this {@link ServletContext}
- * @param validate Should a validating parser be used to parse
web.xml?
- * @param blockExternal Should external entities be blocked when parsing
- * web.xml?
+ * @param classLoader Class loader for this {@link ServletContext}
+ * @param validate Should a validating parser be used to parse
web.xml?
+ * @param blockExternal Should external entities be blocked when
parsing web.xml?
+ *
* @throws JasperException An error occurred building the merged web.xml
*/
- public JspCServletContext(PrintWriter aLogWriter, URL aResourceBaseURL,
- ClassLoader classLoader, boolean validate, boolean blockExternal)
- throws JasperException {
+ public JspCServletContext(PrintWriter aLogWriter, URL aResourceBaseURL,
ClassLoader classLoader, boolean validate,
+ boolean blockExternal) throws JasperException {
myAttributes = new HashMap<>();
- myParameters.put(Constants.XML_BLOCK_EXTERNAL_INIT_PARAM,
- String.valueOf(blockExternal));
+ myParameters.put(Constants.XML_BLOCK_EXTERNAL_INIT_PARAM,
String.valueOf(blockExternal));
myLogWriter = aLogWriter;
myResourceBaseURL = aResourceBaseURL;
this.loader = classLoader;
@@ -146,16 +143,14 @@ public class JspCServletContext implements ServletContext
{
jspConfigDescriptor = webXml.getJspConfigDescriptor();
}
- private WebXml buildMergedWebXml(boolean validate, boolean blockExternal)
- throws JasperException {
+ private WebXml buildMergedWebXml(boolean validate, boolean blockExternal)
throws JasperException {
WebXml webXml = new WebXml();
WebXmlParser webXmlParser = new WebXmlParser(validate, validate,
blockExternal);
// Use this class's classloader as Ant will have set the TCCL to its
own
webXmlParser.setClassLoader(getClass().getClassLoader());
try {
- URL url = getResource(
-
org.apache.tomcat.util.descriptor.web.Constants.WEB_XML_LOCATION);
+ URL url =
getResource(org.apache.tomcat.util.descriptor.web.Constants.WEB_XML_LOCATION);
if (!webXmlParser.parseWebXml(url, webXml, false)) {
throw new
JasperException(Localizer.getMessage("jspc.error.invalidWebXml"));
}
@@ -175,7 +170,7 @@ public class JspCServletContext implements ServletContext {
return webXml;
}
- Map<String, WebXml> fragments = scanForFragments(webXmlParser);
+ Map<String,WebXml> fragments = scanForFragments(webXmlParser);
Set<WebXml> orderedFragments = WebXml.orderWebFragments(webXml,
fragments, this);
// Find resource JARs
@@ -213,15 +208,14 @@ public class JspCServletContext implements ServletContext
{
}
- private Map<String, WebXml> scanForFragments(WebXmlParser webXmlParser)
throws JasperException {
+ private Map<String,WebXml> scanForFragments(WebXmlParser webXmlParser)
throws JasperException {
StandardJarScanner scanner = new StandardJarScanner();
// TODO - enabling this means initializing the classloader first in
JspC
scanner.setScanClassPath(false);
// TODO - configure filter rules from Ant rather then system properties
scanner.setJarScanFilter(new StandardJarScanFilter());
- FragmentJarScannerCallback callback =
- new FragmentJarScannerCallback(webXmlParser, false, true);
+ FragmentJarScannerCallback callback = new
FragmentJarScannerCallback(webXmlParser, false, true);
scanner.scan(JarScanType.PLUGGABILITY, this, callback);
if (!callback.isOk()) {
throw new
JasperException(Localizer.getMessage("jspc.error.invalidFragment"));
@@ -407,11 +401,9 @@ public class JspCServletContext implements ServletContext {
for (URL jarUrl : resourceJARs) {
try (Jar jar = JarFactory.newInstance(jarUrl)) {
jar.nextEntry();
- for (String entryName = jar.getEntryName();
- entryName != null;
- jar.nextEntry(), entryName = jar.getEntryName()) {
- if (entryName.startsWith(jarPath) &&
- entryName.length() > jarPath.length()) {
+ for (String entryName = jar.getEntryName(); entryName !=
null; jar.nextEntry(), entryName =
+ jar.getEntryName()) {
+ if (entryName.startsWith(jarPath) &&
entryName.length() > jarPath.length()) {
// Let the Set implementation handle duplicates
int sep = entryName.indexOf('/', jarPath.length());
if (sep < 0) {
@@ -471,15 +463,13 @@ public class JspCServletContext implements ServletContext
{
@Override
- public FilterRegistration.Dynamic addFilter(String filterName,
- String className) {
+ public FilterRegistration.Dynamic addFilter(String filterName, String
className) {
return null;
}
@Override
- public ServletRegistration.Dynamic addServlet(String servletName,
- String className) {
+ public ServletRegistration.Dynamic addServlet(String servletName, String
className) {
return null;
}
@@ -503,8 +493,7 @@ public class JspCServletContext implements ServletContext {
@Override
- public void setSessionTrackingModes(
- Set<SessionTrackingMode> sessionTrackingModes) {
+ public void setSessionTrackingModes(Set<SessionTrackingMode>
sessionTrackingModes) {
// Do nothing
}
@@ -516,22 +505,19 @@ public class JspCServletContext implements ServletContext
{
@Override
- public Dynamic addFilter(String filterName,
- Class<? extends Filter> filterClass) {
+ public Dynamic addFilter(String filterName, Class<? extends Filter>
filterClass) {
return null;
}
@Override
- public ServletRegistration.Dynamic addServlet(String servletName,
- Servlet servlet) {
+ public ServletRegistration.Dynamic addServlet(String servletName, Servlet
servlet) {
return null;
}
@Override
- public ServletRegistration.Dynamic addServlet(String servletName,
- Class<? extends Servlet> servletClass) {
+ public ServletRegistration.Dynamic addServlet(String servletName, Class<?
extends Servlet> servletClass) {
return null;
}
@@ -543,15 +529,13 @@ public class JspCServletContext implements ServletContext
{
@Override
- public <T extends Filter> T createFilter(Class<T> c)
- throws ServletException {
+ public <T extends Filter> T createFilter(Class<T> c) throws
ServletException {
return null;
}
@Override
- public <T extends Servlet> T createServlet(Class<T> c)
- throws ServletException {
+ public <T extends Servlet> T createServlet(Class<T> c) throws
ServletException {
return null;
}
@@ -593,8 +577,7 @@ public class JspCServletContext implements ServletContext {
@Override
- public <T extends EventListener> T createListener(Class<T> c)
- throws ServletException {
+ public <T extends EventListener> T createListener(Class<T> c) throws
ServletException {
return null;
}
@@ -624,7 +607,7 @@ public class JspCServletContext implements ServletContext {
@Override
- public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
+ public Map<String,? extends FilterRegistration> getFilterRegistrations() {
return null;
}
@@ -636,7 +619,7 @@ public class JspCServletContext implements ServletContext {
@Override
- public Map<String, ? extends ServletRegistration>
getServletRegistrations() {
+ public Map<String,? extends ServletRegistration> getServletRegistrations()
{
return null;
}
diff --git a/java/org/apache/jasper/servlet/JspServlet.java
b/java/org/apache/jasper/servlet/JspServlet.java
index 3fd33a20f2..196b21af4f 100644
--- a/java/org/apache/jasper/servlet/JspServlet.java
+++ b/java/org/apache/jasper/servlet/JspServlet.java
@@ -40,14 +40,10 @@ import org.apache.tomcat.PeriodicEventListener;
import org.apache.tomcat.util.security.Escape;
/**
- * The JSP engine (a.k.a Jasper).
- *
- * The servlet container is responsible for providing a
- * URLClassLoader for the web application context Jasper
- * is being used in. Jasper will try get the Tomcat
- * ServletContext attribute for its ServletContext class
- * loader, if that fails, it uses the parent class loader.
- * In either case, it must be a URLClassLoader.
+ * The JSP engine (a.k.a Jasper). The servlet container is responsible for
providing a URLClassLoader for the web
+ * application context Jasper is being used in. Jasper will try get the Tomcat
ServletContext attribute for its
+ * ServletContext class loader, if that fails, it uses the parent class
loader. In either case, it must be a
+ * URLClassLoader.
*
* @author Anil K. Vijendran
* @author Harish Prabandham
@@ -120,22 +116,19 @@ public class JspServlet extends HttpServlet implements
PeriodicEventListener {
}
if (log.isDebugEnabled()) {
- log.debug(Localizer.getMessage("jsp.message.scratch.dir.is",
- options.getScratchDir().toString()));
+ log.debug(Localizer.getMessage("jsp.message.scratch.dir.is",
options.getScratchDir().toString()));
log.debug(Localizer.getMessage("jsp.message.dont.modify.servlets"));
}
}
/**
- * Returns the number of JSPs for which JspServletWrappers exist, i.e.,
- * the number of JSPs that have been loaded into the webapp with which
- * this JspServlet is associated.
- *
- * <p>This info may be used for monitoring purposes.
+ * Returns the number of JSPs for which JspServletWrappers exist, i.e.,
the number of JSPs that have been loaded
+ * into the webapp with which this JspServlet is associated.
+ * <p>
+ * This info may be used for monitoring purposes.
*
- * @return The number of JSPs that have been loaded into the webapp with
- * which this JspServlet is associated
+ * @return The number of JSPs that have been loaded into the webapp with
which this JspServlet is associated
*/
public int getJspCount() {
return this.rctxt.getJspCount();
@@ -154,11 +147,10 @@ public class JspServlet extends HttpServlet implements
PeriodicEventListener {
/**
* Gets the number of JSPs that have been reloaded.
+ * <p>
+ * This info may be used for monitoring purposes.
*
- * <p>This info may be used for monitoring purposes.
- *
- * @return The number of JSPs (in the webapp with which this JspServlet is
- * associated) that have been reloaded
+ * @return The number of JSPs (in the webapp with which this JspServlet is
associated) that have been reloaded
*/
public int getJspReloadCount() {
return this.rctxt.getJspReloadCount();
@@ -167,11 +159,11 @@ public class JspServlet extends HttpServlet implements
PeriodicEventListener {
/**
* Gets the number of JSPs that are in the JSP limiter queue
+ * <p>
+ * This info may be used for monitoring purposes.
*
- * <p>This info may be used for monitoring purposes.
- *
- * @return The number of JSPs (in the webapp with which this JspServlet is
- * associated) that are in the JSP limiter queue
+ * @return The number of JSPs (in the webapp with which this JspServlet is
associated) that are in the JSP limiter
+ * queue
*/
public int getJspQueueLength() {
return this.rctxt.getJspQueueLength();
@@ -180,11 +172,10 @@ public class JspServlet extends HttpServlet implements
PeriodicEventListener {
/**
* Gets the number of JSPs that have been unloaded.
+ * <p>
+ * This info may be used for monitoring purposes.
*
- * <p>This info may be used for monitoring purposes.
- *
- * @return The number of JSPs (in the webapp with which this JspServlet is
- * associated) that have been unloaded
+ * @return The number of JSPs (in the webapp with which this JspServlet is
associated) that have been unloaded
*/
public int getJspUnloadCount() {
return this.rctxt.getJspUnloadCount();
@@ -192,17 +183,17 @@ public class JspServlet extends HttpServlet implements
PeriodicEventListener {
/**
- * <p>Look for a <em>precompilation request</em> as described in
- * Section 8.4.2 of the JSP 1.2 Specification. <strong>WARNING</strong> -
- * we cannot use <code>request.getParameter()</code> for this, because
- * that will trigger parsing all of the request parameters, and not give
- * a servlet the opportunity to call
- * <code>request.setCharacterEncoding()</code> first.</p>
+ * <p>
+ * Look for a <em>precompilation request</em> as described in Section
8.4.2 of the JSP 1.2 Specification.
+ * <strong>WARNING</strong> - we cannot use
<code>request.getParameter()</code> for this, because that will trigger
+ * parsing all of the request parameters, and not give a servlet the
opportunity to call
+ * <code>request.setCharacterEncoding()</code> first.
+ * </p>
*
* @param request The servlet request we are processing
*
- * @exception ServletException if an invalid parameter value for the
- * <code>jsp_precompile</code> parameter name is specified
+ * @exception ServletException if an invalid parameter value for the
<code>jsp_precompile</code> parameter name is
+ * specified
*/
boolean preCompile(HttpServletRequest request) throws ServletException {
@@ -215,16 +206,15 @@ public class JspServlet extends HttpServlet implements
PeriodicEventListener {
if (start < 0) {
return false;
}
- queryString =
- queryString.substring(start + precompileParameter.length());
+ queryString = queryString.substring(start +
precompileParameter.length());
if (queryString.length() == 0) {
- return true; // ?jsp_precompile
+ return true; // ?jsp_precompile
}
if (queryString.startsWith("&")) {
- return true; // ?jsp_precompile&foo=bar...
+ return true; // ?jsp_precompile&foo=bar...
}
if (!queryString.startsWith("=")) {
- return false; // part of some other name or value
+ return false; // part of some other name or value
}
int limit = queryString.length();
int ampersand = queryString.indexOf('&');
@@ -233,51 +223,45 @@ public class JspServlet extends HttpServlet implements
PeriodicEventListener {
}
String value = queryString.substring(1, limit);
if (value.equals("true")) {
- return true; // ?jsp_precompile=true
+ return true; // ?jsp_precompile=true
} else if (value.equals("false")) {
// Spec says if jsp_precompile=false, the request should not
// be delivered to the JSP page; the easiest way to implement
// this is to set the flag to true, and precompile the page anyway.
// This still conforms to the spec, since it says the
// precompilation request can be ignored.
- return true; // ?jsp_precompile=false
+ return true; // ?jsp_precompile=false
} else {
- throw new
ServletException(Localizer.getMessage("jsp.error.precompilation.parameter",
- precompileParameter, value));
+ throw new ServletException(
+ Localizer.getMessage("jsp.error.precompilation.parameter",
precompileParameter, value));
}
}
@Override
- public void service (HttpServletRequest request, HttpServletResponse
response)
- throws ServletException, IOException {
+ public void service(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// jspFile may be configured as an init-param for this servlet instance
String jspUri = jspFile;
if (jspUri == null) {
/*
- * Check to see if the requested JSP has been the target of a
- * RequestDispatcher.include()
+ * Check to see if the requested JSP has been the target of a
RequestDispatcher.include()
*/
- jspUri = (String) request.getAttribute(
- RequestDispatcher.INCLUDE_SERVLET_PATH);
+ jspUri = (String)
request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
if (jspUri != null) {
/*
- * Requested JSP has been target of
- * RequestDispatcher.include(). Its path is assembled from the
- * relevant jakarta.servlet.include.* request attributes
+ * Requested JSP has been target of
RequestDispatcher.include(). Its path is assembled from the relevant
+ * jakarta.servlet.include.* request attributes
*/
- String pathInfo = (String) request.getAttribute(
- RequestDispatcher.INCLUDE_PATH_INFO);
+ String pathInfo = (String)
request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
if (pathInfo != null) {
jspUri += pathInfo;
}
} else {
/*
- * Requested JSP has not been the target of a
- * RequestDispatcher.include(). Reconstruct its path from the
+ * Requested JSP has not been the target of a
RequestDispatcher.include(). Reconstruct its path from the
* request's getServletPath() and getPathInfo()
*/
jspUri = request.getServletPath();
@@ -327,14 +311,12 @@ public class JspServlet extends HttpServlet implements
PeriodicEventListener {
// -------------------------------------------------------- Private Methods
- private void serviceJspFile(HttpServletRequest request,
- HttpServletResponse response, String jspUri,
- boolean precompile)
- throws ServletException, IOException {
+ private void serviceJspFile(HttpServletRequest request,
HttpServletResponse response, String jspUri,
+ boolean precompile) throws ServletException, IOException {
JspServletWrapper wrapper = rctxt.getWrapper(jspUri);
if (wrapper == null) {
- synchronized(this) {
+ synchronized (this) {
wrapper = rctxt.getWrapper(jspUri);
if (wrapper == null) {
// Check if the requested JSP page exists, to avoid
@@ -343,9 +325,8 @@ public class JspServlet extends HttpServlet implements
PeriodicEventListener {
handleMissingResource(request, response, jspUri);
return;
}
- wrapper = new JspServletWrapper(config, options, jspUri,
- rctxt);
- rctxt.addWrapper(jspUri,wrapper);
+ wrapper = new JspServletWrapper(config, options, jspUri,
rctxt);
+ rctxt.addWrapper(jspUri, wrapper);
}
}
}
@@ -359,14 +340,12 @@ public class JspServlet extends HttpServlet implements
PeriodicEventListener {
}
- private void handleMissingResource(HttpServletRequest request,
- HttpServletResponse response, String jspUri)
+ private void handleMissingResource(HttpServletRequest request,
HttpServletResponse response, String jspUri)
throws ServletException, IOException {
- String includeRequestUri =
-
(String)request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);
+ String includeRequestUri = (String)
request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);
- String msg = Localizer.getMessage("jsp.error.file.not.found",jspUri);
+ String msg = Localizer.getMessage("jsp.error.file.not.found", jspUri);
if (includeRequestUri != null) {
// This file was included. Throw an exception as
// a response.sendError() will be ignored
diff --git a/java/org/apache/jasper/servlet/JspServletWrapper.java
b/java/org/apache/jasper/servlet/JspServletWrapper.java
index b2f53cfe28..f2a35dbff2 100644
--- a/java/org/apache/jasper/servlet/JspServletWrapper.java
+++ b/java/org/apache/jasper/servlet/JspServletWrapper.java
@@ -49,14 +49,10 @@ import org.apache.tomcat.InstanceManager;
import org.apache.tomcat.Jar;
/**
- * The JSP engine (a.k.a Jasper).
- *
- * The servlet container is responsible for providing a
- * URLClassLoader for the web application context Jasper
- * is being used in. Jasper will try get the Tomcat
- * ServletContext attribute for its ServletContext class
- * loader, if that fails, it uses the parent class loader.
- * In either case, it must be a URLClassLoader.
+ * The JSP engine (a.k.a Jasper). The servlet container is responsible for
providing a URLClassLoader for the web
+ * application context Jasper is being used in. Jasper will try get the Tomcat
ServletContext attribute for its
+ * ServletContext class loader, if that fails, it uses the parent class
loader. In either case, it must be a
+ * URLClassLoader.
*
* @author Anil K. Vijendran
* @author Harish Prabandham
@@ -67,8 +63,7 @@ import org.apache.tomcat.Jar;
*/
public class JspServletWrapper {
- private static final Map<String,Long> ALWAYS_OUTDATED_DEPENDENCIES =
- new HashMap<>();
+ private static final Map<String,Long> ALWAYS_OUTDATED_DEPENDENCIES = new
HashMap<>();
static {
// If this is missing,
@@ -86,11 +81,9 @@ public class JspServletWrapper {
private final ServletConfig config;
private final Options options;
/*
- * The servlet / tag file needs a compilation check on first access. Use a
- * separate flag (rather then theServlet == null / tagHandlerClass == null
- * as it avoids the potentially expensive isOutDated() calls in
- * ctxt.compile() if there are multiple concurrent requests for the servlet
- * / tag before the class has been loaded.
+ * The servlet / tag file needs a compilation check on first access. Use a
separate flag (rather then theServlet ==
+ * null / tagHandlerClass == null as it avoids the potentially expensive
isOutDated() calls in ctxt.compile() if
+ * there are multiple concurrent requests for the servlet / tag before the
class has been loaded.
*/
private volatile boolean mustCompile = true;
/* Whether the servlet/tag file needs reloading on next access */
@@ -110,8 +103,7 @@ public class JspServletWrapper {
/*
* JspServletWrapper for JSP pages.
*/
- public JspServletWrapper(ServletConfig config, Options options,
- String jspUri, JspRuntimeContext rctxt) {
+ public JspServletWrapper(ServletConfig config, Options options, String
jspUri, JspRuntimeContext rctxt) {
this.isTagFile = false;
this.config = config;
@@ -120,32 +112,24 @@ public class JspServletWrapper {
unloadByCount = options.getMaxLoadedJsps() > 0 ? true : false;
unloadByIdle = options.getJspIdleTimeout() > 0 ? true : false;
unloadAllowed = unloadByCount || unloadByIdle ? true : false;
- ctxt = new JspCompilationContext(jspUri, options,
- config.getServletContext(),
- this, rctxt);
+ ctxt = new JspCompilationContext(jspUri, options,
config.getServletContext(), this, rctxt);
}
/*
* JspServletWrapper for tag files.
*/
- public JspServletWrapper(ServletContext servletContext,
- Options options,
- String tagFilePath,
- TagInfo tagInfo,
- JspRuntimeContext rctxt,
- Jar tagJar) {
+ public JspServletWrapper(ServletContext servletContext, Options options,
String tagFilePath, TagInfo tagInfo,
+ JspRuntimeContext rctxt, Jar tagJar) {
this.isTagFile = true;
- this.config = null; // not used
+ this.config = null; // not used
this.options = options;
this.jspUri = tagFilePath;
this.tripCount = 0;
unloadByCount = options.getMaxLoadedJsps() > 0 ? true : false;
unloadByIdle = options.getJspIdleTimeout() > 0 ? true : false;
unloadAllowed = unloadByCount || unloadByIdle ? true : false;
- ctxt = new JspCompilationContext(jspUri, tagInfo, options,
- servletContext, this, rctxt,
- tagJar);
+ ctxt = new JspCompilationContext(jspUri, tagInfo, options,
servletContext, this, rctxt, tagJar);
}
public JspCompilationContext getJspEngineContext() {
@@ -166,13 +150,11 @@ public class JspServletWrapper {
public Servlet getServlet() throws ServletException {
/*
- * DCL on 'reload' requires that 'reload' be volatile
- * (this also forces a read memory barrier, ensuring the new servlet
- * object is read consistently).
+ * DCL on 'reload' requires that 'reload' be volatile (this also
forces a read memory barrier, ensuring the new
+ * servlet object is read consistently).
*
- * When running in non development mode with a checkInterval it is
- * possible (see BZ 62603) for a race condition to cause failures
- * if a Servlet or tag is reloaded while a compile check is running
+ * When running in non development mode with a checkInterval it is
possible (see BZ 62603) for a race condition
+ * to cause failures if a Servlet or tag is reloaded while a compile
check is running
*/
if (getReloadInternal() || theServlet == null) {
synchronized (this) {
@@ -188,8 +170,7 @@ public class JspServletWrapper {
InstanceManager instanceManager =
InstanceManagerFactory.getInstanceManager(config);
servlet = (Servlet)
instanceManager.newInstance(ctxt.getFQCN(), ctxt.getJspLoader());
} catch (Exception e) {
- Throwable t = ExceptionUtils
- .unwrapInvocationTargetException(e);
+ Throwable t =
ExceptionUtils.unwrapInvocationTargetException(e);
ExceptionUtils.handleThrowable(t);
throw new JasperException(t);
}
@@ -223,8 +204,7 @@ public class JspServletWrapper {
}
/**
- * Sets the last-modified time of the servlet class file associated with
- * this JspServletWrapper.
+ * Sets the last-modified time of the servlet class file associated with
this JspServletWrapper.
*
* @param lastModified Last-modified time of servlet class
*/
@@ -242,7 +222,7 @@ public class JspServletWrapper {
// a new loader will be created which will load the new
// class.
// TODO Are there inefficiencies between reload and the
- // isOutDated() check?
+ // isOutDated() check?
ctxt.clearJspLoader();
}
}
@@ -251,7 +231,9 @@ public class JspServletWrapper {
/**
* Compile (if needed) and load a tag file.
+ *
* @return the loaded class
+ *
* @throws JasperException Error compiling or loading tag file
*/
public Class<?> loadTagFile() throws JasperException {
@@ -290,11 +272,11 @@ public class JspServletWrapper {
}
/**
- * Compile and load a prototype for the Tag file. This is needed
- * when compiling tag files with circular dependencies. A prototype
- * (skeleton) with no dependencies on other other tag files is
- * generated and compiled.
+ * Compile and load a prototype for the Tag file. This is needed when
compiling tag files with circular
+ * dependencies. A prototype (skeleton) with no dependencies on other
other tag files is generated and compiled.
+ *
* @return the loaded class
+ *
* @throws JasperException Error compiling or loading tag file
*/
public Class<?> loadTagFilePrototype() throws JasperException {
@@ -309,6 +291,7 @@ public class JspServletWrapper {
/**
* Get a list of files that the current page has source dependency on.
+ *
* @return the map of dependent resources
*/
public Map<String,Long> getDependants() {
@@ -360,9 +343,7 @@ public class JspServletWrapper {
return unloadHandle;
}
- public void service(HttpServletRequest request,
- HttpServletResponse response,
- boolean precompile)
+ public void service(HttpServletRequest request, HttpServletResponse
response, boolean precompile)
throws ServletException, IOException, FileNotFoundException {
Servlet servlet;
@@ -376,9 +357,8 @@ public class JspServletWrapper {
if ((available > 0L) && (available < Long.MAX_VALUE)) {
if (available > System.currentTimeMillis()) {
response.setDateHeader("Retry-After", available);
- response.sendError
- (HttpServletResponse.SC_SERVICE_UNAVAILABLE,
- Localizer.getMessage("jsp.error.unavailable"));
+
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
+ Localizer.getMessage("jsp.error.unavailable"));
return;
}
@@ -434,7 +414,7 @@ public class JspServletWrapper {
* (3) Handle limitation of number of loaded Jsps
*/
if (unloadAllowed) {
- synchronized(this) {
+ synchronized (this) {
if (unloadByCount) {
if (unloadHandle == null) {
unloadHandle = ctxt.getRuntimeContext().push(this);
@@ -455,8 +435,7 @@ public class JspServletWrapper {
*/
servlet.service(request, response);
} catch (UnavailableException ex) {
- String includeRequestUri = (String)
- request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);
+ String includeRequestUri = (String)
request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);
if (includeRequestUri != null) {
// This file was included. Throw an exception as
// a response.sendError() will be ignored by the
@@ -466,15 +445,12 @@ public class JspServletWrapper {
int unavailableSeconds = ex.getUnavailableSeconds();
if (unavailableSeconds <= 0) {
- unavailableSeconds = 60; // Arbitrary default
+ unavailableSeconds = 60; // Arbitrary default
}
- available = System.currentTimeMillis() +
- (unavailableSeconds * 1000L);
- response.sendError
- (HttpServletResponse.SC_SERVICE_UNAVAILABLE,
- ex.getMessage());
+ available = System.currentTimeMillis() + (unavailableSeconds *
1000L);
+ response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
ex.getMessage());
} catch (ServletException | IllegalStateException ex) {
- if(options.getDevelopment()) {
+ if (options.getDevelopment()) {
throw handleJspException(ex);
}
throw ex;
@@ -484,7 +460,7 @@ public class JspServletWrapper {
}
throw ex;
} catch (Exception ex) {
- if(options.getDevelopment()) {
+ if (options.getDevelopment()) {
throw handleJspException(ex);
}
throw new JasperException(ex);
@@ -506,8 +482,7 @@ public class JspServletWrapper {
Throwable t =
ExceptionUtils.unwrapInvocationTargetException(e);
ExceptionUtils.handleThrowable(t);
// Log any exception, since it can't be passed along
- log.error(Localizer.getMessage("jsp.error.file.not.found",
- e.getMessage()), t);
+ log.error(Localizer.getMessage("jsp.error.file.not.found",
e.getMessage()), t);
}
}
}
@@ -518,6 +493,7 @@ public class JspServletWrapper {
public long getLastModificationTest() {
return lastModificationTest;
}
+
/**
* @param lastModificationTest The lastModificationTest to set.
*/
@@ -533,16 +509,16 @@ public class JspServletWrapper {
}
/**
- * <p>Attempts to construct a JasperException that contains helpful
information
- * about what went wrong. Uses the JSP compiler system to translate the
line
- * number in the generated servlet that originated the exception to a line
- * number in the JSP. Then constructs an exception containing that
- * information, and a snippet of the JSP to help debugging.
- * Please see https://bz.apache.org/bugzilla/show_bug.cgi?id=37062 and
- * http://www.tfenne.com/jasper/ for more details.
+ * <p>
+ * Attempts to construct a JasperException that contains helpful
information about what went wrong. Uses the JSP
+ * compiler system to translate the line number in the generated servlet
that originated the exception to a line
+ * number in the JSP. Then constructs an exception containing that
information, and a snippet of the JSP to help
+ * debugging. Please see
https://bz.apache.org/bugzilla/show_bug.cgi?id=37062 and
http://www.tfenne.com/jasper/ for
+ * more details.
* </p>
*
* @param ex the exception that was the cause of the problem.
+ *
* @return a JasperException with more detailed information
*/
protected JasperException handleJspException(Exception ex) {
@@ -592,18 +568,16 @@ public class JspServletWrapper {
source.getFileName(), source.getLineNumber(), null, ctxt);
if (options.getDisplaySourceFragment()) {
- return new JasperException(Localizer.getMessage
- ("jsp.exception", detail.getJspFileName(),
- "" + source.getLineNumber()) +
System.lineSeparator() +
- System.lineSeparator() +
detail.getJspExtract() +
- System.lineSeparator() +
System.lineSeparator() +
- "Stacktrace:", ex);
+ return new JasperException(
+ Localizer.getMessage("jsp.exception",
detail.getJspFileName(), "" + source.getLineNumber()) +
+ System.lineSeparator() +
System.lineSeparator() + detail.getJspExtract() +
+ System.lineSeparator() +
System.lineSeparator() + "Stacktrace:",
+ ex);
}
- return new JasperException(Localizer.getMessage
- ("jsp.exception", detail.getJspFileName(),
- "" + source.getLineNumber()), ex);
+ return new JasperException(
+ Localizer.getMessage("jsp.exception",
detail.getJspFileName(), "" + source.getLineNumber()), ex);
} catch (Exception je) {
// If anything goes wrong, just revert to the original behaviour
if (ex instanceof JasperException) {
diff --git a/java/org/apache/jasper/servlet/TldPreScanned.java
b/java/org/apache/jasper/servlet/TldPreScanned.java
index 84de9c44e8..5638862de9 100644
--- a/java/org/apache/jasper/servlet/TldPreScanned.java
+++ b/java/org/apache/jasper/servlet/TldPreScanned.java
@@ -29,19 +29,19 @@ public class TldPreScanned extends TldScanner {
private final Collection<URL> preScannedURLs;
- public TldPreScanned (ServletContext context, boolean namespaceAware,
boolean validation,
- boolean blockExternal, Collection<URL> preScannedTlds) {
+ public TldPreScanned(ServletContext context, boolean namespaceAware,
boolean validation, boolean blockExternal,
+ Collection<URL> preScannedTlds) {
super(context, namespaceAware, validation, blockExternal);
preScannedURLs = preScannedTlds;
}
@Override
public void scanJars() {
- for (URL url : preScannedURLs){
+ for (URL url : preScannedURLs) {
String str = url.toExternalForm();
int a = str.indexOf("jar:");
int b = str.indexOf("!/");
- if (a >= 0 && b> 0) {
+ if (a >= 0 && b > 0) {
String fileUrl = str.substring(a + 4, b);
String path = str.substring(b + 2);
try {
diff --git a/java/org/apache/jasper/servlet/TldScanner.java
b/java/org/apache/jasper/servlet/TldScanner.java
index e20be33b3c..03081b9316 100644
--- a/java/org/apache/jasper/servlet/TldScanner.java
+++ b/java/org/apache/jasper/servlet/TldScanner.java
@@ -59,26 +59,20 @@ public class TldScanner {
private static final String WEB_INF = "/WEB-INF/";
private final ServletContext context;
private final TldParser tldParser;
- private final Map<String, TldResourcePath> uriTldResourcePathMap = new
HashMap<>();
- private final Map<TldResourcePath, TaglibXml> tldResourcePathTaglibXmlMap
= new HashMap<>();
+ private final Map<String,TldResourcePath> uriTldResourcePathMap = new
HashMap<>();
+ private final Map<TldResourcePath,TaglibXml> tldResourcePathTaglibXmlMap =
new HashMap<>();
private final List<String> listeners = new ArrayList<>();
/**
* Initialise with the application's ServletContext.
*
* @param context the application's servletContext
- * @param namespaceAware should the XML parser used to parse TLD files be
- * configured to be name space aware
- * @param validation should the XML parser used to parse TLD files be
- * configured to use validation
- * @param blockExternal should the XML parser used to parse TLD files be
- * configured to be block references to external
- * entities
+ * @param namespaceAware should the XML parser used to parse TLD files be
configured to be name space aware
+ * @param validation should the XML parser used to parse TLD files be
configured to use validation
+ * @param blockExternal should the XML parser used to parse TLD files be
configured to be block references to
+ * external entities
*/
- public TldScanner(ServletContext context,
- boolean namespaceAware,
- boolean validation,
- boolean blockExternal) {
+ public TldScanner(ServletContext context, boolean namespaceAware, boolean
validation, boolean blockExternal) {
this.context = context;
this.tldParser = new TldParser(namespaceAware, validation,
blockExternal);
@@ -109,13 +103,12 @@ public class TldScanner {
*
* @return the map of URI to TldResourcePath
*/
- public Map<String, TldResourcePath> getUriTldResourcePathMap() {
+ public Map<String,TldResourcePath> getUriTldResourcePathMap() {
return uriTldResourcePathMap;
}
/**
- * Returns the map of TldResourcePath to parsed XML files built by this
- * scanner.
+ * Returns the map of TldResourcePath to parsed XML files built by this
scanner.
*
* @return the map of TldResourcePath to parsed XML files
*/
@@ -133,11 +126,10 @@ public class TldScanner {
}
/**
- * Set the class loader used by the digester to create objects as a result
- * of this scan. Normally this only needs to be set when using JspC.
+ * Set the class loader used by the digester to create objects as a result
of this scan. Normally this only needs to
+ * be set when using JspC.
*
- * @param classLoader Class loader to use when creating new objects while
- * parsing TLDs
+ * @param classLoader Class loader to use when creating new objects while
parsing TLDs
*/
public void setClassLoader(ClassLoader classLoader) {
tldParser.setClassLoader(classLoader);
@@ -151,7 +143,8 @@ public class TldScanner {
/**
* Scan for TLDs defined in <jsp-config>.
- * @throws IOException Error reading resources
+ *
+ * @throws IOException Error reading resources
* @throws SAXException XML parsing error
*/
protected void scanJspConfig() throws IOException, SAXException {
@@ -172,16 +165,12 @@ public class TldScanner {
resourcePath = WEB_INF + resourcePath;
}
if (uriTldResourcePathMap.containsKey(taglibURI)) {
- log.warn(Localizer.getMessage(MSG + ".webxmlSkip",
- resourcePath,
- taglibURI));
+ log.warn(Localizer.getMessage(MSG + ".webxmlSkip",
resourcePath, taglibURI));
continue;
}
if (log.isTraceEnabled()) {
- log.trace(Localizer.getMessage(MSG + ".webxmlAdd",
- resourcePath,
- taglibURI));
+ log.trace(Localizer.getMessage(MSG + ".webxmlAdd",
resourcePath, taglibURI));
}
URL url = context.getResource(resourcePath);
@@ -202,9 +191,7 @@ public class TldScanner {
listeners.addAll(tld.getListeners());
}
} else {
- log.warn(Localizer.getMessage(MSG +
".webxmlFailPathDoesNotExist",
- resourcePath,
- taglibURI));
+ log.warn(Localizer.getMessage(MSG +
".webxmlFailPathDoesNotExist", resourcePath, taglibURI));
continue;
}
}
@@ -214,11 +201,11 @@ public class TldScanner {
* Scan web application resources for TLDs, recursively.
*
* @param startPath the directory resource to scan
+ *
* @throws IOException if there was a problem scanning for or loading a
TLD
* @throws SAXException if there was a problem parsing a TLD
*/
- protected void scanResourcePaths(String startPath)
- throws IOException, SAXException {
+ protected void scanResourcePaths(String startPath) throws IOException,
SAXException {
boolean found = false;
Set<String> dirList = context.getResourcePaths(startPath);
@@ -266,8 +253,7 @@ public class TldScanner {
}
protected void parseTld(String resourcePath) throws IOException,
SAXException {
- TldResourcePath tldResourcePath =
- new TldResourcePath(context.getResource(resourcePath),
resourcePath);
+ TldResourcePath tldResourcePath = new
TldResourcePath(context.getResource(resourcePath), resourcePath);
parseTld(tldResourcePath);
}
@@ -301,16 +287,13 @@ public class TldScanner {
boolean found = false;
URL jarFileUrl = jar.getJarFileURL();
jar.nextEntry();
- for (String entryName = jar.getEntryName();
- entryName != null;
- jar.nextEntry(), entryName = jar.getEntryName()) {
- if (!(entryName.startsWith("META-INF/") &&
- entryName.endsWith(TLD_EXT))) {
+ for (String entryName = jar.getEntryName(); entryName != null;
jar.nextEntry(), entryName =
+ jar.getEntryName()) {
+ if (!(entryName.startsWith("META-INF/") &&
entryName.endsWith(TLD_EXT))) {
continue;
}
found = true;
- TldResourcePath tldResourcePath =
- new TldResourcePath(jarFileUrl, webappPath, entryName);
+ TldResourcePath tldResourcePath = new
TldResourcePath(jarFileUrl, webappPath, entryName);
try {
parseTld(tldResourcePath);
} catch (SAXException e) {
@@ -324,15 +307,13 @@ public class TldScanner {
} else {
foundJarWithoutTld = true;
if (log.isDebugEnabled()) {
- log.debug(Localizer.getMessage(
- "jsp.tldCache.noTldInJar", jarFileUrl.toString()));
+ log.debug(Localizer.getMessage("jsp.tldCache.noTldInJar",
jarFileUrl.toString()));
}
}
}
@Override
- public void scan(File file, final String webappPath, boolean isWebapp)
- throws IOException {
+ public void scan(File file, final String webappPath, boolean isWebapp)
throws IOException {
File metaInf = new File(file, "META-INF");
if (!metaInf.isDirectory()) {
return;
@@ -341,12 +322,9 @@ public class TldScanner {
final Path filePath = file.toPath();
Files.walkFileTree(metaInf.toPath(), new SimpleFileVisitor<Path>()
{
@Override
- public FileVisitResult visitFile(Path file,
- BasicFileAttributes attrs)
- throws IOException {
+ public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
Path fileName = file.getFileName();
- if (fileName == null || !fileName.toString().toLowerCase(
- Locale.ENGLISH).endsWith(TLD_EXT)) {
+ if (fileName == null ||
!fileName.toString().toLowerCase(Locale.ENGLISH).endsWith(TLD_EXT)) {
return FileVisitResult.CONTINUE;
}
@@ -355,8 +333,7 @@ public class TldScanner {
if (webappPath == null) {
resourcePath = null;
} else {
- String subPath = file.subpath(
- filePath.getNameCount(),
file.getNameCount()).toString();
+ String subPath = file.subpath(filePath.getNameCount(),
file.getNameCount()).toString();
if ('/' != File.separatorChar) {
subPath = subPath.replace(File.separatorChar, '/');
}
@@ -375,13 +352,11 @@ public class TldScanner {
});
if (foundFileWithoutTld) {
if (log.isDebugEnabled()) {
- log.debug(Localizer.getMessage("jsp.tldCache.tldInDir",
- file.getAbsolutePath()));
+ log.debug(Localizer.getMessage("jsp.tldCache.tldInDir",
file.getAbsolutePath()));
}
} else {
if (log.isDebugEnabled()) {
- log.debug(Localizer.getMessage("jsp.tldCache.noTldInDir",
- file.getAbsolutePath()));
+ log.debug(Localizer.getMessage("jsp.tldCache.noTldInDir",
file.getAbsolutePath()));
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]