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
commit e27240ee2b453fd594492d21afb15a401ce01c0d Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Mar 20 15:12:31 2025 +0000 Code clean-up - formatting. No functional change. --- java/org/apache/jasper/Constants.java | 37 +- java/org/apache/jasper/EmbeddedServletOptions.java | 84 ++--- java/org/apache/jasper/JasperException.java | 10 +- java/org/apache/jasper/JspC.java | 419 +++++++++------------ java/org/apache/jasper/JspCompilationContext.java | 174 ++++----- java/org/apache/jasper/Options.java | 142 +++---- 6 files changed, 377 insertions(+), 489 deletions(-) diff --git a/java/org/apache/jasper/Constants.java b/java/org/apache/jasper/Constants.java index efed51e648..9cf3b4fc38 100644 --- a/java/org/apache/jasper/Constants.java +++ b/java/org/apache/jasper/Constants.java @@ -33,16 +33,12 @@ public class Constants { public static final String SPEC_VERSION = "4.0"; /** - * These classes/packages are automatically imported by the - * generated code. + * These classes/packages are automatically imported by the generated code. */ - private static final String[] PRIVATE_STANDARD_IMPORTS = { - "jakarta.servlet.*", - "jakarta.servlet.http.*", - "jakarta.servlet.jsp.*" - }; + private static final String[] PRIVATE_STANDARD_IMPORTS = + { "jakarta.servlet.*", "jakarta.servlet.http.*", "jakarta.servlet.jsp.*" }; public static final List<String> STANDARD_IMPORTS = - Collections.unmodifiableList(Arrays.asList(PRIVATE_STANDARD_IMPORTS)); + Collections.unmodifiableList(Arrays.asList(PRIVATE_STANDARD_IMPORTS)); /** * Default size of the JSP buffer. @@ -60,36 +56,31 @@ public class Constants { public static final int MAX_POOL_SIZE = 5; /** - * Name of the system property containing - * the tomcat product installation path + * Name of the system property containing the tomcat product installation path */ public static final String CATALINA_HOME_PROP = "catalina.home"; /** - * Name of the ServletContext init-param that determines if the XML parsers - * used for *.tld files will be validating or not. + * Name of the ServletContext init-param that determines if the XML parsers used for *.tld files will be validating + * or not. * <p> * This must be kept in sync with org.apache.catalina.Globals */ - public static final String XML_VALIDATION_TLD_INIT_PARAM = - "org.apache.jasper.XML_VALIDATE_TLD"; + public static final String XML_VALIDATION_TLD_INIT_PARAM = "org.apache.jasper.XML_VALIDATE_TLD"; /** - * Name of the ServletContext init-param that determines if the XML parsers - * will block the resolution of external entities. + * Name of the ServletContext init-param that determines if the XML parsers will block the resolution of external + * entities. * <p> * This must be kept in sync with org.apache.catalina.Globals */ - public static final String XML_BLOCK_EXTERNAL_INIT_PARAM = - "org.apache.jasper.XML_BLOCK_EXTERNAL"; + public static final String XML_BLOCK_EXTERNAL_INIT_PARAM = "org.apache.jasper.XML_BLOCK_EXTERNAL"; /** - * Name of the ServletContext init-param that determines the JSP - * factory pool size. Set the value to a positive integer to enable it. - * The default value is <code>8</code> per thread. + * Name of the ServletContext init-param that determines the JSP factory pool size. Set the value to a positive + * integer to enable it. The default value is <code>8</code> per thread. */ - public static final String JSP_FACTORY_POOL_SIZE_INIT_PARAM = - "org.apache.jasper.runtime.JspFactoryImpl.POOL_SIZE"; + public static final String JSP_FACTORY_POOL_SIZE_INIT_PARAM = "org.apache.jasper.runtime.JspFactoryImpl.POOL_SIZE"; } diff --git a/java/org/apache/jasper/EmbeddedServletOptions.java b/java/org/apache/jasper/EmbeddedServletOptions.java index 4857070e5d..81156548fd 100644 --- a/java/org/apache/jasper/EmbeddedServletOptions.java +++ b/java/org/apache/jasper/EmbeddedServletOptions.java @@ -73,9 +73,8 @@ public final class EmbeddedServletOptions implements Options { private boolean isPoolingEnabled = true; /** - * Do you want support for "mapped" files? This will generate - * servlet that has a print statement per line of the JSP file. - * This seems like a really nice feature to have for debugging. + * Do you want support for "mapped" files? This will generate servlet that has a print statement per line of the JSP + * file. This seems like a really nice feature to have for debugging. */ private boolean mappedFile = true; @@ -107,8 +106,7 @@ public final class EmbeddedServletOptions implements Options { private boolean errorOnUseBeanInvalidClassAttribute = true; /** - * I want to see my generated servlets. Which directory are they - * in? + * I want to see my generated servlets. Which directory are they in? */ private final File scratchDir; @@ -153,8 +151,7 @@ public final class EmbeddedServletOptions implements Options { private TagPluginManager tagPluginManager = null; /** - * Java platform encoding to generate the JSP - * page servlet. + * Java platform encoding to generate the JSP page servlet. */ private String javaEncoding = "UTF-8"; @@ -174,33 +171,29 @@ public final class EmbeddedServletOptions implements Options { private boolean xpoweredBy; /** - * Should we include a source fragment in exception messages, which could be displayed - * to the developer ? + * Should we include a source fragment in exception messages, which could be displayed to the developer ? */ private boolean displaySourceFragment = true; /** - * The maximum number of loaded jsps per web-application. If there are more - * jsps loaded, they will be unloaded. + * The maximum number of loaded jsps per web-application. If there are more jsps loaded, they will be unloaded. */ private int maxLoadedJsps = -1; /** - * The idle time in seconds after which a JSP is unloaded. - * If unset or less or equal than 0, no jsps are unloaded. + * The idle time in seconds after which a JSP is unloaded. If unset or less or equal than 0, no jsps are unloaded. */ private int jspIdleTimeout = -1; /** - * Should JSP.1.6 be applied strictly to attributes defined using scriptlet - * expressions? + * Should JSP.1.6 be applied strictly to attributes defined using scriptlet expressions? */ private boolean strictQuoteEscaping = true; /** - * When EL is used in JSP attribute values, should the rules for quoting of - * attributes described in JSP.1.6 be applied to the expression? + * When EL is used in JSP attribute values, should the rules for quoting of attributes described in JSP.1.6 be + * applied to the expression? */ private boolean quoteAttributeEL = true; @@ -230,13 +223,13 @@ public final class EmbeddedServletOptions implements Options { private boolean useInstanceManagerForTags = false; - public String getProperty(String name ) { - return settings.getProperty( name ); + public String getProperty(String name) { + return settings.getProperty(name); } - public void setProperty(String name, String value ) { - if (name != null && value != null){ - settings.setProperty( name, value ); + public void setProperty(String name, String value) { + if (name != null && value != null) { + settings.setProperty(name, value); } } @@ -388,7 +381,7 @@ public final class EmbeddedServletOptions implements Options { } @Override - public Map<String, TagLibraryInfo> getCache() { + public Map<String,TagLibraryInfo> getCache() { return null; } @@ -478,18 +471,18 @@ public final class EmbeddedServletOptions implements Options { } /** - * Create an EmbeddedServletOptions object using data available from - * ServletConfig and ServletContext. - * @param config The Servlet config + * Create an EmbeddedServletOptions object using data available from ServletConfig and ServletContext. + * + * @param config The Servlet config * @param context The Servlet context */ public EmbeddedServletOptions(ServletConfig config, ServletContext context) { - Enumeration<String> enumeration=config.getInitParameterNames(); - while( enumeration.hasMoreElements() ) { - String k=enumeration.nextElement(); - String v=config.getInitParameter( k ); - setProperty( k, v); + Enumeration<String> enumeration = config.getInitParameterNames(); + while (enumeration.hasMoreElements()) { + String k = enumeration.nextElement(); + String v = config.getInitParameter(k); + setProperty(k, v); } String keepgen = config.getInitParameter("keepgenerated"); @@ -519,8 +512,7 @@ public final class EmbeddedServletOptions implements Options { this.isPoolingEnabled = true; String poolingEnabledParam = config.getInitParameter("enablePooling"); - if (poolingEnabledParam != null - && !poolingEnabledParam.equalsIgnoreCase("true")) { + if (poolingEnabledParam != null && !poolingEnabledParam.equalsIgnoreCase("true")) { if (poolingEnabledParam.equalsIgnoreCase("false")) { this.isPoolingEnabled = false; } else { @@ -546,9 +538,9 @@ public final class EmbeddedServletOptions implements Options { String debugInfo = config.getInitParameter("classdebuginfo"); if (debugInfo != null) { if (debugInfo.equalsIgnoreCase("true")) { - this.classDebugInfo = true; + this.classDebugInfo = true; } else if (debugInfo.equalsIgnoreCase("false")) { - this.classDebugInfo = false; + this.classDebugInfo = false; } else { if (log.isWarnEnabled()) { log.warn(Localizer.getMessage("jsp.warning.classDebugInfo")); @@ -560,7 +552,7 @@ public final class EmbeddedServletOptions implements Options { if (checkInterval != null) { try { this.checkInterval = Integer.parseInt(checkInterval); - } catch(NumberFormatException ex) { + } catch (NumberFormatException ex) { if (log.isWarnEnabled()) { log.warn(Localizer.getMessage("jsp.warning.checkInterval")); } @@ -571,7 +563,7 @@ public final class EmbeddedServletOptions implements Options { if (modificationTestInterval != null) { try { this.modificationTestInterval = Integer.parseInt(modificationTestInterval); - } catch(NumberFormatException ex) { + } catch (NumberFormatException ex) { if (log.isWarnEnabled()) { log.warn(Localizer.getMessage("jsp.warning.modificationTestInterval")); } @@ -674,21 +666,19 @@ public final class EmbeddedServletOptions implements Options { return; } - if (!(scratchDir.exists() && scratchDir.canRead() && - scratchDir.canWrite() && scratchDir.isDirectory())) { - log.fatal(Localizer.getMessage("jsp.error.bad.scratch.dir", - scratchDir.getAbsolutePath())); + if (!(scratchDir.exists() && scratchDir.canRead() && scratchDir.canWrite() && scratchDir.isDirectory())) { + log.fatal(Localizer.getMessage("jsp.error.bad.scratch.dir", scratchDir.getAbsolutePath())); } this.compiler = config.getInitParameter("compiler"); String compilerTargetVM = config.getInitParameter("compilerTargetVM"); - if(compilerTargetVM != null) { + if (compilerTargetVM != null) { this.compilerTargetVM = compilerTargetVM; } String compilerSourceVM = config.getInitParameter("compilerSourceVM"); - if(compilerSourceVM != null) { + if (compilerSourceVM != null) { this.compilerSourceVM = compilerSourceVM; } @@ -745,9 +735,9 @@ public final class EmbeddedServletOptions implements Options { if (maxLoadedJsps != null) { try { this.maxLoadedJsps = Integer.parseInt(maxLoadedJsps); - } catch(NumberFormatException ex) { + } catch (NumberFormatException ex) { if (log.isWarnEnabled()) { - log.warn(Localizer.getMessage("jsp.warning.maxLoadedJsps", ""+this.maxLoadedJsps)); + log.warn(Localizer.getMessage("jsp.warning.maxLoadedJsps", "" + this.maxLoadedJsps)); } } } @@ -756,9 +746,9 @@ public final class EmbeddedServletOptions implements Options { if (jspIdleTimeout != null) { try { this.jspIdleTimeout = Integer.parseInt(jspIdleTimeout); - } catch(NumberFormatException ex) { + } catch (NumberFormatException ex) { if (log.isWarnEnabled()) { - log.warn(Localizer.getMessage("jsp.warning.jspIdleTimeout", ""+this.jspIdleTimeout)); + log.warn(Localizer.getMessage("jsp.warning.jspIdleTimeout", "" + this.jspIdleTimeout)); } } } diff --git a/java/org/apache/jasper/JasperException.java b/java/org/apache/jasper/JasperException.java index 46e08675fb..b65bb2979a 100644 --- a/java/org/apache/jasper/JasperException.java +++ b/java/org/apache/jasper/JasperException.java @@ -17,8 +17,7 @@ package org.apache.jasper; /** - * Base class for all exceptions generated by the JSP engine. Makes it - * convenient to catch just this at the top-level. + * Base class for all exceptions generated by the JSP engine. Makes it convenient to catch just this at the top-level. * * @author Anil K. Vijendran */ @@ -31,9 +30,9 @@ public class JasperException extends jakarta.servlet.ServletException { } /** - * Creates a JasperException with the embedded exception and the reason for - * throwing a JasperException. - * @param reason The exception message + * Creates a JasperException with the embedded exception and the reason for throwing a JasperException. + * + * @param reason The exception message * @param exception The root cause */ public JasperException(String reason, Throwable exception) { @@ -42,6 +41,7 @@ public class JasperException extends jakarta.servlet.ServletException { /** * Creates a JasperException with the embedded exception. + * * @param exception The root cause */ public JasperException(Throwable exception) { diff --git a/java/org/apache/jasper/JspC.java b/java/org/apache/jasper/JspC.java index 7929c5e39f..b66e0b4064 100644 --- a/java/org/apache/jasper/JspC.java +++ b/java/org/apache/jasper/JspC.java @@ -65,14 +65,10 @@ import org.apache.tools.ant.util.FileUtils; import org.xml.sax.SAXException; /** - * Shell for the jspc compiler. Handles all options associated with the - * command line and creates compilation contexts which it then compiles - * according to the specified options. + * Shell for the jspc compiler. Handles all options associated with the command line and creates compilation contexts + * which it then compiles according to the specified options. This version can process files from a _single_ webapp at + * once, i.e. a single docbase can be specified. It can be used as an Ant task using: * - * This version can process files from a _single_ webapp at once, i.e. - * a single docbase can be specified. - * - * It can be used as an Ant task using: * <pre> * <taskdef classname="org.apache.jasper.JspC" name="jasper" > * <classpath> @@ -141,7 +137,7 @@ public class JspC extends Task implements Options { protected static final String SWITCH_QUOTE_ATTRIBUTE_EL = "-quoteAttributeEL"; protected static final String SWITCH_NO_QUOTE_ATTRIBUTE_EL = "-no-quoteAttributeEL"; protected static final String SWITCH_THREAD_COUNT = "-threadCount"; - protected static final String SHOW_SUCCESS ="-s"; + protected static final String SHOW_SUCCESS = "-s"; protected static final String LIST_ERRORS = "-l"; protected static final int INC_WEBXML = 10; protected static final int FRG_WEBXML = 15; @@ -193,7 +189,7 @@ public class JspC extends Task implements Options { protected boolean smapSuppressed = true; protected boolean smapDumped = false; protected boolean caching = true; - protected final Map<String, TagLibraryInfo> cache = new HashMap<>(); + protected final Map<String,TagLibraryInfo> cache = new HashMap<>(); protected String compiler = null; @@ -203,8 +199,7 @@ public class JspC extends Task implements Options { protected boolean classDebugInfo = true; /** - * Throw an exception if there's a compilation error, or swallow it. - * Default is true to preserve old behavior. + * Throw an exception if there's a compilation error, or swallow it. Default is true to preserve old behavior. */ protected boolean failOnError = true; @@ -214,8 +209,7 @@ public class JspC extends Task implements Options { private boolean fork = false; /** - * The file extensions to be handled as JSP files. - * Default list is .jsp and .jspx. + * The file extensions to be handled as JSP files. Default list is .jsp and .jspx. */ protected List<String> extensions; @@ -225,14 +219,12 @@ public class JspC extends Task implements Options { protected final List<String> pages = new ArrayList<>(); /** - * Needs better documentation, this data member does. - * True by default. + * Needs better documentation, this data member does. True by default. */ protected boolean errorOnUseBeanInvalidClassAttribute = true; /** - * The java file encoding. Default - * is UTF-8. Added per bugzilla 19622. + * The java file encoding. Default is UTF-8. Added per bugzilla 19622. */ protected String javaEncoding = "UTF-8"; @@ -255,8 +247,7 @@ public class JspC extends Task implements Options { protected JspCServletContext context; /** - * The runtime context. - * Maintain a dummy JspRuntimeContext for compiling tag files. + * The runtime context. Maintain a dummy JspRuntimeContext for compiling tag files. */ protected JspRuntimeContext rctxt; @@ -300,7 +291,9 @@ public class JspC extends Task implements Options { /** * Apply command-line arguments. + * * @param arg The arguments + * * @throws JasperException JSPC error */ public void setArgs(String[] arg) throws JasperException { @@ -316,24 +309,24 @@ public class JspC extends Task implements Options { listErrors = true; } else if (tok.equals(SWITCH_OUTPUT_DIR)) { tok = nextArg(); - setOutputDir( tok ); + setOutputDir(tok); } else if (tok.equals(SWITCH_PACKAGE_NAME)) { targetPackage = nextArg(); } else if (tok.equals(SWITCH_COMPILE)) { - compile=true; + compile = true; } else if (tok.equals(SWITCH_FAIL_FAST)) { failFast = true; } else if (tok.equals(SWITCH_CLASS_NAME)) { targetClassName = nextArg(); } else if (tok.equals(SWITCH_URI_BASE)) { - uriBase=nextArg(); + uriBase = nextArg(); } else if (tok.equals(SWITCH_URI_ROOT)) { - setUriroot( nextArg()); + setUriroot(nextArg()); } else if (tok.equals(SWITCH_FILE_WEBAPP)) { - setUriroot( nextArg()); - } else if ( tok.equals( SHOW_SUCCESS ) ) { + setUriroot(nextArg()); + } else if (tok.equals(SHOW_SUCCESS)) { showSuccess = true; - } else if ( tok.equals( LIST_ERRORS ) ) { + } else if (tok.equals(LIST_ERRORS)) { listErrors = true; } else if (tok.equals(SWITCH_WEBAPP_INC)) { webxmlFile = nextArg(); @@ -373,8 +366,7 @@ public class JspC extends Task implements Options { setClassPath(nextArg()); } else if (tok.startsWith(SWITCH_DIE)) { try { - dieLevel = Integer.parseInt( - tok.substring(SWITCH_DIE.length())); + dieLevel = Integer.parseInt(tok.substring(SWITCH_DIE.length())); } catch (NumberFormatException nfe) { dieLevel = DEFAULT_DIE_LEVEL; } @@ -420,18 +412,17 @@ public class JspC extends Task implements Options { } // Add all extra arguments to the list of files - while( true ) { + while (true) { String file = nextFile(); - if( file==null ) { + if (file == null) { break; } - pages.add( file ); + pages.add(file); } } /** - * In JspC this always returns <code>true</code>. - * {@inheritDoc} + * In JspC this always returns <code>true</code>. {@inheritDoc} */ @Override public boolean getKeepGenerated() { @@ -449,8 +440,7 @@ public class JspC extends Task implements Options { } /** - * Sets the option to control handling of template text that consists - * entirely of whitespace. + * Sets the option to control handling of template text that consists entirely of whitespace. * * @param ts New value */ @@ -476,6 +466,7 @@ public class JspC extends Task implements Options { /** * Sets the option to enable the tag handler pooling. + * * @param poolingEnabled New value */ public void setPoolingEnabled(boolean poolingEnabled) { @@ -489,6 +480,7 @@ public class JspC extends Task implements Options { /** * Sets the option to enable generation of X-Powered-By response header. + * * @param xpoweredBy New value */ public void setXpoweredBy(boolean xpoweredBy) { @@ -496,8 +488,7 @@ public class JspC extends Task implements Options { } /** - * In JspC this always returns <code>true</code>. - * {@inheritDoc} + * In JspC this always returns <code>true</code>. {@inheritDoc} */ @Override public boolean getDisplaySourceFragment() { @@ -520,8 +511,8 @@ public class JspC extends Task implements Options { } /** - * Sets the option to issue a compilation error if the class attribute - * specified in useBean action is invalid. + * Sets the option to issue a compilation error if the class attribute specified in useBean action is invalid. + * * @param b New value */ public void setErrorOnUseBeanInvalidClassAttribute(boolean b) { @@ -539,10 +530,11 @@ public class JspC extends Task implements Options { /** * Sets the option to include debug information in compiled class. + * * @param b New value */ - public void setClassDebugInfo( boolean b ) { - classDebugInfo=b; + public void setClassDebugInfo(boolean b) { + classDebugInfo = b; } @Override @@ -558,6 +550,7 @@ public class JspC extends Task implements Options { /** * Sets the option to enable caching. + * * @param caching New value * * @see Options#isCaching() @@ -567,13 +560,12 @@ public class JspC extends Task implements Options { } @Override - public Map<String, TagLibraryInfo> getCache() { + public Map<String,TagLibraryInfo> getCache() { return cache; } /** - * In JspC this always returns <code>0</code>. - * {@inheritDoc} + * In JspC this always returns <code>0</code>. {@inheritDoc} */ @Override public int getCheckInterval() { @@ -581,8 +573,7 @@ public class JspC extends Task implements Options { } /** - * In JspC this always returns <code>0</code>. - * {@inheritDoc} + * In JspC this always returns <code>0</code>. {@inheritDoc} */ @Override public int getModificationTestInterval() { @@ -591,8 +582,7 @@ public class JspC extends Task implements Options { /** - * In JspC this always returns <code>false</code>. - * {@inheritDoc} + * In JspC this always returns <code>false</code>. {@inheritDoc} */ @Override public boolean getRecompileOnFail() { @@ -601,8 +591,7 @@ public class JspC extends Task implements Options { /** - * In JspC this always returns <code>false</code>. - * {@inheritDoc} + * In JspC this always returns <code>false</code>. {@inheritDoc} */ @Override public boolean getDevelopment() { @@ -616,6 +605,7 @@ public class JspC extends Task implements Options { /** * Sets smapSuppressed flag. + * * @param smapSuppressed New value */ public void setSmapSuppressed(boolean smapSuppressed) { @@ -629,6 +619,7 @@ public class JspC extends Task implements Options { /** * Sets smapDumped flag. + * * @param smapDumped New value * * @see Options#isSmapDumped() @@ -639,11 +630,9 @@ public class JspC extends Task implements Options { /** - * Determines whether text strings are to be generated as char arrays, - * which improves performance in some cases. + * Determines whether text strings are to be generated as char arrays, which improves performance in some cases. * - * @param genStringAsCharArray true if text strings are to be generated as - * char arrays, false otherwise + * @param genStringAsCharArray true if text strings are to be generated as char arrays, false otherwise */ public void setGenStringAsCharArray(boolean genStringAsCharArray) { this.genStringAsCharArray = genStringAsCharArray; @@ -666,12 +655,13 @@ public class JspC extends Task implements Options { /** * Sets the option to determine what compiler to use. + * * @param c New value * * @see Options#getCompiler() */ public void setCompiler(String c) { - compiler=c; + compiler = c; } @Override @@ -686,6 +676,7 @@ public class JspC extends Task implements Options { /** * Sets the compiler target VM. + * * @param vm New value * * @see Options#getCompilerTargetVM() @@ -694,17 +685,18 @@ public class JspC extends Task implements Options { compilerTargetVM = vm; } - @Override + @Override public String getCompilerSourceVM() { - return compilerSourceVM; - } - - /** - * Sets the compiler source VM. - * @param vm New value - * - * @see Options#getCompilerSourceVM() - */ + return compilerSourceVM; + } + + /** + * Sets the compiler source VM. + * + * @param vm New value + * + * @see Options#getCompilerSourceVM() + */ public void setCompilerSourceVM(String vm) { compilerSourceVM = vm; } @@ -715,8 +707,7 @@ public class JspC extends Task implements Options { } /** - * Returns the encoding to use for - * java files. The default is UTF-8. + * Returns the encoding to use for java files. The default is UTF-8. * * @return String The encoding */ @@ -726,8 +717,7 @@ public class JspC extends Task implements Options { } /** - * Sets the encoding to use for - * java files. + * Sets the encoding to use for java files. * * @param encodingName The name, e.g. "UTF-8" */ @@ -746,24 +736,23 @@ public class JspC extends Task implements Options { @Override public String getClassPath() { - if( classPath != null ) { + if (classPath != null) { return classPath; } return System.getProperty("java.class.path"); } /** - * Sets the classpath used while compiling the servlets generated from JSP - * files - * @param s New value + * Sets the classpath used while compiling the servlets generated from JSP files + * + * @param s New value */ public void setClassPath(String s) { - classPath=s; + classPath = s; } /** - * Returns the list of file extensions - * that are treated as JSP files. + * Returns the list of file extensions that are treated as JSP files. * * @return The list of extensions */ @@ -772,14 +761,13 @@ public class JspC extends Task implements Options { } /** - * Adds the given file extension to the - * list of extensions handled as JSP files. + * Adds the given file extension to the list of extensions handled as JSP files. * * @param extension The extension to add, e.g. "myjsp" */ protected void addExtension(final String extension) { - if(extension != null) { - if(extensions == null) { + if (extension != null) { + if (extensions == null) { extensions = new ArrayList<>(); } @@ -788,33 +776,32 @@ public class JspC extends Task implements Options { } /** - * Base dir for the webapp. Used to generate class names and resolve - * includes. + * Base dir for the webapp. Used to generate class names and resolve includes. + * * @param s New value */ - public void setUriroot( String s ) { + public void setUriroot(String s) { if (s == null) { uriRoot = null; return; } try { uriRoot = resolveFile(s).getCanonicalPath(); - } catch( Exception ex ) { + } catch (Exception ex) { uriRoot = s; } } /** - * Parses comma-separated list of JSP files to be processed. If the argument - * is null, nothing is done. - * - * <p>Each file is interpreted relative to uriroot, unless it is absolute, - * in which case it must start with uriroot.</p> + * Parses comma-separated list of JSP files to be processed. If the argument is null, nothing is done. + * <p> + * Each file is interpreted relative to uriroot, unless it is absolute, in which case it must start with uriroot. + * </p> * * @param jspFiles Comma-separated list of JSP files to be processed */ public void setJspFiles(final String jspFiles) { - if(jspFiles == null) { + if (jspFiles == null) { return; } @@ -829,18 +816,17 @@ public class JspC extends Task implements Options { * * @param b Flag value */ - public void setCompile( final boolean b ) { + public void setCompile(final boolean b) { compile = b; } /** - * Sets the verbosity level. The actual number doesn't - * matter: if it's greater than zero, the verbose flag will - * be true. + * Sets the verbosity level. The actual number doesn't matter: if it's greater than zero, the verbose flag will be + * true. * * @param level Positive means verbose */ - public void setVerbose( final int level ) { + public void setVerbose(final int level) { if (level > 0) { verbose = true; showSuccess = true; @@ -848,7 +834,7 @@ public class JspC extends Task implements Options { } } - public void setValidateTld( boolean b ) { + public void setValidateTld(boolean b) { this.validateTld = b; } @@ -856,7 +842,7 @@ public class JspC extends Task implements Options { return validateTld; } - public void setValidateXml( boolean b ) { + public void setValidateXml(boolean b) { this.validateXml = b; } @@ -864,7 +850,7 @@ public class JspC extends Task implements Options { return validateXml; } - public void setBlockExternal( boolean b ) { + public void setBlockExternal(boolean b) { this.blockExternal = b; } @@ -872,7 +858,7 @@ public class JspC extends Task implements Options { return blockExternal; } - public void setStrictQuoteEscaping( boolean b ) { + public void setStrictQuoteEscaping(boolean b) { this.strictQuoteEscaping = b; } @@ -910,94 +896,91 @@ public class JspC extends Task implements Options { throw new BuildException(Localizer.getMessage("jspc.error.parseThreadCount", threadCount)); } if (newThreadCount < 1) { - throw new BuildException(Localizer.getMessage( - "jspc.error.minThreadCount", Integer.valueOf(newThreadCount))); + throw new BuildException( + Localizer.getMessage("jspc.error.minThreadCount", Integer.valueOf(newThreadCount))); } this.threadCount = newThreadCount; } - public void setListErrors( boolean b ) { + public void setListErrors(boolean b) { listErrors = b; } - public void setOutputDir( String s ) { - if( s!= null ) { + public void setOutputDir(String s) { + if (s != null) { scratchDir = resolveFile(s).getAbsoluteFile(); } else { - scratchDir=null; + scratchDir = null; } } /** * Sets the package name to be used for the generated servlet classes. + * * @param p New value */ - public void setPackage( String p ) { - targetPackage=p; + public void setPackage(String p) { + targetPackage = p; } /** - * Class name of the generated file ( without package ). - * Can only be used if a single file is converted. - * XXX Do we need this feature ? + * Class name of the generated file ( without package ). Can only be used if a single file is converted. XXX Do we + * need this feature ? + * * @param p New value */ - public void setClassName( String p ) { - targetClassName=p; + public void setClassName(String p) { + targetClassName = p; } /** - * File where we generate configuration with the class definitions to be - * included in a web.xml file. + * File where we generate configuration with the class definitions to be included in a web.xml file. + * * @param s New value */ - public void setWebXmlInclude( String s ) { - webxmlFile=resolveFile(s).getAbsolutePath(); - webxmlLevel=INC_WEBXML; + public void setWebXmlInclude(String s) { + webxmlFile = resolveFile(s).getAbsolutePath(); + webxmlLevel = INC_WEBXML; } /** - * File where we generate a complete web-fragment.xml with the class - * definitions. + * File where we generate a complete web-fragment.xml with the class definitions. + * * @param s New value */ - public void setWebFragmentXml( String s ) { - webxmlFile=resolveFile(s).getAbsolutePath(); - webxmlLevel=FRG_WEBXML; + public void setWebFragmentXml(String s) { + webxmlFile = resolveFile(s).getAbsolutePath(); + webxmlLevel = FRG_WEBXML; } /** * File where we generate a complete web.xml with the class definitions. + * * @param s New value */ - public void setWebXml( String s ) { - webxmlFile=resolveFile(s).getAbsolutePath(); - webxmlLevel=ALL_WEBXML; + public void setWebXml(String s) { + webxmlFile = resolveFile(s).getAbsolutePath(); + webxmlLevel = ALL_WEBXML; } /** * Sets the encoding to be used to read and write web.xml files. - * * <p> * If not specified, defaults to UTF-8. * </p> * - * @param encoding - * Encoding, e.g. "UTF-8". + * @param encoding Encoding, e.g. "UTF-8". */ public void setWebXmlEncoding(String encoding) { webxmlEncoding = encoding; } /** - * Sets the option to merge generated web.xml fragment into the - * WEB-INF/web.xml file of the web application that we were processing. + * Sets the option to merge generated web.xml fragment into the WEB-INF/web.xml file of the web application that we + * were processing. * - * @param b - * <code>true</code> to merge the fragment into the existing - * web.xml file of the processed web application - * ({uriroot}/WEB-INF/web.xml), <code>false</code> to keep the - * generated web.xml fragment + * @param b <code>true</code> to merge the fragment into the existing web.xml file of the processed web application + * ({uriroot}/WEB-INF/web.xml), <code>false</code> to keep the generated web.xml fragment */ public void setAddWebXmlMappings(boolean b) { addWebXmlMappings = b; @@ -1005,6 +988,7 @@ public class JspC extends Task implements Options { /** * Sets the option that throws an exception in case of a compilation error. + * * @param b New value */ public void setFailOnError(final boolean b) { @@ -1012,8 +996,7 @@ public class JspC extends Task implements Options { } /** - * @return <code>true</code> if an exception will be thrown - * in case of a compilation error. + * @return <code>true</code> if an exception will be thrown in case of a compilation error. */ public boolean getFailOnError() { return failOnError; @@ -1033,8 +1016,7 @@ public class JspC extends Task implements Options { /** * {@inheritDoc} * <p> - * Hard-coded to {@code false} for pre-compiled code to enable repeatable - * builds. + * Hard-coded to {@code false} for pre-compiled code to enable repeatable builds. */ @Override public boolean getGeneratedJavaAddTimestamp() { @@ -1043,19 +1025,14 @@ public class JspC extends Task implements Options { /** - * Adds servlet declaration and mapping for the JSP page servlet to the - * generated web.xml fragment. + * Adds servlet declaration and mapping for the JSP page servlet to the generated web.xml fragment. + * + * @param file Context-relative path to the JSP file, e.g. <code>/index.jsp</code> + * @param clctxt Compilation context of the servlet * - * @param file - * Context-relative path to the JSP file, e.g. - * <code>/index.jsp</code> - * @param clctxt - * Compilation context of the servlet * @throws IOException An IO error occurred */ - public void generateWebMapping( String file, JspCompilationContext clctxt ) - throws IOException - { + public void generateWebMapping(String file, JspCompilationContext clctxt) throws IOException { if (log.isDebugEnabled()) { log.debug(Localizer.getMessage("jspc.generatingMapping", file, clctxt)); } @@ -1064,14 +1041,14 @@ public class JspC extends Task implements Options { String packageName = clctxt.getServletPackageName(); String thisServletName; - if (packageName.isEmpty()) { + if (packageName.isEmpty()) { thisServletName = className; } else { thisServletName = packageName + '.' + className; } if (servletout != null) { - synchronized(servletout) { + synchronized (servletout) { servletout.write("\n <servlet>\n <servlet-name>"); servletout.write(thisServletName); servletout.write("</servlet-name>\n <servlet-class>"); @@ -1080,7 +1057,7 @@ public class JspC extends Task implements Options { } } if (mappingout != null) { - synchronized(mappingout) { + synchronized (mappingout) { mappingout.write("\n <servlet-mapping>\n <servlet-name>"); mappingout.write(thisServletName); mappingout.write("</servlet-name>\n <url-pattern>"); @@ -1092,6 +1069,7 @@ public class JspC extends Task implements Options { /** * Include the generated web.xml inside the webapp's web.xml. + * * @throws IOException An IO error occurred */ protected void mergeIntoWebXml() throws IOException { @@ -1099,14 +1077,11 @@ public class JspC extends Task implements Options { File webappBase = new File(uriRoot); File webXml = new File(webappBase, "WEB-INF/web.xml"); File webXml2 = new File(webappBase, "WEB-INF/web2.xml"); - String insertStartMarker = - Localizer.getMessage("jspc.webinc.insertStart"); - String insertEndMarker = - Localizer.getMessage("jspc.webinc.insertEnd"); + String insertStartMarker = Localizer.getMessage("jspc.webinc.insertStart"); + String insertEndMarker = Localizer.getMessage("jspc.webinc.insertEnd"); try (BufferedReader reader = new BufferedReader(openWebxmlReader(webXml)); - BufferedReader fragmentReader = - new BufferedReader(openWebxmlReader(new File(webxmlFile))); + BufferedReader fragmentReader = new BufferedReader(openWebxmlReader(new File(webxmlFile))); PrintWriter writer = new PrintWriter(openWebxmlWriter(webXml2))) { // Insert the <servlet> and <servlet-mapping> declarations @@ -1158,8 +1133,7 @@ public class JspC extends Task implements Options { } } - try (FileInputStream fis = new FileInputStream(webXml2); - FileOutputStream fos = new FileOutputStream(webXml)) { + try (FileInputStream fis = new FileInputStream(webXml2); FileOutputStream fos = new FileOutputStream(webXml)) { byte[] buf = new byte[512]; while (true) { @@ -1171,9 +1145,8 @@ public class JspC extends Task implements Options { } } - if(!webXml2.delete() && log.isDebugEnabled()) { - log.debug(Localizer.getMessage("jspc.delete.fail", - webXml2.toString())); + if (!webXml2.delete() && log.isDebugEnabled()) { + log.debug(Localizer.getMessage("jspc.delete.fail", webXml2.toString())); } if (!(new File(webxmlFile)).delete() && log.isDebugEnabled()) { @@ -1236,9 +1209,8 @@ public class JspC extends Task implements Options { scratchDir = new File(temp).getAbsoluteFile(); } - String jspUri=file.replace('\\','/'); - JspCompilationContext clctxt = new JspCompilationContext - ( jspUri, this, context, null, rctxt ); + String jspUri = file.replace('\\', '/'); + JspCompilationContext clctxt = new JspCompilationContext(jspUri, this, context, null, rctxt); /* Override the defaults */ if ((targetClassName != null) && (!targetClassName.isEmpty())) { @@ -1261,7 +1233,7 @@ public class JspC extends Task implements Options { // .jsp file is newer than .class file; // Otherwise only generate .java, if .jsp file is newer than // the .java file - if( clc.isOutDated(compile) ) { + if (clc.isOutDated(compile)) { if (log.isDebugEnabled()) { log.debug(Localizer.getMessage("jspc.outdated", jspUri)); } @@ -1270,27 +1242,23 @@ public class JspC extends Task implements Options { } // Generate mapping - generateWebMapping( file, clctxt ); - if ( showSuccess ) { + generateWebMapping(file, clctxt); + if (showSuccess) { log.info(Localizer.getMessage("jspc.built", file)); } } catch (JasperException je) { Throwable rootCause = je; - while (rootCause instanceof JasperException - && ((JasperException) rootCause).getRootCause() != null) { + while (rootCause instanceof JasperException && ((JasperException) rootCause).getRootCause() != null) { rootCause = ((JasperException) rootCause).getRootCause(); } if (rootCause != je) { - log.error(Localizer.getMessage("jspc.error.generalException", - file), - rootCause); + log.error(Localizer.getMessage("jspc.error.generalException", file), rootCause); } throw je; } catch (Exception e) { if ((e instanceof FileNotFoundException) && log.isWarnEnabled()) { - log.warn(Localizer.getMessage("jspc.error.fileDoesNotExist", - e.getMessage())); + log.warn(Localizer.getMessage("jspc.error.fileDoesNotExist", e.getMessage())); } throw new JasperException(e); } finally { @@ -1302,9 +1270,8 @@ public class JspC extends Task implements Options { /** - * Locate all jsp files in the webapp. Used if no explicit jsps are - * specified. Scan is performed via the ServletContext and will include any - * JSPs located in resource JARs. + * Locate all jsp files in the webapp. Used if no explicit jsps are specified. Scan is performed via the + * ServletContext and will include any JSPs located in resource JARs. */ public void scanFiles() { // Make sure default extensions are always included @@ -1339,7 +1306,7 @@ public class JspC extends Task implements Options { */ @Override public void execute() { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug(Localizer.getMessage("jspc.start", Integer.toString(pages.size()))); } @@ -1351,8 +1318,7 @@ public class JspC extends Task implements Options { String firstJsp = pages.getFirst(); File firstJspF = new File(firstJsp); if (!firstJspF.exists()) { - throw new JasperException(Localizer.getMessage( - "jspc.error.fileDoesNotExist", firstJsp)); + throw new JasperException(Localizer.getMessage("jspc.error.fileDoesNotExist", firstJsp)); } locateUriRoot(firstJspF); } @@ -1390,8 +1356,7 @@ public class JspC extends Task implements Options { } if (!fjsp.exists()) { if (log.isWarnEnabled()) { - log.warn(Localizer.getMessage( - "jspc.error.fileDoesNotExist", fjsp.toString())); + log.warn(Localizer.getMessage("jspc.error.fileDoesNotExist", fjsp.toString())); } continue; } @@ -1450,11 +1415,10 @@ public class JspC extends Task implements Options { } long time = System.currentTimeMillis() - start; - String msg = Localizer.getMessage("jspc.generation.result", - Integer.toString(errorCount), Long.toString(time)); + String msg = + Localizer.getMessage("jspc.generation.result", Integer.toString(errorCount), Long.toString(time)); if (failOnError && errorCount > 0) { - System.out.println(Localizer.getMessage( - "jspc.errorCount", Integer.valueOf(errorCount))); + System.out.println(Localizer.getMessage("jspc.errorCount", Integer.valueOf(errorCount))); throw new BuildException(msg); } else { log.info(msg); @@ -1483,8 +1447,7 @@ public class JspC extends Task implements Options { // ==================== protected utility methods ==================== protected String nextArg() { - if ((argPos >= args.length) - || (fullstop = SWITCH_FULL_STOP.equals(args[argPos]))) { + if ((argPos >= args.length) || (fullstop = SWITCH_FULL_STOP.equals(args[argPos]))) { return null; } else { return args[argPos++]; @@ -1517,9 +1480,9 @@ public class JspC extends Task implements Options { mapout.write(Localizer.getMessage("jspc.webxml.header", webxmlEncoding)); mapout.flush(); } else if (webxmlLevel >= FRG_WEBXML) { - mapout.write(Localizer.getMessage("jspc.webfrg.header", webxmlEncoding)); - mapout.flush(); - } else if ((webxmlLevel>= INC_WEBXML) && !addWebXmlMappings) { + mapout.write(Localizer.getMessage("jspc.webfrg.header", webxmlEncoding)); + mapout.flush(); + } else if ((webxmlLevel >= INC_WEBXML) && !addWebXmlMappings) { mapout.write(Localizer.getMessage("jspc.webinc.header")); mapout.flush(); } @@ -1539,7 +1502,7 @@ public class JspC extends Task implements Options { if (webxmlLevel >= ALL_WEBXML) { mapout.write(Localizer.getMessage("jspc.webxml.footer")); } else if (webxmlLevel >= FRG_WEBXML) { - mapout.write(Localizer.getMessage("jspc.webfrg.footer")); + mapout.write(Localizer.getMessage("jspc.webfrg.footer")); } else if ((webxmlLevel >= INC_WEBXML) && !addWebXmlMappings) { mapout.write(Localizer.getMessage("jspc.webinc.footer")); } @@ -1561,20 +1524,18 @@ public class JspC extends Task implements Options { } - protected TldScanner newTldScanner(JspCServletContext context, boolean namespaceAware, - boolean validate, boolean blockExternal) { + protected TldScanner newTldScanner(JspCServletContext context, boolean namespaceAware, boolean validate, + boolean blockExternal) { return new TldScanner(context, namespaceAware, validate, blockExternal); } - protected void initServletContext(ClassLoader classLoader) - throws IOException, JasperException { + protected void initServletContext(ClassLoader classLoader) throws IOException, JasperException { // TODO: should we use the Ant Project's log? PrintWriter log = new PrintWriter(System.out); URL resourceBase = new File(uriRoot).getCanonicalFile().toURI().toURL(); - context = new JspCServletContext(log, resourceBase, classLoader, - isValidateXml(), isBlockExternal()); + context = new JspCServletContext(log, resourceBase, classLoader, isValidateXml(), isBlockExternal()); if (isValidateTld()) { context.setInitParameter(Constants.XML_VALIDATION_TLD_INIT_PARAM, "true"); } @@ -1587,8 +1548,7 @@ public class JspC extends Task implements Options { } catch (SAXException e) { throw new JasperException(e); } - tldCache = new TldCache(context, scanner.getUriTldResourcePathMap(), - scanner.getTldResourcePathTaglibXmlMap()); + tldCache = new TldCache(context, scanner.getUriTldResourcePathMap(), scanner.getTldResourcePathTaglibXmlMap()); context.setAttribute(TldCache.SERVLET_CONTEXT_ATTRIBUTE_NAME, tldCache); rctxt = new JspRuntimeContext(context, this); jspConfig = new JspConfig(context); @@ -1596,9 +1556,10 @@ public class JspC extends Task implements Options { } /** - * Initializes the classloader as/if needed for the given - * compilation context. + * Initializes the classloader as/if needed for the given compilation context. + * * @return the classloader that will be used + * * @throws IOException If an error occurs */ protected ClassLoader initClassLoader() throws IOException { @@ -1607,14 +1568,12 @@ public class JspC extends Task implements Options { ClassLoader jspcLoader = getClass().getClassLoader(); if (jspcLoader instanceof AntClassLoader) { - classPath += File.pathSeparator - + ((AntClassLoader) jspcLoader).getClasspath(); + classPath += File.pathSeparator + ((AntClassLoader) jspcLoader).getClasspath(); } // Turn the classPath into URLs List<URL> urls = new ArrayList<>(); - StringTokenizer tokenizer = new StringTokenizer(classPath, - File.pathSeparator); + StringTokenizer tokenizer = new StringTokenizer(classPath, File.pathSeparator); while (tokenizer.hasMoreTokens()) { String path = tokenizer.nextToken(); try { @@ -1633,8 +1592,7 @@ public class JspC extends Task implements Options { File classes = new File(webappBase, "/WEB-INF/classes"); try { if (classes.exists()) { - classPath = classPath + File.pathSeparator - + classes.getCanonicalPath(); + classPath = classPath + File.pathSeparator + classes.getCanonicalPath(); urls.add(classes.getCanonicalFile().toURI().toURL()); } } catch (IOException ioe) { @@ -1679,12 +1637,12 @@ public class JspC extends Task implements Options { } /** - * Find the WEB-INF dir by looking up in the directory tree. - * This is used if no explicit docbase is set, but only files. + * Find the WEB-INF dir by looking up in the directory tree. This is used if no explicit docbase is set, but only + * files. * * @param f The path from which it will start looking */ - protected void locateUriRoot( File f ) { + protected void locateUriRoot(File f) { String tUriBase = uriBase; if (tUriBase == null) { tUriBase = "/"; @@ -1698,9 +1656,7 @@ public class JspC extends Task implements Options { uriRoot = f.getCanonicalPath(); uriBase = tUriBase; if (log.isInfoEnabled()) { - log.info(Localizer.getMessage( - "jspc.implicit.uriRoot", - uriRoot)); + log.info(Localizer.getMessage("jspc.implicit.uriRoot", uriRoot)); } break; } @@ -1730,30 +1686,26 @@ public class JspC extends Task implements Options { } /** - * Resolves the relative or absolute pathname correctly - * in both Ant and command-line situations. If Ant launched - * us, we should use the basedir of the current project - * to resolve relative paths. - * - * See Bugzilla 35571. + * Resolves the relative or absolute pathname correctly in both Ant and command-line situations. If Ant launched us, + * we should use the basedir of the current project to resolve relative paths. See Bugzilla 35571. * * @param s The file + * * @return The file resolved */ - protected File resolveFile(final String s) { - if(getProject() == null) { - // Note FileUtils.getFileUtils replaces FileUtils.newFileUtils in Ant 1.6.3 - return FileUtils.getFileUtils().resolveFile(null, s); - } else { - return FileUtils.getFileUtils().resolveFile(getProject().getBaseDir(), s); - } - } + protected File resolveFile(final String s) { + if (getProject() == null) { + // Note FileUtils.getFileUtils replaces FileUtils.newFileUtils in Ant 1.6.3 + return FileUtils.getFileUtils().resolveFile(null, s); + } else { + return FileUtils.getFileUtils().resolveFile(getProject().getBaseDir(), s); + } + } private Reader openWebxmlReader(File file) throws IOException { FileInputStream fis = new FileInputStream(file); try { - return webxmlEncoding != null ? new InputStreamReader(fis, - webxmlEncoding) : new InputStreamReader(fis); + return webxmlEncoding != null ? new InputStreamReader(fis, webxmlEncoding) : new InputStreamReader(fis); } catch (IOException ex) { fis.close(); throw ex; @@ -1763,8 +1715,7 @@ public class JspC extends Task implements Options { private Writer openWebxmlWriter(File file) throws IOException { FileOutputStream fos = new FileOutputStream(file); try { - return webxmlEncoding != null ? new OutputStreamWriter(fos, - webxmlEncoding) : new OutputStreamWriter(fos); + return webxmlEncoding != null ? new OutputStreamWriter(fos, webxmlEncoding) : new OutputStreamWriter(fos); } catch (IOException ex) { fos.close(); throw ex; diff --git a/java/org/apache/jasper/JspCompilationContext.java b/java/org/apache/jasper/JspCompilationContext.java index 95943153c8..63741bb59b 100644 --- a/java/org/apache/jasper/JspCompilationContext.java +++ b/java/org/apache/jasper/JspCompilationContext.java @@ -43,12 +43,9 @@ import org.apache.tomcat.Jar; import org.apache.tomcat.util.descriptor.tld.TldResourcePath; /** - * A place holder for various things that are used through out the JSP - * engine. This is a per-request/per-context data structure. Some of - * the instance variables are set at different points. - * - * Most of the path-related stuff is here - mangling names, versions, dirs, - * loading resources and dealing with uris. + * A place holder for various things that are used through out the JSP engine. This is a per-request/per-context data + * structure. Some of the instance variables are set at different points. Most of the path-related stuff is here - + * mangling names, versions, dirs, loading resources and dealing with uris. * * @author Anil K. Vijendran * @author Harish Prabandham @@ -94,21 +91,18 @@ public class JspCompilationContext { private Jar tagJar; // jspURI _must_ be relative to the context - public JspCompilationContext(String jspUri, Options options, - ServletContext context, JspServletWrapper jsw, + public JspCompilationContext(String jspUri, Options options, ServletContext context, JspServletWrapper jsw, JspRuntimeContext rctxt) { this(jspUri, null, options, context, jsw, rctxt, null, false); } - public JspCompilationContext(String tagfile, TagInfo tagInfo, - Options options, ServletContext context, JspServletWrapper jsw, - JspRuntimeContext rctxt, Jar tagJar) { + public JspCompilationContext(String tagfile, TagInfo tagInfo, Options options, ServletContext context, + JspServletWrapper jsw, JspRuntimeContext rctxt, Jar tagJar) { this(tagfile, tagInfo, options, context, jsw, rctxt, tagJar, true); } - private JspCompilationContext(String jspUri, TagInfo tagInfo, - Options options, ServletContext context, JspServletWrapper jsw, - JspRuntimeContext rctxt, Jar tagJar, boolean isTagFile) { + private JspCompilationContext(String jspUri, TagInfo tagInfo, Options options, ServletContext context, + JspServletWrapper jsw, JspRuntimeContext rctxt, Jar tagJar, boolean isTagFile) { this.jspUri = canonicalURI(jspUri); this.options = options; @@ -146,7 +140,7 @@ public class JspCompilationContext { * @return the classpath that is passed off to the Java compiler. */ public String getClassPath() { - if( classPath != null ) { + if (classPath != null) { return classPath; } return rctxt.getClassPath(); @@ -154,6 +148,7 @@ public class JspCompilationContext { /** * The classpath that is passed off to the Java compiler. + * * @param classPath The class path to use */ public void setClassPath(String classPath) { @@ -161,12 +156,12 @@ public class JspCompilationContext { } /** - * What class loader to use for loading classes while compiling - * this JSP? + * What class loader to use for loading classes while compiling this JSP? + * * @return the class loader used to load all compiled classes */ public ClassLoader getClassLoader() { - if( loader != null ) { + if (loader != null) { return loader; } return rctxt.getParentClassLoader(); @@ -177,8 +172,8 @@ public class JspCompilationContext { } public ClassLoader getJspLoader() { - if( jspLoader == null ) { - jspLoader = new JasperLoader(new URL[] {baseUrl}, getClassLoader(), basePackageName); + if (jspLoader == null) { + jspLoader = new JasperLoader(new URL[] { baseUrl }, getClassLoader(), basePackageName); } return jspLoader; } @@ -188,12 +183,12 @@ public class JspCompilationContext { } - // ---------- Input/Output ---------- + // ---------- Input/Output ---------- /** - * The output directory to generate code into. The output directory - * is make up of the scratch directory, which is provide in Options, - * plus the directory derived from the package name. + * The output directory to generate code into. The output directory is make up of the scratch directory, which is + * provide in Options, plus the directory derived from the package name. + * * @return the output directory in which the generated sources are placed */ public String getOutputDir() { @@ -205,13 +200,13 @@ public class JspCompilationContext { } /** - * Create a "Compiler" object based on some init param data. This - * is not done yet. Right now we're just hardcoding the actual - * compilers that are created. + * Create a "Compiler" object based on some init param data. This is not done yet. Right now we're just hardcoding + * the actual compilers that are created. + * * @return the Java compiler wrapper */ public Compiler createCompiler() { - if (jspCompiler != null ) { + if (jspCompiler != null) { return jspCompiler; } if (options.getCompilerClassName() != null) { @@ -258,9 +253,10 @@ public class JspCompilationContext { // ---------- Access resources in the webapp ---------- /** - * Get the full value of a URI relative to this compilations context - * uses current file as the base. + * Get the full value of a URI relative to this compilations context uses current file as the base. + * * @param uri The relative URI + * * @return absolute URI */ public String resolveRelativeUri(String uri) { @@ -274,11 +270,11 @@ public class JspCompilationContext { } /** - * Gets a resource as a stream, relative to the meanings of this - * context's implementation. + * Gets a resource as a stream, relative to the meanings of this context's implementation. + * * @param res the resource to look for - * @return a null if the resource cannot be found or represented - * as an InputStream. + * + * @return a null if the resource cannot be found or represented as an InputStream. */ public java.io.InputStream getResourceAsStream(String res) { return context.getResourceAsStream(canonicalURI(res)); @@ -295,9 +291,10 @@ public class JspCompilationContext { } /** - * Gets the actual path of a URI relative to the context of - * the compilation. + * Gets the actual path of a URI relative to the context of the compilation. + * * @param path The webapp path + * * @return the corresponding path in the filesystem */ public String getRealPath(String path) { @@ -308,10 +305,10 @@ public class JspCompilationContext { } /** - * Returns the JAR file in which the tag file for which this - * JspCompilationContext was created is packaged, or null if this - * JspCompilationContext does not correspond to a tag file, or if the - * corresponding tag file is not packaged in a JAR. + * Returns the JAR file in which the tag file for which this JspCompilationContext was created is packaged, or null + * if this JspCompilationContext does not correspond to a tag file, or if the corresponding tag file is not packaged + * in a JAR. + * * @return a JAR file */ public Jar getTagFileJar() { @@ -325,8 +322,8 @@ public class JspCompilationContext { /* ==================== Common implementation ==================== */ /** - * Just the class name (does not include package name) of the - * generated class. + * Just the class name (does not include package name) of the generated class. + * * @return the class name */ public String getServletClassName() { @@ -353,8 +350,8 @@ public class JspCompilationContext { } /** - * Path of the JSP URI. Note that this is not a file name. This is - * the context rooted URI of the JSP file. + * Path of the JSP URI. Note that this is not a file name. This is the context rooted URI of the JSP file. + * * @return the path to the JSP */ public String getJspFile() { @@ -396,8 +393,7 @@ public class JspCompilationContext { } } catch (IOException e) { if (log.isDebugEnabled()) { - log.debug(Localizer.getMessage( - "jsp.error.lastModified", getJspFile()), e); + log.debug(Localizer.getMessage("jsp.error.lastModified", getJspFile()), e); } } finally { if (uc != null) { @@ -405,8 +401,7 @@ public class JspCompilationContext { uc.getInputStream().close(); } catch (IOException e) { if (log.isDebugEnabled()) { - log.debug(Localizer.getMessage( - "jsp.error.lastModified", getJspFile()), e); + log.debug(Localizer.getMessage("jsp.error.lastModified", getJspFile()), e); } result = -1; } @@ -428,10 +423,8 @@ public class JspCompilationContext { } /** - * @return <code>true</code> if we are compiling a tag file - * in prototype mode. - * ie we only generate codes with class for the tag handler with empty - * method bodies. + * @return <code>true</code> if we are compiling a tag file in prototype mode. ie we only generate codes with class + * for the tag handler with empty method bodies. */ public boolean isPrototypeMode() { return protoTypeMode; @@ -442,9 +435,9 @@ public class JspCompilationContext { } /** - * Package name for the generated class is made up of the base package - * name, which is user settable, and the derived package name. The - * derived package name directly mirrors the file hierarchy of the JSP page. + * Package name for the generated class is made up of the base package name, which is user settable, and the derived + * package name. The derived package name directly mirrors the file hierarchy of the JSP page. + * * @return the package name */ public String getServletPackageName() { @@ -468,15 +461,13 @@ public class JspCompilationContext { protected String getDerivedPackageName() { if (derivedPackageName == null) { int iSep = jspUri.lastIndexOf('/'); - derivedPackageName = (iSep > 0) ? - JspUtil.makeJavaPackage(jspUri.substring(1,iSep)) : ""; + derivedPackageName = (iSep > 0) ? JspUtil.makeJavaPackage(jspUri.substring(1, iSep)) : ""; } return derivedPackageName; } /** - * @return The base package name into which all servlet and associated code - * is generated + * @return The base package name into which all servlet and associated code is generated */ public String getBasePackageName() { return basePackageName; @@ -484,6 +475,7 @@ public class JspCompilationContext { /** * The package name into which the servlet class is generated. + * * @param basePackageName The package name to use */ public void setBasePackageName(String basePackageName) { @@ -491,8 +483,7 @@ public class JspCompilationContext { } /** - * @return Full path name of the Java file into which the servlet is being - * generated. + * @return Full path name of the Java file into which the servlet is being generated. */ public String getServletJavaFileName() { if (servletJavaFileName == null) { @@ -529,8 +520,7 @@ public class JspCompilationContext { String tagName = tagInfo.getTagClassName(); javaPath = tagName.replace('.', '/') + ".java"; } else { - javaPath = getServletPackageName().replace('.', '/') + '/' + - getServletClassName() + ".java"; + javaPath = getServletPackageName().replace('.', '/') + '/' + getServletClassName() + ".java"; } return javaPath; } @@ -555,12 +545,13 @@ public class JspCompilationContext { /** * Gets the 'location' of the TLD associated with the given taglib 'uri'. + * * @param uri The taglib URI - * @return An array of two Strings: The first element denotes the real - * path to the TLD. If the path to the TLD points to a jar file, then the - * second element denotes the name of the TLD entry in the jar file. - * Returns null if the given uri is not associated with any tag library - * 'exposed' in the web application. + * + * @return An array of two Strings: The first element denotes the real path to the TLD. If the path to the TLD + * points to a jar file, then the second element denotes the name of the TLD entry in the jar file. + * Returns null if the given uri is not associated with any tag library 'exposed' in the web + * application. */ public TldResourcePath getTldResourcePath(String uri) { return getOptions().getTldCache().getTldResourcePath(uri); @@ -612,9 +603,7 @@ public class JspCompilationContext { // Re-throw to let caller handle this - will result in a 404 throw fnfe; } catch (Exception ex) { - JasperException je = new JasperException( - Localizer.getMessage("jsp.error.unable.compile"), - ex); + JasperException je = new JasperException(Localizer.getMessage("jsp.error.unable.compile"), ex); // Cache compilation exception jsw.setCompilationException(je); throw je; @@ -631,11 +620,9 @@ public class JspCompilationContext { String name = getFQCN(); servletClass = jspLoader.loadClass(name); } catch (ClassNotFoundException cex) { - throw new JasperException(Localizer.getMessage("jsp.error.unable.load"), - cex); + throw new JasperException(Localizer.getMessage("jsp.error.unable.load"), cex); } catch (Exception ex) { - throw new JasperException(Localizer.getMessage("jsp.error.unable.compile"), - ex); + throw new JasperException(Localizer.getMessage("jsp.error.unable.compile"), ex); } removed = false; return servletClass; @@ -666,7 +653,7 @@ public class JspCompilationContext { } protected boolean makeOutputDir() { - synchronized(outputDirLock) { + synchronized (outputDirLock) { File outDirFile = new File(outputDir); return (outDirFile.mkdirs() || outDirFile.isDirectory()); } @@ -679,7 +666,7 @@ public class JspCompilationContext { path = tagName.replace('.', File.separatorChar); path = path.substring(0, path.lastIndexOf(File.separatorChar)); } else { - path = getServletPackageName().replace('.',File.separatorChar); + path = getServletPackageName().replace('.', File.separatorChar); } // Append servlet or tag handler path to scratch dir @@ -709,52 +696,47 @@ public class JspCompilationContext { int pos = 0; while (pos < len) { char c = s.charAt(pos); - if ( isPathSeparator(c) ) { + if (isPathSeparator(c)) { /* - * multiple path separators. - * 'foo///bar' -> 'foo/bar' + * multiple path separators. 'foo///bar' -> 'foo/bar' */ - while (pos+1 < len && isPathSeparator(s.charAt(pos+1))) { + while (pos + 1 < len && isPathSeparator(s.charAt(pos + 1))) { ++pos; } - if (pos+1 < len && s.charAt(pos+1) == '.') { + if (pos + 1 < len && s.charAt(pos + 1) == '.') { /* * a single dot at the end of the path - we are done. */ - if (pos+2 >= len) { + if (pos + 2 >= len) { break; } - switch (s.charAt(pos+2)) { + switch (s.charAt(pos + 2)) { /* - * self directory in path - * foo/./bar -> foo/bar + * self directory in path foo/./bar -> foo/bar */ case '/': case '\\': pos += 2; continue; - /* - * two dots in a path: go back one hierarchy. - * foo/bar/../baz -> foo/baz - */ + /* + * two dots in a path: go back one hierarchy. foo/bar/../baz -> foo/baz + */ case '.': // only if we have exactly _two_ dots. - if (pos+3 < len && isPathSeparator(s.charAt(pos+3))) { + if (pos + 3 < len && isPathSeparator(s.charAt(pos + 3))) { pos += 3; - int separatorPos = result.length()-1; - while (separatorPos >= 0 && - ! isPathSeparator(result - .charAt(separatorPos))) { + int separatorPos = result.length() - 1; + while (separatorPos >= 0 && !isPathSeparator(result.charAt(separatorPos))) { --separatorPos; } if (separatorPos >= 0) { result.setLength(separatorPos); } continue; - } + } } } } diff --git a/java/org/apache/jasper/Options.java b/java/org/apache/jasper/Options.java index 075b37b85b..721a66ce88 100644 --- a/java/org/apache/jasper/Options.java +++ b/java/org/apache/jasper/Options.java @@ -35,9 +35,9 @@ import org.apache.jasper.compiler.TldCache; public interface Options { /** - * Returns true if Jasper issues a compilation error instead of a runtime - * Instantiation error if the class attribute specified in useBean action - * is invalid. + * Returns true if Jasper issues a compilation error instead of a runtime Instantiation error if the class attribute + * specified in useBean action is invalid. + * * @return <code>true</code> to get an error */ boolean getErrorOnUseBeanInvalidClassAttribute(); @@ -48,8 +48,7 @@ public interface Options { boolean getKeepGenerated(); /** - * @return <code>true</code> if tag handler pooling is enabled, - * <code>false</code> otherwise. + * @return <code>true</code> if tag handler pooling is enabled, <code>false</code> otherwise. */ boolean isPoolingEnabled(); @@ -59,8 +58,7 @@ public interface Options { boolean getMappedFile(); /** - * @return <code>true</code> if debug information in included - * in compiled classes. + * @return <code>true</code> if debug information in included in compiled classes. */ boolean getClassDebugInfo(); @@ -70,42 +68,36 @@ public interface Options { int getCheckInterval(); /** - * Main development flag, which enables detailed error reports with - * sources, as well automatic recompilation of JSPs and tag files. - * This setting should usually be <code>false</code> when running - * in production. + * Main development flag, which enables detailed error reports with sources, as well automatic recompilation of JSPs + * and tag files. This setting should usually be <code>false</code> when running in production. + * * @return <code>true</code> if Jasper is in development mode */ boolean getDevelopment(); /** - * @return <code>true</code> to include a source fragment in exception - * messages. + * @return <code>true</code> to include a source fragment in exception messages. */ boolean getDisplaySourceFragment(); /** - * @return <code>true</code> to suppress generation of SMAP info for - * JSR45 debugging. + * @return <code>true</code> to suppress generation of SMAP info for JSR45 debugging. */ boolean isSmapSuppressed(); /** * This setting is ignored if suppressSmap() is <code>true</code>. - * @return <code>true</code> to write SMAP info for JSR45 debugging to a - * file. + * + * @return <code>true</code> to write SMAP info for JSR45 debugging to a file. */ boolean isSmapDumped(); /** - * @return {@link TrimSpacesOption#TRUE} to remove template text that - * consists only of whitespace from the output completely, - * {@link TrimSpacesOption#SINGLE} to replace such template text - * with a single space, {@link TrimSpacesOption#FALSE} to leave - * such template text unchanged or {@link TrimSpacesOption#EXTENDED} - * to remove template text that consists only of whitespace and to - * replace any sequence of whitespace and new lines within template - * text with a single new line. + * @return {@link TrimSpacesOption#TRUE} to remove template text that consists only of whitespace from the output + * completely, {@link TrimSpacesOption#SINGLE} to replace such template text with a single space, + * {@link TrimSpacesOption#FALSE} to leave such template text unchanged or + * {@link TrimSpacesOption#EXTENDED} to remove template text that consists only of whitespace and to + * replace any sequence of whitespace and new lines within template text with a single new line. */ TrimSpacesOption getTrimSpaces(); @@ -121,13 +113,11 @@ public interface Options { /** * Compiler to use. - * * <p> - * If <code>null</code> (the default), the java compiler from Eclipse JDT - * project, bundled with Tomcat, will be used. Otherwise, the - * <code>javac</code> task from Apache Ant will be used to call an external - * java compiler and the value of this option will be passed to it. See - * Apache Ant documentation for the possible values. + * If <code>null</code> (the default), the java compiler from Eclipse JDT project, bundled with Tomcat, will be + * used. Otherwise, the <code>javac</code> task from Apache Ant will be used to call an external java compiler and + * the value of this option will be passed to it. See Apache Ant documentation for the possible values. + * * @return the compiler name */ String getCompiler(); @@ -148,14 +138,11 @@ public interface Options { String getCompilerClassName(); /** - * The cache that maps URIs, resource paths and parsed TLD files for the - * various tag libraries 'exposed' by the web application. - * A tag library is 'exposed' either explicitly in - * web.xml or implicitly via the uri tag in the TLD - * of a taglib deployed in a jar file (WEB-INF/lib). + * The cache that maps URIs, resource paths and parsed TLD files for the various tag libraries 'exposed' by the web + * application. A tag library is 'exposed' either explicitly in web.xml or implicitly via the uri tag in the TLD of + * a taglib deployed in a jar file (WEB-INF/lib). * - * @return the instance of the TldCache - * for the web-application. + * @return the instance of the TldCache for the web-application. */ TldCache getTldCache(); @@ -166,10 +153,9 @@ public interface Options { /** * The boolean flag to tell Ant whether to fork JSP page compilations. - * * <p> - * Is used only when Jasper uses an external java compiler (wrapped through - * a <code>javac</code> Apache Ant task). + * Is used only when Jasper uses an external java compiler (wrapped through a <code>javac</code> Apache Ant task). + * * @return <code>true</code> to fork a process during compilation */ boolean getFork(); @@ -192,8 +178,7 @@ public interface Options { /** * Indicates whether text strings are to be generated as char arrays. * - * @return <code>true</code> if text strings are to be generated as char - * arrays, <code>false</code> otherwise + * @return <code>true</code> if text strings are to be generated as char arrays, <code>false</code> otherwise */ boolean genStringAsCharArray(); @@ -209,86 +194,79 @@ public interface Options { boolean getRecompileOnFail(); /** - * @return <code>true</code> is caching is enabled - * (used for precompilation). + * @return <code>true</code> is caching is enabled (used for precompilation). */ boolean isCaching(); /** - * The web-application wide cache for the TagLibraryInfo tag library - * descriptors, used if {@link #isCaching()} returns <code>true</code>. - * + * The web-application wide cache for the TagLibraryInfo tag library descriptors, used if {@link #isCaching()} + * returns <code>true</code>. * <p> - * Using this cache avoids the cost of repeating the parsing of a tag - * library descriptor XML file (performed by TagLibraryInfoImpl.parseTLD). + * Using this cache avoids the cost of repeating the parsing of a tag library descriptor XML file (performed by + * TagLibraryInfoImpl.parseTLD). * </p> * * @return the Map(String uri, TagLibraryInfo tld) instance. */ - Map<String, TagLibraryInfo> getCache(); + Map<String,TagLibraryInfo> getCache(); /** - * The maximum number of loaded jsps per web-application. If there are more - * jsps loaded, they will be unloaded. If unset or less than 0, no jsps - * are unloaded. + * The maximum number of loaded jsps per web-application. If there are more jsps loaded, they will be unloaded. If + * unset or less than 0, no jsps are unloaded. + * * @return The JSP count */ int getMaxLoadedJsps(); /** - * @return the idle time in seconds after which a JSP is unloaded. - * If unset or less or equal than 0, no jsps are unloaded. + * @return the idle time in seconds after which a JSP is unloaded. If unset or less or equal than 0, no jsps are + * unloaded. */ int getJspIdleTimeout(); /** - * @return {@code true} if the quote escaping required by section JSP.1.6 of - * the JSP specification should be applied to scriplet expression. + * @return {@code true} if the quote escaping required by section JSP.1.6 of the JSP specification should be applied + * to scriplet expression. */ boolean getStrictQuoteEscaping(); /** - * @return {@code true} if EL expressions used within attributes should have - * the quoting rules in JSP.1.6 applied to the expression. + * @return {@code true} if EL expressions used within attributes should have the quoting rules in JSP.1.6 applied to + * the expression. */ boolean getQuoteAttributeEL(); /** - * @return the name of the variable that will be used in the generated - * JSP code for the expression factory + * @return the name of the variable that will be used in the generated JSP code for the expression factory */ default String getVariableForExpressionFactory() { return "_el_expressionfactory"; } /** - * @return the name of the variable that will be used in the generated - * JSP code for the instance manager + * @return the name of the variable that will be used in the generated JSP code for the instance manager */ default String getVariableForInstanceManager() { return "_jsp_instancemanager"; } /** - * @return {@code true} if tag pooling is disabled with page that uses - * extends. + * @return {@code true} if tag pooling is disabled with page that uses extends. */ default boolean getPoolTagsWithExtends() { return false; } /** - * @return {@code true} if the requirement to have the object - * used in jsp:getProperty action to be previously "introduced" - * to the JSP processor (see JSP.5.3) is enforced. + * @return {@code true} if the requirement to have the object used in jsp:getProperty action to be previously + * "introduced" to the JSP processor (see JSP.5.3) is enforced. */ default boolean getStrictGetProperty() { return true; } /** - * @return {@code true} if the strict white space rules are - * applied. + * @return {@code true} if the strict white space rules are applied. */ default boolean getStrictWhitespace() { return true; @@ -302,9 +280,9 @@ public interface Options { } /** - * _jspService is the name of the method that is called by - * HttpJspBase.service(). This is where most of the code generated - * from JSPs go. + * _jspService is the name of the method that is called by HttpJspBase.service(). This is where most of the code + * generated from JSPs go. + * * @return the method name */ default String getServiceMethodName() { @@ -312,17 +290,15 @@ public interface Options { } /** - * @return ServletContext attribute for classpath. This is tomcat specific. - * Other servlet engines may choose to support this attribute if they - * want to have this JSP engine running on them. + * @return ServletContext attribute for classpath. This is tomcat specific. Other servlet engines may choose to + * support this attribute if they want to have this JSP engine running on them. */ default String getServletClasspathAttribute() { return "org.apache.catalina.jsp_classpath"; } /** - * @return The query parameter that causes the JSP engine to just - * pregenerated the servlet but not invoke it. + * @return The query parameter that causes the JSP engine to just pregenerated the servlet but not invoke it. */ default String getJspPrecompilationQueryParameter() { return "jsp_precompile"; @@ -350,8 +326,7 @@ public interface Options { } /** - * @return {@code true} if the container instance manager will be used - * to create the bean instances + * @return {@code true} if the container instance manager will be used to create the bean instances */ default boolean getUseInstanceManagerForTags() { return false; @@ -359,9 +334,8 @@ public interface Options { /** - * Should the container include the time the file was generated in the - * comments at the start of a Java file generated from a JSP or tag. - * Defaults to {@code true}. + * Should the container include the time the file was generated in the comments at the start of a Java file + * generated from a JSP or tag. Defaults to {@code true}. * * @return {@code true} to include the timestamp, otherwise don't include it */ --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org