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 c578fdafa64c4549bea7d26aa06ec70fa20dbd33 Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri May 17 19:27:47 2024 +0100 Code clean-up - formatting. No functional change --- java/org/apache/catalina/util/CharsetMapper.java | 37 ++-- java/org/apache/catalina/util/ContextName.java | 32 ++- .../catalina/util/CustomObjectInputStream.java | 59 +++--- java/org/apache/catalina/util/DOMWriter.java | 5 +- .../org/apache/catalina/util/ErrorPageSupport.java | 10 +- java/org/apache/catalina/util/IOTools.java | 36 ++-- java/org/apache/catalina/util/Introspection.java | 56 ++--- java/org/apache/catalina/util/LifecycleBase.java | 85 +++----- .../apache/catalina/util/LifecycleMBeanBase.java | 65 +++--- java/org/apache/catalina/util/ParameterMap.java | 33 ++- java/org/apache/catalina/util/RequestUtil.java | 9 +- java/org/apache/catalina/util/ResourceSet.java | 31 +-- java/org/apache/catalina/util/ServerInfo.java | 21 +- java/org/apache/catalina/util/SessionConfig.java | 14 +- .../catalina/util/SessionIdGeneratorBase.java | 97 ++++----- .../catalina/util/StandardSessionIdGenerator.java | 4 +- java/org/apache/catalina/util/Strftime.java | 232 ++++++++++----------- java/org/apache/catalina/util/StringUtil.java | 10 +- java/org/apache/catalina/util/TLSUtil.java | 10 +- .../apache/catalina/util/TimeBucketCounter.java | 8 +- java/org/apache/catalina/util/ToStringUtil.java | 6 +- java/org/apache/catalina/util/TomcatCSS.java | 13 +- java/org/apache/catalina/util/URLEncoder.java | 30 ++- java/org/apache/catalina/util/XMLWriter.java | 122 ++++++----- 24 files changed, 445 insertions(+), 580 deletions(-) diff --git a/java/org/apache/catalina/util/CharsetMapper.java b/java/org/apache/catalina/util/CharsetMapper.java index c04d1c5e4e..5bb215e62f 100644 --- a/java/org/apache/catalina/util/CharsetMapper.java +++ b/java/org/apache/catalina/util/CharsetMapper.java @@ -25,14 +25,11 @@ import org.apache.tomcat.util.ExceptionUtils; import org.apache.tomcat.util.compat.JreCompat; - /** - * Utility class that attempts to map from a Locale to the corresponding - * character set to be used for interpreting input text (or generating - * output text) when the Content-Type header does not include one. You - * can customize the behavior of this class by modifying the mapping data - * it loads, or by subclassing it (to change the algorithm) and then using - * your own version for a particular web application. + * Utility class that attempts to map from a Locale to the corresponding character set to be used for interpreting input + * text (or generating output text) when the Content-Type header does not include one. You can customize the behavior of + * this class by modifying the mapping data it loads, or by subclassing it (to change the algorithm) and then using your + * own version for a particular web application. * * @author Craig R. McClanahan */ @@ -45,8 +42,7 @@ public class CharsetMapper { /** * Default properties resource name. */ - public static final String DEFAULT_RESOURCE = - "/org/apache/catalina/util/CharsetMapperDefault.properties"; + public static final String DEFAULT_RESOURCE = "/org/apache/catalina/util/CharsetMapperDefault.properties"; // ---------------------------------------------------------- Constructors @@ -65,8 +61,7 @@ public class CharsetMapper { * * @param name Name of a properties resource to be loaded * - * @exception IllegalArgumentException if the specified properties - * resource could not be loaded for any reason. + * @exception IllegalArgumentException if the specified properties resource could not be loaded for any reason. */ public CharsetMapper(String name) { if (JreCompat.isGraalAvailable()) { @@ -86,8 +81,7 @@ public class CharsetMapper { /** - * The mapping properties that have been initialized from the specified or - * default properties resource. + * The mapping properties that have been initialized from the specified or default properties resource. */ private Properties map = new Properties(); @@ -96,11 +90,11 @@ public class CharsetMapper { /** - * Calculate the name of a character set to be assumed, given the specified - * Locale and the absence of a character set specified as part of the - * content type header. + * Calculate the name of a character set to be assumed, given the specified Locale and the absence of a character + * set specified as part of the content type header. * * @param locale The locale for which to calculate a character set + * * @return the charset name */ public String getCharset(Locale locale) { @@ -108,8 +102,7 @@ public class CharsetMapper { // then language only String charset = map.getProperty(locale.toString()); if (charset == null) { - charset = map.getProperty(locale.getLanguage() + "_" - + locale.getCountry()); + charset = map.getProperty(locale.getLanguage() + "_" + locale.getCountry()); if (charset == null) { charset = map.getProperty(locale.getLanguage()); } @@ -119,12 +112,10 @@ public class CharsetMapper { /** - * The deployment descriptor can have a - * locale-encoding-mapping-list element which describes the - * webapp's desired mapping from locale to charset. This method - * gets called when processing the web.xml file for a context + * The deployment descriptor can have a locale-encoding-mapping-list element which describes the webapp's desired + * mapping from locale to charset. This method gets called when processing the web.xml file for a context * - * @param locale The locale for a character set + * @param locale The locale for a character set * @param charset The charset to be associated with the locale */ public void addCharsetMappingFromDeploymentDescriptor(String locale, String charset) { diff --git a/java/org/apache/catalina/util/ContextName.java b/java/org/apache/catalina/util/ContextName.java index f426d41972..14588a9bfd 100644 --- a/java/org/apache/catalina/util/ContextName.java +++ b/java/org/apache/catalina/util/ContextName.java @@ -19,8 +19,8 @@ package org.apache.catalina.util; import java.util.Locale; /** - * Utility class to manage context names so there is one place where the - * conversions between baseName, path and version take place. + * Utility class to manage context names so there is one place where the conversions between baseName, path and version + * take place. */ public final class ContextName { public static final String ROOT_NAME = "ROOT"; @@ -34,13 +34,11 @@ public final class ContextName { /** - * Creates an instance from a context name, display name, base name, - * directory name, WAR name or context.xml name. + * Creates an instance from a context name, display name, base name, directory name, WAR name or context.xml name. * - * @param name The name to use as the basis for this object - * @param stripFileExtension If a .war or .xml file extension is present - * at the end of the provided name should it be - * removed? + * @param name The name to use as the basis for this object + * @param stripFileExtension If a .war or .xml file extension is present at the end of the provided name should it + * be removed? */ public ContextName(String name, boolean stripFileExtension) { @@ -62,10 +60,9 @@ public final class ContextName { } // Remove any file extensions - if (stripFileExtension && - (tmp1.toLowerCase(Locale.ENGLISH).endsWith(".war") || - tmp1.toLowerCase(Locale.ENGLISH).endsWith(".xml"))) { - tmp1 = tmp1.substring(0, tmp1.length() -4); + if (stripFileExtension && (tmp1.toLowerCase(Locale.ENGLISH).endsWith(".war") || + tmp1.toLowerCase(Locale.ENGLISH).endsWith(".xml"))) { + tmp1 = tmp1.substring(0, tmp1.length() - 4); } baseName = tmp1; @@ -97,8 +94,8 @@ public final class ContextName { /** * Construct an instance from a path and version. * - * @param path Context path to use - * @param version Context version to use + * @param path Context path to use + * @param version Context version to use */ public ContextName(String path, String version) { // Path should never be null, '/' or '/ROOT' @@ -127,8 +124,7 @@ public final class ContextName { if (this.path.isEmpty()) { tmp.append(ROOT_NAME); } else { - tmp.append(this.path.substring(1).replace('/', - FWD_SLASH_REPLACEMENT)); + tmp.append(this.path.substring(1).replace('/', FWD_SLASH_REPLACEMENT)); } if (!this.version.isEmpty()) { tmp.append(VERSION_MARKER); @@ -176,8 +172,8 @@ public final class ContextName { /** - * Extract the final component of the given path which is assumed to be a - * base name and generate a {@link ContextName} from that base name. + * Extract the final component of the given path which is assumed to be a base name and generate a + * {@link ContextName} from that base name. * * @param path The path that ends in a base name * diff --git a/java/org/apache/catalina/util/CustomObjectInputStream.java b/java/org/apache/catalina/util/CustomObjectInputStream.java index c6f41cd9da..85bf8ae263 100644 --- a/java/org/apache/catalina/util/CustomObjectInputStream.java +++ b/java/org/apache/catalina/util/CustomObjectInputStream.java @@ -31,9 +31,8 @@ import org.apache.juli.logging.Log; import org.apache.tomcat.util.res.StringManager; /** - * Custom subclass of <code>ObjectInputStream</code> that loads from the - * class loader for this web application. This allows classes defined only - * with the web application to be found correctly. + * Custom subclass of <code>ObjectInputStream</code> that loads from the class loader for this web application. This + * allows classes defined only with the web application to be found correctly. * * @author Craig R. McClanahan * @author Bip Thelin @@ -42,8 +41,7 @@ public final class CustomObjectInputStream extends ObjectInputStream { private static final StringManager sm = StringManager.getManager(CustomObjectInputStream.class); - private static final WeakHashMap<ClassLoader, Set<String>> reportedClassCache = - new WeakHashMap<>(); + private static final WeakHashMap<ClassLoader,Set<String>> reportedClassCache = new WeakHashMap<>(); /** * The class loader we will use to resolve classes. @@ -58,10 +56,9 @@ public final class CustomObjectInputStream extends ObjectInputStream { /** - * Construct a new instance of CustomObjectInputStream without any filtering - * of deserialized classes. + * Construct a new instance of CustomObjectInputStream without any filtering of deserialized classes. * - * @param stream The input stream we will read from + * @param stream The input stream we will read from * @param classLoader The class loader used to instantiate objects * * @exception IOException if an input/output error occurs @@ -72,29 +69,24 @@ public final class CustomObjectInputStream extends ObjectInputStream { /** - * Construct a new instance of CustomObjectInputStream with filtering of - * deserialized classes. + * Construct a new instance of CustomObjectInputStream with filtering of deserialized classes. * - * @param stream The input stream we will read from - * @param classLoader The class loader used to instantiate objects - * @param log The logger to use to report any issues. It may only be null if - * the filterMode does not require logging - * @param allowedClassNamePattern The regular expression to use to filter - * deserialized classes. The fully qualified - * class name must match this pattern for - * deserialization to be allowed if filtering - * is enabled. - * @param warnOnFailure Should any failures be logged? + * @param stream The input stream we will read from + * @param classLoader The class loader used to instantiate objects + * @param log The logger to use to report any issues. It may only be null if the filterMode does + * not require logging + * @param allowedClassNamePattern The regular expression to use to filter deserialized classes. The fully qualified + * class name must match this pattern for deserialization to be allowed if + * filtering is enabled. + * @param warnOnFailure Should any failures be logged? * * @exception IOException if an input/output error occurs */ - public CustomObjectInputStream(InputStream stream, ClassLoader classLoader, - Log log, Pattern allowedClassNamePattern, boolean warnOnFailure) - throws IOException { + public CustomObjectInputStream(InputStream stream, ClassLoader classLoader, Log log, + Pattern allowedClassNamePattern, boolean warnOnFailure) throws IOException { super(stream); if (log == null && allowedClassNamePattern != null && warnOnFailure) { - throw new IllegalArgumentException( - sm.getString("customObjectInputStream.logRequired")); + throw new IllegalArgumentException(sm.getString("customObjectInputStream.logRequired")); } this.classLoader = classLoader; this.log = log; @@ -127,17 +119,16 @@ public final class CustomObjectInputStream extends ObjectInputStream { /** - * Load the local class equivalent of the specified stream class - * description, by using the class loader assigned to this Context. + * Load the local class equivalent of the specified stream class description, by using the class loader assigned to + * this Context. * * @param classDesc Class description from the input stream * * @exception ClassNotFoundException if this class cannot be found - * @exception IOException if an input/output error occurs + * @exception IOException if an input/output error occurs */ @Override - public Class<?> resolveClass(ObjectStreamClass classDesc) - throws ClassNotFoundException, IOException { + public Class<?> resolveClass(ObjectStreamClass classDesc) throws ClassNotFoundException, IOException { String name = classDesc.getName(); if (allowedClassNamePattern != null) { @@ -170,13 +161,11 @@ public final class CustomObjectInputStream extends ObjectInputStream { /** - * Return a proxy class that implements the interfaces named in a proxy - * class descriptor. Do this using the class loader assigned to this - * Context. + * Return a proxy class that implements the interfaces named in a proxy class descriptor. Do this using the class + * loader assigned to this Context. */ @Override - protected Class<?> resolveProxyClass(String[] interfaces) - throws IOException, ClassNotFoundException { + protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException { Class<?>[] cinterfaces = new Class[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { diff --git a/java/org/apache/catalina/util/DOMWriter.java b/java/org/apache/catalina/util/DOMWriter.java index 96f6567764..0cd3532526 100644 --- a/java/org/apache/catalina/util/DOMWriter.java +++ b/java/org/apache/catalina/util/DOMWriter.java @@ -41,6 +41,7 @@ public class DOMWriter { /** * Prints the specified node, recursively. + * * @param node The node to output */ public void print(Node node) { @@ -102,7 +103,7 @@ public class DOMWriter { } out.print("?>"); break; - } + } if (type == Node.ELEMENT_NODE) { out.print("</"); @@ -128,7 +129,9 @@ public class DOMWriter { /** * Returns a sorted list of attributes. + * * @param attrs The map to sort + * * @return a sorted attribute array */ private Attr[] sortAttributes(NamedNodeMap attrs) { diff --git a/java/org/apache/catalina/util/ErrorPageSupport.java b/java/org/apache/catalina/util/ErrorPageSupport.java index 93012befdf..d87c21fe7a 100644 --- a/java/org/apache/catalina/util/ErrorPageSupport.java +++ b/java/org/apache/catalina/util/ErrorPageSupport.java @@ -24,16 +24,15 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.tomcat.util.descriptor.web.ErrorPage; /** - * Provides support for tracking per exception type and per HTTP status code - * error pages. + * Provides support for tracking per exception type and per HTTP status code error pages. */ public class ErrorPageSupport { // Fully qualified class name to error page - private Map<String, ErrorPage> exceptionPages = new ConcurrentHashMap<>(); + private Map<String,ErrorPage> exceptionPages = new ConcurrentHashMap<>(); // HTTP status code to error page - private Map<Integer, ErrorPage> statusPages = new ConcurrentHashMap<>(); + private Map<Integer,ErrorPage> statusPages = new ConcurrentHashMap<>(); public void add(ErrorPage errorPage) { @@ -66,8 +65,7 @@ public class ErrorPageSupport { * * @param exceptionType The fully qualified class name of the exception type * - * @return The ErrorPage for the named exception type, or {@code null} if - * none is configured + * @return The ErrorPage for the named exception type, or {@code null} if none is configured */ public ErrorPage find(String exceptionType) { return exceptionPages.get(exceptionType); diff --git a/java/org/apache/catalina/util/IOTools.java b/java/org/apache/catalina/util/IOTools.java index 7b5507dfbd..a9835bb29c 100644 --- a/java/org/apache/catalina/util/IOTools.java +++ b/java/org/apache/catalina/util/IOTools.java @@ -29,49 +29,47 @@ import java.io.Writer; * @author Dan Sandberg */ public class IOTools { - protected static final int DEFAULT_BUFFER_SIZE=4*1024; //4k + protected static final int DEFAULT_BUFFER_SIZE = 4 * 1024; // 4k private IOTools() { - //Ensure non-instantiability + // Ensure non-instantiability } /** - * Read input from reader and write it to writer until there is no more - * input from reader. + * Read input from reader and write it to writer until there is no more input from reader. * * @param reader the reader to read from. * @param writer the writer to write to. - * @param buf the char array to use as a buffer + * @param buf the char array to use as a buffer + * * @throws IOException IO error */ - public static void flow( Reader reader, Writer writer, char[] buf ) - throws IOException { + public static void flow(Reader reader, Writer writer, char[] buf) throws IOException { int numRead; - while ( (numRead = reader.read(buf) ) >= 0) { + while ((numRead = reader.read(buf)) >= 0) { writer.write(buf, 0, numRead); } } /** - * Read input from reader and write it to writer until there is no more - * input from reader. + * Read input from reader and write it to writer until there is no more input from reader. * * @param reader the reader to read from. * @param writer the writer to write to. + * * @throws IOException IO error + * * @see #flow( Reader, Writer, char[] ) */ - public static void flow( Reader reader, Writer writer ) - throws IOException { + public static void flow(Reader reader, Writer writer) throws IOException { char[] buf = new char[DEFAULT_BUFFER_SIZE]; - flow( reader, writer, buf ); + flow(reader, writer, buf); } /** - * Read input from input stream and write it to output stream until there is - * no more input from input stream using a new buffer of the default size - * (4 KiB). + * Read input from input stream and write it to output stream until there is no more input from input stream using a + * new buffer of the default size (4 KiB). * * @param is input stream the input stream to read from. * @param os output stream the output stream to write to. @@ -81,7 +79,7 @@ public class IOTools { public static void flow(InputStream is, OutputStream os) throws IOException { byte[] buf = new byte[DEFAULT_BUFFER_SIZE]; int numRead; - while ( (numRead = is.read(buf) ) >= 0) { + while ((numRead = is.read(buf)) >= 0) { if (os != null) { os.write(buf, 0, numRead); } @@ -92,8 +90,8 @@ public class IOTools { /** * Read until EOF or the buffer is filled. * - * @param is The source to read from - * @param buf The buffer to write to + * @param is The source to read from + * @param buf The buffer to write to * * @return The number of bytes read * diff --git a/java/org/apache/catalina/util/Introspection.java b/java/org/apache/catalina/util/Introspection.java index cff56d0878..9b1e7f066b 100644 --- a/java/org/apache/catalina/util/Introspection.java +++ b/java/org/apache/catalina/util/Introspection.java @@ -26,21 +26,20 @@ import org.apache.tomcat.util.ExceptionUtils; import org.apache.tomcat.util.res.StringManager; /** - * Provides introspection utilities that either require knowledge of Tomcat - * internals or are solely used by Tomcat internals. + * Provides introspection utilities that either require knowledge of Tomcat internals or are solely used by Tomcat + * internals. */ public class Introspection { - private static final StringManager sm = - StringManager.getManager("org.apache.catalina.util"); + private static final StringManager sm = StringManager.getManager("org.apache.catalina.util"); /** - * Extract the Java Bean property name from the setter name. + * Extract the Java Bean property name from the setter name. Note: This method assumes that the method name has + * already been checked for correctness. * - * Note: This method assumes that the method name has already been checked - * for correctness. * @param setter The setter method + * * @return the bean property name */ public static String getPropertyName(Method setter) { @@ -49,19 +48,15 @@ public class Introspection { /** - * Determines if a method has a valid name and signature for a Java Bean - * setter. + * Determines if a method has a valid name and signature for a Java Bean setter. * - * @param method The method to test + * @param method The method to test * - * @return <code>true</code> if the method does have a valid name and - * signature, else <code>false</code> + * @return <code>true</code> if the method does have a valid name and signature, else <code>false</code> */ public static boolean isValidSetter(Method method) { - if (method.getName().startsWith("set") - && method.getName().length() > 3 - && method.getParameterTypes().length == 1 - && method.getReturnType().getName().equals("void")) { + if (method.getName().startsWith("set") && method.getName().length() > 3 && + method.getParameterTypes().length == 1 && method.getReturnType().getName().equals("void")) { return true; } return false; @@ -70,29 +65,25 @@ public class Introspection { /** * Determines if a method is a valid lifecycle callback method. * - * @param method - * The method to test + * @param method The method to test * - * @return <code>true</code> if the method is a valid lifecycle callback - * method, else <code>false</code> + * @return <code>true</code> if the method is a valid lifecycle callback method, else <code>false</code> */ public static boolean isValidLifecycleCallback(Method method) { - if (method.getParameterTypes().length != 0 - || Modifier.isStatic(method.getModifiers()) - || method.getExceptionTypes().length > 0 - || !method.getReturnType().getName().equals("void")) { + if (method.getParameterTypes().length != 0 || Modifier.isStatic(method.getModifiers()) || + method.getExceptionTypes().length > 0 || !method.getReturnType().getName().equals("void")) { return false; } return true; } /** - * Attempt to load a class using the given Container's class loader. If the - * class cannot be loaded, a debug level log message will be written to the - * Container's log and null will be returned. - * @param context The class loader of this context will be used to attempt - * to load the class + * Attempt to load a class using the given Container's class loader. If the class cannot be loaded, a debug level + * log message will be written to the Container's log and null will be returned. + * + * @param context The class loader of this context will be used to attempt to load the class * @param className The class name + * * @return the loaded class or <code>null</code> if loading failed */ public static Class<?> loadClass(Context context, String className) { @@ -113,10 +104,9 @@ public class Introspection { /** * Converts the primitive type to its corresponding wrapper. * - * @param clazz - * Class that will be evaluated - * @return if the parameter is a primitive type returns its wrapper; - * otherwise returns the same class + * @param clazz Class that will be evaluated + * + * @return if the parameter is a primitive type returns its wrapper; otherwise returns the same class */ public static Class<?> convertPrimitiveType(Class<?> clazz) { if (clazz.equals(char.class)) { diff --git a/java/org/apache/catalina/util/LifecycleBase.java b/java/org/apache/catalina/util/LifecycleBase.java index f25af03fa5..ec7abb1b22 100644 --- a/java/org/apache/catalina/util/LifecycleBase.java +++ b/java/org/apache/catalina/util/LifecycleBase.java @@ -30,9 +30,8 @@ import org.apache.tomcat.util.ExceptionUtils; import org.apache.tomcat.util.res.StringManager; /** - * Base implementation of the {@link Lifecycle} interface that implements the - * state transition rules for {@link Lifecycle#start()} and - * {@link Lifecycle#stop()} + * Base implementation of the {@link Lifecycle} interface that implements the state transition rules for + * {@link Lifecycle#start()} and {@link Lifecycle#stop()} */ public abstract class LifecycleBase implements Lifecycle { @@ -57,13 +56,11 @@ public abstract class LifecycleBase implements Lifecycle { /** - * Will a {@link LifecycleException} thrown by a sub-class during - * {@link #initInternal()}, {@link #startInternal()}, - * {@link #stopInternal()} or {@link #destroyInternal()} be re-thrown for - * the caller to handle or will it be logged instead? + * Will a {@link LifecycleException} thrown by a sub-class during {@link #initInternal()}, {@link #startInternal()}, + * {@link #stopInternal()} or {@link #destroyInternal()} be re-thrown for the caller to handle or will it be logged + * instead? * - * @return {@code true} if the exception will be re-thrown, otherwise - * {@code false} + * @return {@code true} if the exception will be re-thrown, otherwise {@code false} */ public boolean getThrowOnFailure() { return throwOnFailure; @@ -71,13 +68,11 @@ public abstract class LifecycleBase implements Lifecycle { /** - * Configure if a {@link LifecycleException} thrown by a sub-class during - * {@link #initInternal()}, {@link #startInternal()}, - * {@link #stopInternal()} or {@link #destroyInternal()} will be re-thrown - * for the caller to handle or if it will be logged instead. + * Configure if a {@link LifecycleException} thrown by a sub-class during {@link #initInternal()}, + * {@link #startInternal()}, {@link #stopInternal()} or {@link #destroyInternal()} will be re-thrown for the caller + * to handle or if it will be logged instead. * - * @param throwOnFailure {@code true} if the exception should be re-thrown, - * otherwise {@code false} + * @param throwOnFailure {@code true} if the exception should be re-thrown, otherwise {@code false} */ public void setThrowOnFailure(boolean throwOnFailure) { this.throwOnFailure = throwOnFailure; @@ -105,8 +100,8 @@ public abstract class LifecycleBase implements Lifecycle { /** * Allow sub classes to fire {@link Lifecycle} events. * - * @param type Event type - * @param data Data associated with event. + * @param type Event type + * @param data Data associated with event. */ protected void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(this, type, data); @@ -133,8 +128,7 @@ public abstract class LifecycleBase implements Lifecycle { /** - * Sub-classes implement this method to perform any instance initialisation - * required. + * Sub-classes implement this method to perform any instance initialisation required. * * @throws LifecycleException If the initialisation fails */ @@ -161,8 +155,7 @@ public abstract class LifecycleBase implements Lifecycle { init(); } else if (state.equals(LifecycleState.FAILED)) { stop(); - } else if (!state.equals(LifecycleState.INITIALIZED) && - !state.equals(LifecycleState.STOPPED)) { + } else if (!state.equals(LifecycleState.INITIALIZED) && !state.equals(LifecycleState.STOPPED)) { invalidTransition(BEFORE_START_EVENT); } @@ -189,15 +182,11 @@ public abstract class LifecycleBase implements Lifecycle { /** - * Sub-classes must ensure that the state is changed to - * {@link LifecycleState#STARTING} during the execution of this method. - * Changing state will trigger the {@link Lifecycle#START_EVENT} event. - * - * If a component fails to start it may either throw a - * {@link LifecycleException} which will cause it's parent to fail to start - * or it can place itself in the error state in which case {@link #stop()} - * will be called on the failed component but the parent component will - * continue to start normally. + * Sub-classes must ensure that the state is changed to {@link LifecycleState#STARTING} during the execution of this + * method. Changing state will trigger the {@link Lifecycle#START_EVENT} event. If a component fails to start it may + * either throw a {@link LifecycleException} which will cause it's parent to fail to start or it can place itself in + * the error state in which case {@link #stop()} will be called on the failed component but the parent component + * will continue to start normally. * * @throws LifecycleException Start error occurred */ @@ -261,9 +250,8 @@ public abstract class LifecycleBase implements Lifecycle { /** - * Sub-classes must ensure that the state is changed to - * {@link LifecycleState#STOPPING} during the execution of this method. - * Changing state will trigger the {@link Lifecycle#STOP_EVENT} event. + * Sub-classes must ensure that the state is changed to {@link LifecycleState#STOPPING} during the execution of this + * method. Changing state will trigger the {@link Lifecycle#STOP_EVENT} event. * * @throws LifecycleException Stop error occurred */ @@ -312,8 +300,7 @@ public abstract class LifecycleBase implements Lifecycle { /** - * Sub-classes implement this method to perform any instance destruction - * required. + * Sub-classes implement this method to perform any instance destruction required. * * @throws LifecycleException If the destruction fails */ @@ -333,12 +320,12 @@ public abstract class LifecycleBase implements Lifecycle { /** - * Provides a mechanism for sub-classes to update the component state. - * Calling this method will automatically fire any associated - * {@link Lifecycle} event. It will also check that any attempted state - * transition is valid for a sub-class. + * Provides a mechanism for sub-classes to update the component state. Calling this method will automatically fire + * any associated {@link Lifecycle} event. It will also check that any attempted state transition is valid for a + * sub-class. * * @param state The new state for this component + * * @throws LifecycleException when attempting to set an invalid state */ protected synchronized void setState(LifecycleState state) throws LifecycleException { @@ -347,17 +334,16 @@ public abstract class LifecycleBase implements Lifecycle { /** - * Provides a mechanism for sub-classes to update the component state. - * Calling this method will automatically fire any associated - * {@link Lifecycle} event. It will also check that any attempted state - * transition is valid for a sub-class. + * Provides a mechanism for sub-classes to update the component state. Calling this method will automatically fire + * any associated {@link Lifecycle} event. It will also check that any attempted state transition is valid for a + * sub-class. * * @param state The new state for this component * @param data The data to pass to the associated {@link Lifecycle} event + * * @throws LifecycleException when attempting to set an invalid state */ - protected synchronized void setState(LifecycleState state, Object data) - throws LifecycleException { + protected synchronized void setState(LifecycleState state, Object data) throws LifecycleException { setStateInternal(state, data, true); } @@ -385,12 +371,9 @@ public abstract class LifecycleBase implements Lifecycle { // stopInternal() permits STOPPING_PREP to STOPPING and FAILED to // STOPPING if (!(state == LifecycleState.FAILED || - (this.state == LifecycleState.STARTING_PREP && - state == LifecycleState.STARTING) || - (this.state == LifecycleState.STOPPING_PREP && - state == LifecycleState.STOPPING) || - (this.state == LifecycleState.FAILED && - state == LifecycleState.STOPPING))) { + (this.state == LifecycleState.STARTING_PREP && state == LifecycleState.STARTING) || + (this.state == LifecycleState.STOPPING_PREP && state == LifecycleState.STOPPING) || + (this.state == LifecycleState.FAILED && state == LifecycleState.STOPPING))) { // No other transition permitted invalidTransition(state.name()); } diff --git a/java/org/apache/catalina/util/LifecycleMBeanBase.java b/java/org/apache/catalina/util/LifecycleMBeanBase.java index e6ba64aa53..e4db48c832 100644 --- a/java/org/apache/catalina/util/LifecycleMBeanBase.java +++ b/java/org/apache/catalina/util/LifecycleMBeanBase.java @@ -27,13 +27,11 @@ import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.modeler.Registry; import org.apache.tomcat.util.res.StringManager; -public abstract class LifecycleMBeanBase extends LifecycleBase - implements JmxEnabled { +public abstract class LifecycleMBeanBase extends LifecycleBase implements JmxEnabled { private static final Log log = LogFactory.getLog(LifecycleMBeanBase.class); - private static final StringManager sm = - StringManager.getManager("org.apache.catalina.util"); + private static final StringManager sm = StringManager.getManager("org.apache.catalina.util"); /* Cache components of the MBean registration. */ @@ -77,10 +75,9 @@ public abstract class LifecycleMBeanBase extends LifecycleBase /** - * Method implemented by sub-classes to identify the domain in which MBeans - * should be registered. + * Method implemented by sub-classes to identify the domain in which MBeans should be registered. * - * @return The name of the domain to use to register MBeans. + * @return The name of the domain to use to register MBeans. */ protected abstract String getDomainInternal(); @@ -92,31 +89,26 @@ public abstract class LifecycleMBeanBase extends LifecycleBase /** - * Allow sub-classes to specify the key properties component of the - * {@link ObjectName} that will be used to register this component. + * Allow sub-classes to specify the key properties component of the {@link ObjectName} that will be used to register + * this component. * - * @return The string representation of the key properties component of the - * desired {@link ObjectName} + * @return The string representation of the key properties component of the desired {@link ObjectName} */ protected abstract String getObjectNameKeyProperties(); /** - * Utility method to enable sub-classes to easily register additional - * components that don't implement {@link JmxEnabled} with an MBean server. - * <br> - * Note: This method should only be used once {@link #initInternal()} has - * been called and before {@link #destroyInternal()} has been called. + * Utility method to enable sub-classes to easily register additional components that don't implement + * {@link JmxEnabled} with an MBean server. <br> + * Note: This method should only be used once {@link #initInternal()} has been called and before + * {@link #destroyInternal()} has been called. * - * @param obj The object the register - * @param objectNameKeyProperties The key properties component of the - * object name to use to register the - * object + * @param obj The object the register + * @param objectNameKeyProperties The key properties component of the object name to use to register the object * - * @return The name used to register the object + * @return The name used to register the object */ - protected final ObjectName register(Object obj, - String objectNameKeyProperties) { + protected final ObjectName register(Object obj, String objectNameKeyProperties) { // Construct an object name with the right domain StringBuilder name = new StringBuilder(getDomain()); @@ -137,15 +129,12 @@ public abstract class LifecycleMBeanBase extends LifecycleBase /** - * Utility method to enable sub-classes to easily unregister additional - * components that don't implement {@link JmxEnabled} with an MBean server. - * <br> - * Note: This method should only be used once {@link #initInternal()} has - * been called and before {@link #destroyInternal()} has been called. + * Utility method to enable sub-classes to easily unregister additional components that don't implement + * {@link JmxEnabled} with an MBean server. <br> + * Note: This method should only be used once {@link #initInternal()} has been called and before + * {@link #destroyInternal()} has been called. * - * @param objectNameKeyProperties The key properties component of the - * object name to use to unregister the - * object + * @param objectNameKeyProperties The key properties component of the object name to use to unregister the object */ protected final void unregister(String objectNameKeyProperties) { // Construct an object name with the right domain @@ -157,13 +146,12 @@ public abstract class LifecycleMBeanBase extends LifecycleBase /** - * Utility method to enable sub-classes to easily unregister additional - * components that don't implement {@link JmxEnabled} with an MBean server. - * <br> - * Note: This method should only be used once {@link #initInternal()} has - * been called and before {@link #destroyInternal()} has been called. + * Utility method to enable sub-classes to easily unregister additional components that don't implement + * {@link JmxEnabled} with an MBean server. <br> + * Note: This method should only be used once {@link #initInternal()} has been called and before + * {@link #destroyInternal()} has been called. * - * @param on The name of the component to unregister + * @param on The name of the component to unregister */ protected final void unregister(ObjectName on) { Registry.getRegistry(null, null).unregisterComponent(on); @@ -198,8 +186,7 @@ public abstract class LifecycleMBeanBase extends LifecycleBase @Override - public final ObjectName preRegister(MBeanServer server, ObjectName name) - throws Exception { + public final ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { this.oname = name; this.domain = name.getDomain().intern(); diff --git a/java/org/apache/catalina/util/ParameterMap.java b/java/org/apache/catalina/util/ParameterMap.java index 5e09295539..208893ab2d 100644 --- a/java/org/apache/catalina/util/ParameterMap.java +++ b/java/org/apache/catalina/util/ParameterMap.java @@ -26,18 +26,16 @@ import java.util.Set; import org.apache.tomcat.util.res.StringManager; /** - * Implementation of <strong>java.util.Map</strong> that includes a - * <code>locked</code> property. This class can be used to safely expose - * Catalina internal parameter map objects to user classes without having - * to clone them in order to avoid modifications. When first created, a - * <code>ParameterMap</code> instance is not locked. + * Implementation of <strong>java.util.Map</strong> that includes a <code>locked</code> property. This class can be used + * to safely expose Catalina internal parameter map objects to user classes without having to clone them in order to + * avoid modifications. When first created, a <code>ParameterMap</code> instance is not locked. * * @param <K> The type of Key * @param <V> The type of Value * * @author Craig R. McClanahan */ -public final class ParameterMap<K,V> implements Map<K,V>, Serializable { +public final class ParameterMap<K, V> implements Map<K,V>, Serializable { private static final long serialVersionUID = 2L; @@ -47,8 +45,7 @@ public final class ParameterMap<K,V> implements Map<K,V>, Serializable { /** - * Construct a new, empty map with the default initial capacity and - * load factor. + * Construct a new, empty map with the default initial capacity and load factor. */ public ParameterMap() { delegatedMap = new LinkedHashMap<>(); @@ -57,8 +54,7 @@ public final class ParameterMap<K,V> implements Map<K,V>, Serializable { /** - * Construct a new, empty map with the specified initial capacity and - * default load factor. + * Construct a new, empty map with the specified initial capacity and default load factor. * * @param initialCapacity The initial capacity of this map */ @@ -69,11 +65,10 @@ public final class ParameterMap<K,V> implements Map<K,V>, Serializable { /** - * Construct a new, empty map with the specified initial capacity and - * load factor. + * Construct a new, empty map with the specified initial capacity and load factor. * * @param initialCapacity The initial capacity of this map - * @param loadFactor The load factor of this map + * @param loadFactor The load factor of this map */ public ParameterMap(int initialCapacity, float loadFactor) { delegatedMap = new LinkedHashMap<>(initialCapacity, loadFactor); @@ -210,8 +205,7 @@ public final class ParameterMap<K,V> implements Map<K,V>, Serializable { /** * {@inheritDoc} * <p> - * Returns an <strong>unmodifiable</strong> {@link Set} view of the keys - * contained in this map if it is locked. + * Returns an <strong>unmodifiable</strong> {@link Set} view of the keys contained in this map if it is locked. */ @Override public Set<K> keySet() { @@ -226,8 +220,8 @@ public final class ParameterMap<K,V> implements Map<K,V>, Serializable { /** * {@inheritDoc} * <p> - * Returns an <strong>unmodifiable</strong> {@link Collection} view of the - * values contained in this map if it is locked. + * Returns an <strong>unmodifiable</strong> {@link Collection} view of the values contained in this map if it is + * locked. */ @Override public Collection<V> values() { @@ -242,11 +236,10 @@ public final class ParameterMap<K,V> implements Map<K,V>, Serializable { /** * {@inheritDoc} * <p> - * Returns an <strong>unmodifiable</strong> {@link Set} view of the mappings - * contained in this map if it is locked. + * Returns an <strong>unmodifiable</strong> {@link Set} view of the mappings contained in this map if it is locked. */ @Override - public Set<Map.Entry<K, V>> entrySet() { + public Set<Map.Entry<K,V>> entrySet() { if (locked) { return unmodifiableDelegatedMap.entrySet(); } diff --git a/java/org/apache/catalina/util/RequestUtil.java b/java/org/apache/catalina/util/RequestUtil.java index dfd9ab733e..85448b7ad1 100644 --- a/java/org/apache/catalina/util/RequestUtil.java +++ b/java/org/apache/catalina/util/RequestUtil.java @@ -27,10 +27,8 @@ import jakarta.servlet.http.HttpServletRequest; public final class RequestUtil { /** - * Build an appropriate return value for - * {@link HttpServletRequest#getRequestURL()} based on the provided - * request object. Note that this will also work for instances of - * {@link jakarta.servlet.http.HttpServletRequestWrapper}. + * Build an appropriate return value for {@link HttpServletRequest#getRequestURL()} based on the provided request + * object. Note that this will also work for instances of {@link jakarta.servlet.http.HttpServletRequestWrapper}. * * @param request The request object for which the URL should be built * @@ -48,8 +46,7 @@ public final class RequestUtil { url.append(scheme); url.append("://"); url.append(request.getServerName()); - if ((scheme.equals("http") && (port != 80)) - || (scheme.equals("https") && (port != 443))) { + if ((scheme.equals("http") && (port != 80)) || (scheme.equals("https") && (port != 443))) { url.append(':'); url.append(port); } diff --git a/java/org/apache/catalina/util/ResourceSet.java b/java/org/apache/catalina/util/ResourceSet.java index e97fd0880e..c6a343df23 100644 --- a/java/org/apache/catalina/util/ResourceSet.java +++ b/java/org/apache/catalina/util/ResourceSet.java @@ -24,11 +24,9 @@ import org.apache.tomcat.util.res.StringManager; /** - * Extended implementation of <strong>HashSet</strong> that includes a - * <code>locked</code> property. This class can be used to safely expose - * resource path sets to user classes without having to clone them in order - * to avoid modifications. When first created, a <code>ResourceMap</code> - * is not locked. + * Extended implementation of <strong>HashSet</strong> that includes a <code>locked</code> property. This class can be + * used to safely expose resource path sets to user classes without having to clone them in order to avoid + * modifications. When first created, a <code>ResourceMap</code> is not locked. * * @param <T> The type of elements in the Set * @@ -40,8 +38,7 @@ public final class ResourceSet<T> extends HashSet<T> { // ----------------------------------------------------------- Constructors /** - * Construct a new, empty set with the default initial capacity and - * load factor. + * Construct a new, empty set with the default initial capacity and load factor. */ public ResourceSet() { @@ -51,8 +48,7 @@ public final class ResourceSet<T> extends HashSet<T> { /** - * Construct a new, empty set with the specified initial capacity and - * default load factor. + * Construct a new, empty set with the specified initial capacity and default load factor. * * @param initialCapacity The initial capacity of this set */ @@ -64,11 +60,10 @@ public final class ResourceSet<T> extends HashSet<T> { /** - * Construct a new, empty set with the specified initial capacity and - * load factor. + * Construct a new, empty set with the specified initial capacity and load factor. * * @param initialCapacity The initial capacity of this set - * @param loadFactor The load factor of this set + * @param loadFactor The load factor of this set */ public ResourceSet(int initialCapacity, float loadFactor) { @@ -119,8 +114,7 @@ public final class ResourceSet<T> extends HashSet<T> { /** * The string manager for this package. */ - private static final StringManager sm = - StringManager.getManager("org.apache.catalina.util"); + private static final StringManager sm = StringManager.getManager("org.apache.catalina.util"); // --------------------------------------------------------- Public Methods @@ -134,8 +128,7 @@ public final class ResourceSet<T> extends HashSet<T> { @Override public boolean add(T o) { if (locked) { - throw new IllegalStateException - (sm.getString("resourceSet.locked")); + throw new IllegalStateException(sm.getString("resourceSet.locked")); } return super.add(o); } @@ -150,8 +143,7 @@ public final class ResourceSet<T> extends HashSet<T> { public void clear() { if (locked) { - throw new IllegalStateException - (sm.getString("resourceSet.locked")); + throw new IllegalStateException(sm.getString("resourceSet.locked")); } super.clear(); @@ -166,8 +158,7 @@ public final class ResourceSet<T> extends HashSet<T> { @Override public boolean remove(Object o) { if (locked) { - throw new IllegalStateException - (sm.getString("resourceSet.locked")); + throw new IllegalStateException(sm.getString("resourceSet.locked")); } return super.remove(o); } diff --git a/java/org/apache/catalina/util/ServerInfo.java b/java/org/apache/catalina/util/ServerInfo.java index adf0c4e565..67d1efaa90 100644 --- a/java/org/apache/catalina/util/ServerInfo.java +++ b/java/org/apache/catalina/util/ServerInfo.java @@ -24,8 +24,7 @@ import org.apache.tomcat.util.ExceptionUtils; /** - * Simple utility module to make it easy to plug in the server identifier - * when integrating Tomcat. + * Simple utility module to make it easy to plug in the server identifier when integrating Tomcat. * * @author Craig R. McClanahan */ @@ -63,8 +62,7 @@ public class ServerInfo { String number = null; Properties props = new Properties(); - try (InputStream is = ServerInfo.class.getResourceAsStream - ("/org/apache/catalina/util/ServerInfo.properties")) { + try (InputStream is = ServerInfo.class.getResourceAsStream("/org/apache/catalina/util/ServerInfo.properties")) { props.load(is); info = props.getProperty("server.info"); built = props.getProperty("server.built"); @@ -128,16 +126,11 @@ public class ServerInfo { System.out.println("Server version: " + getServerInfo()); System.out.println("Server built: " + getServerBuilt()); System.out.println("Server number: " + getServerNumber()); - System.out.println("OS Name: " + - System.getProperty("os.name")); - System.out.println("OS Version: " + - System.getProperty("os.version")); - System.out.println("Architecture: " + - System.getProperty("os.arch")); - System.out.println("JVM Version: " + - System.getProperty("java.runtime.version")); - System.out.println("JVM Vendor: " + - System.getProperty("java.vm.vendor")); + System.out.println("OS Name: " + System.getProperty("os.name")); + System.out.println("OS Version: " + System.getProperty("os.version")); + System.out.println("Architecture: " + System.getProperty("os.arch")); + System.out.println("JVM Version: " + System.getProperty("java.runtime.version")); + System.out.println("JVM Vendor: " + System.getProperty("java.vm.vendor")); } } diff --git a/java/org/apache/catalina/util/SessionConfig.java b/java/org/apache/catalina/util/SessionConfig.java index 7720adcbf8..29d6dae277 100644 --- a/java/org/apache/catalina/util/SessionConfig.java +++ b/java/org/apache/catalina/util/SessionConfig.java @@ -26,9 +26,10 @@ public class SessionConfig { private static final String DEFAULT_SESSION_PARAMETER_NAME = "jsessionid"; /** - * Determine the name to use for the session cookie for the provided - * context. + * Determine the name to use for the session cookie for the provided context. + * * @param context The context + * * @return the cookie name for the context */ public static String getSessionCookieName(Context context) { @@ -36,9 +37,10 @@ public class SessionConfig { } /** - * Determine the name to use for the session path parameter for the provided - * context. + * Determine the name to use for the session path parameter for the provided context. + * * @param context The context + * * @return the parameter name for the session */ public static String getSessionUriParamName(Context context) { @@ -68,10 +70,10 @@ public class SessionConfig { /** - * Determine the value to use for the session cookie path for the provided - * context. + * Determine the value to use for the session cookie path for the provided context. * * @param context The context + * * @return the parameter name for the session */ public static String getSessionCookiePath(Context context) { diff --git a/java/org/apache/catalina/util/SessionIdGeneratorBase.java b/java/org/apache/catalina/util/SessionIdGeneratorBase.java index 87d0a575be..d2d4198337 100644 --- a/java/org/apache/catalina/util/SessionIdGeneratorBase.java +++ b/java/org/apache/catalina/util/SessionIdGeneratorBase.java @@ -41,10 +41,9 @@ public abstract class SessionIdGeneratorBase extends LifecycleBase implements Se static { /* - * The default is normally SHA1PRNG. This was chosen because a) it is - * quick and b) it available by default in all JREs. However, it may not - * be available in some configurations such as those that use a FIPS - * certified provider. In those cases, use the platform default. + * The default is normally SHA1PRNG. This was chosen because a) it is quick and b) it available by default in + * all JREs. However, it may not be available in some configurations such as those that use a FIPS certified + * provider. In those cases, use the platform default. */ Set<String> algorithmNames = Security.getAlgorithms("SecureRandom"); if (algorithmNames.contains("SHA1PRNG")) { @@ -58,11 +57,10 @@ public abstract class SessionIdGeneratorBase extends LifecycleBase implements Se } /** - * Queue of random number generator objects to be used when creating session - * identifiers. If the queue is empty when a random number generator is - * required, a new random number generator object is created. This is - * designed this way since random number generators use a sync to make them - * thread-safe and the sync makes using a single object slow(er). + * Queue of random number generator objects to be used when creating session identifiers. If the queue is empty when + * a random number generator is required, a new random number generator object is created. This is designed this way + * since random number generators use a sync to make them thread-safe and the sync makes using a single object + * slow(er). */ private final Queue<SecureRandom> randoms = new ConcurrentLinkedQueue<>(); @@ -82,11 +80,10 @@ public abstract class SessionIdGeneratorBase extends LifecycleBase implements Se /** - * Get the class name of the {@link SecureRandom} implementation used to - * generate session IDs. + * Get the class name of the {@link SecureRandom} implementation used to generate session IDs. * - * @return The fully qualified class name. {@code null} indicates that the - * JRE provided {@link SecureRandom} implementation will be used + * @return The fully qualified class name. {@code null} indicates that the JRE provided {@link SecureRandom} + * implementation will be used */ public String getSecureRandomClass() { return secureRandomClass; @@ -94,9 +91,8 @@ public abstract class SessionIdGeneratorBase extends LifecycleBase implements Se /** - * Specify a non-default {@link SecureRandom} implementation to use. The - * implementation must be self-seeding and have a zero-argument constructor. - * If not specified, an instance of {@link SecureRandom} will be generated. + * Specify a non-default {@link SecureRandom} implementation to use. The implementation must be self-seeding and + * have a zero-argument constructor. If not specified, an instance of {@link SecureRandom} will be generated. * * @param secureRandomClass The fully-qualified class name */ @@ -106,11 +102,9 @@ public abstract class SessionIdGeneratorBase extends LifecycleBase implements Se /** - * Get the name of the algorithm used to create the {@link SecureRandom} - * instances which generate new session IDs. + * Get the name of the algorithm used to create the {@link SecureRandom} instances which generate new session IDs. * - * @return The name of the algorithm. {@code null} or the empty string means - * that platform default will be used + * @return The name of the algorithm. {@code null} or the empty string means that platform default will be used */ public String getSecureRandomAlgorithm() { return secureRandomAlgorithm; @@ -118,15 +112,12 @@ public abstract class SessionIdGeneratorBase extends LifecycleBase implements Se /** - * Specify a non-default algorithm to use to create instances of - * {@link SecureRandom} which are used to generate session IDs. If no - * algorithm is specified, SHA1PRNG will be used. If SHA1PRNG is not - * available, the platform default will be used. To use the platform default - * (which may be SHA1PRNG), specify {@code null} or the empty string. If an - * invalid algorithm and/or provider is specified the {@link SecureRandom} - * instances will be created using the defaults for this - * {@link SessionIdGenerator} implementation. If that fails, the - * {@link SecureRandom} instances will be created using platform defaults. + * Specify a non-default algorithm to use to create instances of {@link SecureRandom} which are used to generate + * session IDs. If no algorithm is specified, SHA1PRNG will be used. If SHA1PRNG is not available, the platform + * default will be used. To use the platform default (which may be SHA1PRNG), specify {@code null} or the empty + * string. If an invalid algorithm and/or provider is specified the {@link SecureRandom} instances will be created + * using the defaults for this {@link SessionIdGenerator} implementation. If that fails, the {@link SecureRandom} + * instances will be created using platform defaults. * * @param secureRandomAlgorithm The name of the algorithm */ @@ -136,11 +127,9 @@ public abstract class SessionIdGeneratorBase extends LifecycleBase implements Se /** - * Get the name of the provider used to create the {@link SecureRandom} - * instances which generate new session IDs. + * Get the name of the provider used to create the {@link SecureRandom} instances which generate new session IDs. * - * @return The name of the provider. {@code null} or the empty string means - * that platform default will be used + * @return The name of the provider. {@code null} or the empty string means that platform default will be used */ public String getSecureRandomProvider() { return secureRandomProvider; @@ -148,16 +137,13 @@ public abstract class SessionIdGeneratorBase extends LifecycleBase implements Se /** - * Specify a non-default provider to use to create instances of - * {@link SecureRandom} which are used to generate session IDs. If no - * provider is specified, the platform default is used. To use the platform - * default specify {@code null} or the empty string. If an invalid algorithm - * and/or provider is specified the {@link SecureRandom} instances will be - * created using the defaults for this {@link SessionIdGenerator} - * implementation. If that fails, the {@link SecureRandom} instances will be - * created using platform defaults. + * Specify a non-default provider to use to create instances of {@link SecureRandom} which are used to generate + * session IDs. If no provider is specified, the platform default is used. To use the platform default specify + * {@code null} or the empty string. If an invalid algorithm and/or provider is specified the {@link SecureRandom} + * instances will be created using the defaults for this {@link SessionIdGenerator} implementation. If that fails, + * the {@link SecureRandom} instances will be created using platform defaults. * - * @param secureRandomProvider The name of the provider + * @param secureRandomProvider The name of the provider */ public void setSecureRandomProvider(String secureRandomProvider) { this.secureRandomProvider = secureRandomProvider; @@ -205,8 +191,7 @@ public abstract class SessionIdGeneratorBase extends LifecycleBase implements Se /** - * Create a new random number generator instance we should use for - * generating session identifiers. + * Create a new random number generator instance we should use for generating session identifiers. */ private SecureRandom createSecureRandom() { @@ -219,8 +204,7 @@ public abstract class SessionIdGeneratorBase extends LifecycleBase implements Se Class<?> clazz = Class.forName(secureRandomClass); result = (SecureRandom) clazz.getConstructor().newInstance(); } catch (Exception e) { - log.error(sm.getString("sessionIdGeneratorBase.random", - secureRandomClass), e); + log.error(sm.getString("sessionIdGeneratorBase.random", secureRandomClass), e); } } @@ -228,22 +212,17 @@ public abstract class SessionIdGeneratorBase extends LifecycleBase implements Se if (result == null) { // No secureRandomClass or creation failed. Use SecureRandom. try { - if (secureRandomProvider != null && - secureRandomProvider.length() > 0) { - result = SecureRandom.getInstance(secureRandomAlgorithm, - secureRandomProvider); - } else if (secureRandomAlgorithm != null && - secureRandomAlgorithm.length() > 0) { + if (secureRandomProvider != null && secureRandomProvider.length() > 0) { + result = SecureRandom.getInstance(secureRandomAlgorithm, secureRandomProvider); + } else if (secureRandomAlgorithm != null && secureRandomAlgorithm.length() > 0) { result = SecureRandom.getInstance(secureRandomAlgorithm); } } catch (NoSuchAlgorithmException e) { error = true; - log.error(sm.getString("sessionIdGeneratorBase.randomAlgorithm", - secureRandomAlgorithm), e); + log.error(sm.getString("sessionIdGeneratorBase.randomAlgorithm", secureRandomAlgorithm), e); } catch (NoSuchProviderException e) { error = true; - log.error(sm.getString("sessionIdGeneratorBase.randomProvider", - secureRandomProvider), e); + log.error(sm.getString("sessionIdGeneratorBase.randomProvider", secureRandomProvider), e); } } @@ -254,8 +233,7 @@ public abstract class SessionIdGeneratorBase extends LifecycleBase implements Se try { result = SecureRandom.getInstance(DEFAULT_SECURE_RANDOM_ALGORITHM); } catch (NoSuchAlgorithmException e) { - log.error(sm.getString("sessionIdGeneratorBase.randomAlgorithm", - secureRandomAlgorithm), e); + log.error(sm.getString("sessionIdGeneratorBase.randomAlgorithm", secureRandomAlgorithm), e); } } @@ -269,8 +247,7 @@ public abstract class SessionIdGeneratorBase extends LifecycleBase implements Se long t2 = System.currentTimeMillis(); if ((t2 - t1) > 100) { - log.warn(sm.getString("sessionIdGeneratorBase.createRandom", - result.getAlgorithm(), Long.valueOf(t2 - t1))); + log.warn(sm.getString("sessionIdGeneratorBase.createRandom", result.getAlgorithm(), Long.valueOf(t2 - t1))); } return result; } diff --git a/java/org/apache/catalina/util/StandardSessionIdGenerator.java b/java/org/apache/catalina/util/StandardSessionIdGenerator.java index ea6ea65e9c..3ae61591d8 100644 --- a/java/org/apache/catalina/util/StandardSessionIdGenerator.java +++ b/java/org/apache/catalina/util/StandardSessionIdGenerator.java @@ -32,9 +32,7 @@ public class StandardSessionIdGenerator extends SessionIdGeneratorBase { while (resultLenBytes < sessionIdLength) { getRandomBytes(random); - for (int j = 0; - j < random.length && resultLenBytes < sessionIdLength; - j++) { + for (int j = 0; j < random.length && resultLenBytes < sessionIdLength; j++) { byte b1 = (byte) ((random[j] & 0xf0) >> 4); byte b2 = (byte) (random[j] & 0x0f); if (b1 < 10) { diff --git a/java/org/apache/catalina/util/Strftime.java b/java/org/apache/catalina/util/Strftime.java index e54d2a6b64..23eef8811e 100644 --- a/java/org/apache/catalina/util/Strftime.java +++ b/java/org/apache/catalina/util/Strftime.java @@ -23,19 +23,17 @@ import java.util.Properties; import java.util.TimeZone; /** - * Converts dates to strings using the same format specifiers as strftime - * - * Note: This does not mimic strftime perfectly. Certain strftime commands, - * are not supported, and will convert as if they were literals. - * - * Certain complicated commands, like those dealing with the week of the year - * probably don't have exactly the same behavior as strftime. - * - * These limitations are due to use SimpleDateTime. If the conversion was done - * manually, all these limitations could be eliminated. - * - * The interface looks like a subset of DateFormat. Maybe someday someone will make this class - * extend DateFormat. + * Converts dates to strings using the same format specifiers as strftime Notes: + * <ul> + * <li>This does not mimic strftime perfectly. Certain strftime commands, are not supported, and will convert as if they + * were literals.</li> + * <li>Certain complicated commands, like those dealing with the week of the year probably don't have exactly the same + * behavior as strftime.</li> + * <li>These limitations are due to use SimpleDateTime. If the conversion was done manually, all these limitations could + * be eliminated.</li> + * <li>The interface looks like a subset of DateFormat. Maybe someday someone will make this class extend + * DateFormat.</li> + * </ul> * * @author Bip Thelin * @author Dan Sandberg @@ -49,59 +47,59 @@ public class Strftime { */ static { translate = new Properties(); - translate.put("a","EEE"); - translate.put("A","EEEE"); - translate.put("b","MMM"); - translate.put("B","MMMM"); - translate.put("c","EEE MMM d HH:mm:ss yyyy"); - - //There's no way to specify the century in SimpleDateFormat. We don't want to hard-code - //20 since this could be wrong for the pre-2000 files. - //translate.put("C", "20"); - translate.put("d","dd"); - translate.put("D","MM/dd/yy"); - translate.put("e","dd"); //will show as '03' instead of ' 3' - translate.put("F","yyyy-MM-dd"); - translate.put("g","yy"); - translate.put("G","yyyy"); - translate.put("H","HH"); - translate.put("h","MMM"); - translate.put("I","hh"); - translate.put("j","DDD"); - translate.put("k","HH"); //will show as '07' instead of ' 7' - translate.put("l","hh"); //will show as '07' instead of ' 7' - translate.put("m","MM"); - translate.put("M","mm"); - translate.put("n","\n"); - translate.put("p","a"); - translate.put("P","a"); //will show as pm instead of PM - translate.put("r","hh:mm:ss a"); - translate.put("R","HH:mm"); - //There's no way to specify this with SimpleDateFormat - //translate.put("s","seconds since epoch"); - translate.put("S","ss"); - translate.put("t","\t"); - translate.put("T","HH:mm:ss"); - //There's no way to specify this with SimpleDateFormat - //translate.put("u","day of week ( 1-7 )"); - - //There's no way to specify this with SimpleDateFormat - //translate.put("U","week in year with first Sunday as first day..."); - - translate.put("V","ww"); //I'm not sure this is always exactly the same - - //There's no way to specify this with SimpleDateFormat - //translate.put("W","week in year with first Monday as first day..."); - - //There's no way to specify this with SimpleDateFormat - //translate.put("w","E"); - translate.put("X","HH:mm:ss"); - translate.put("x","MM/dd/yy"); - translate.put("y","yy"); - translate.put("Y","yyyy"); - translate.put("Z","z"); - translate.put("z","Z"); - translate.put("%","%"); + translate.put("a", "EEE"); + translate.put("A", "EEEE"); + translate.put("b", "MMM"); + translate.put("B", "MMMM"); + translate.put("c", "EEE MMM d HH:mm:ss yyyy"); + + // There's no way to specify the century in SimpleDateFormat. We don't want to hard-code + // 20 since this could be wrong for the pre-2000 files. + // translate.put("C", "20"); + translate.put("d", "dd"); + translate.put("D", "MM/dd/yy"); + translate.put("e", "dd"); // will show as '03' instead of ' 3' + translate.put("F", "yyyy-MM-dd"); + translate.put("g", "yy"); + translate.put("G", "yyyy"); + translate.put("H", "HH"); + translate.put("h", "MMM"); + translate.put("I", "hh"); + translate.put("j", "DDD"); + translate.put("k", "HH"); // will show as '07' instead of ' 7' + translate.put("l", "hh"); // will show as '07' instead of ' 7' + translate.put("m", "MM"); + translate.put("M", "mm"); + translate.put("n", "\n"); + translate.put("p", "a"); + translate.put("P", "a"); // will show as pm instead of PM + translate.put("r", "hh:mm:ss a"); + translate.put("R", "HH:mm"); + // There's no way to specify this with SimpleDateFormat + // translate.put("s","seconds since epoch"); + translate.put("S", "ss"); + translate.put("t", "\t"); + translate.put("T", "HH:mm:ss"); + // There's no way to specify this with SimpleDateFormat + // translate.put("u","day of week ( 1-7 )"); + + // There's no way to specify this with SimpleDateFormat + // translate.put("U","week in year with first Sunday as first day..."); + + translate.put("V", "ww"); // I'm not sure this is always exactly the same + + // There's no way to specify this with SimpleDateFormat + // translate.put("W","week in year with first Monday as first day..."); + + // There's no way to specify this with SimpleDateFormat + // translate.put("w","E"); + translate.put("X", "HH:mm:ss"); + translate.put("x", "MM/dd/yy"); + translate.put("y", "yy"); + translate.put("Y", "yyyy"); + translate.put("Z", "z"); + translate.put("z", "Z"); + translate.put("%", "%"); } @@ -109,21 +107,22 @@ public class Strftime { * Create an instance of this date formatting class * * @param origFormat the strftime-style formatting string - * @param locale the locale to use for locale-specific conversions + * @param locale the locale to use for locale-specific conversions */ - public Strftime( String origFormat, Locale locale ) { - String convertedFormat = convertDateFormat( origFormat ); - simpleDateFormat = new SimpleDateFormat( convertedFormat, locale ); + public Strftime(String origFormat, Locale locale) { + String convertedFormat = convertDateFormat(origFormat); + simpleDateFormat = new SimpleDateFormat(convertedFormat, locale); } /** * Format the date according to the strftime-style string given in the constructor. * * @param date the date to format + * * @return the formatted date */ - public String format( Date date ) { - return simpleDateFormat.format( date ); + public String format(Date date) { + return simpleDateFormat.format(date); } /** @@ -139,50 +138,51 @@ public class Strftime { * Change the timezone used to format dates * * @param timeZone The new time zone + * * @see SimpleDateFormat#setTimeZone */ - public void setTimeZone( TimeZone timeZone ) { - simpleDateFormat.setTimeZone( timeZone ); + public void setTimeZone(TimeZone timeZone) { + simpleDateFormat.setTimeZone(timeZone); } /** - * Search the provided pattern and get the C standard - * Date/Time formatting rules and convert them to the - * Java equivalent. + * Search the provided pattern and get the C standard Date/Time formatting rules and convert them to the Java + * equivalent. * * @param pattern The pattern to search + * * @return The modified pattern */ - protected String convertDateFormat( String pattern ) { + protected String convertDateFormat(String pattern) { boolean inside = false; boolean mark = false; boolean modifiedCommand = false; StringBuilder buf = new StringBuilder(); - for(int i = 0; i < pattern.length(); i++) { + for (int i = 0; i < pattern.length(); i++) { char c = pattern.charAt(i); - if ( c=='%' && !mark ) { - mark=true; + if (c == '%' && !mark) { + mark = true; } else { - if ( mark ) { - if ( modifiedCommand ) { - //don't do anything--we just wanted to skip a char + if (mark) { + if (modifiedCommand) { + // don't do anything--we just wanted to skip a char modifiedCommand = false; mark = false; } else { - inside = translateCommand( buf, pattern, i, inside ); - //It's a modifier code - if ( c=='O' || c=='E' ) { + inside = translateCommand(buf, pattern, i, inside); + // It's a modifier code + if (c == 'O' || c == 'E') { modifiedCommand = true; } else { - mark=false; + mark = false; } } } else { - if ( !inside && c != ' ' ) { - //We start a literal, which we need to quote + if (!inside && c != ' ') { + // We start a literal, which we need to quote buf.append('\''); inside = true; } @@ -192,58 +192,58 @@ public class Strftime { } } - if ( buf.length() > 0 ) { - char lastChar = buf.charAt( buf.length() - 1 ); + if (buf.length() > 0) { + char lastChar = buf.charAt(buf.length() - 1); - if( lastChar!='\'' && inside ) { + if (lastChar != '\'' && inside) { buf.append('\''); } } return buf.toString(); } - protected String quote( String str, boolean insideQuotes ) { + protected String quote(String str, boolean insideQuotes) { String retVal = str; - if ( !insideQuotes ) { + if (!insideQuotes) { retVal = '\'' + retVal + '\''; } return retVal; } /** - * Try to get the Java Date/Time formatting associated with - * the C standard provided. + * Try to get the Java Date/Time formatting associated with the C standard provided. * - * @param buf The buffer - * @param pattern The date/time pattern - * @param index The char index + * @param buf The buffer + * @param pattern The date/time pattern + * @param index The char index * @param oldInside Flag value + * * @return True if new is inside buffer */ - protected boolean translateCommand( StringBuilder buf, String pattern, int index, boolean oldInside ) { - char firstChar = pattern.charAt( index ); + protected boolean translateCommand(StringBuilder buf, String pattern, int index, boolean oldInside) { + char firstChar = pattern.charAt(index); boolean newInside = oldInside; - //O and E are modifiers, they mean to present an alternative representation of the next char - //we just handle the next char as if the O or E wasn't there - if ( firstChar == 'O' || firstChar == 'E' ) { - if ( index + 1 < pattern.length() ) { - newInside = translateCommand( buf, pattern, index + 1, oldInside ); + // O and E are modifiers, they mean to present an alternative representation of the next char + // we just handle the next char as if the O or E wasn't there + if (firstChar == 'O' || firstChar == 'E') { + if (index + 1 < pattern.length()) { + newInside = translateCommand(buf, pattern, index + 1, oldInside); } else { - buf.append( quote("%" + firstChar, oldInside ) ); + buf.append(quote("%" + firstChar, oldInside)); } } else { - String command = translate.getProperty( String.valueOf( firstChar ) ); + String command = translate.getProperty(String.valueOf(firstChar)); - //If we don't find a format, treat it as a literal--That's what apache does - if ( command == null ) { - buf.append( quote( "%" + firstChar, oldInside ) ); + // If we don't find a format, treat it as a literal--That's what apache does + if (command == null) { + buf.append(quote("%" + firstChar, oldInside)); } else { - //If we were inside quotes, close the quotes - if ( oldInside ) { - buf.append( '\'' ); + // If we were inside quotes, close the quotes + if (oldInside) { + buf.append('\''); } - buf.append( command ); + buf.append(command); newInside = false; } } diff --git a/java/org/apache/catalina/util/StringUtil.java b/java/org/apache/catalina/util/StringUtil.java index 41062af232..8e6af25dc2 100644 --- a/java/org/apache/catalina/util/StringUtil.java +++ b/java/org/apache/catalina/util/StringUtil.java @@ -25,19 +25,15 @@ public class StringUtil { private static final Pattern commaSeparatedValuesPattern = Pattern.compile("\\s*,\\s*"); /** - * Splits a comma-separated string into an array of String values. - * - * Whitespace around the commas is removed. - * - * Null or empty values will return a zero-element array. + * Splits a comma-separated string into an array of String values. Whitespace around the commas is removed. Null or + * empty values will return a zero-element array. * * @param s The string to split by commas. * * @return An array of String values. */ public static String[] splitCommaSeparated(String s) { - return (s == null || s.length() == 0) ? new String[0] : - commaSeparatedValuesPattern.split(s); + return (s == null || s.length() == 0) ? new String[0] : commaSeparatedValuesPattern.split(s); } } \ No newline at end of file diff --git a/java/org/apache/catalina/util/TLSUtil.java b/java/org/apache/catalina/util/TLSUtil.java index 43644d9082..ff3a3ce46f 100644 --- a/java/org/apache/catalina/util/TLSUtil.java +++ b/java/org/apache/catalina/util/TLSUtil.java @@ -22,15 +22,13 @@ import org.apache.tomcat.util.net.SSLSupport; public class TLSUtil { /** - * Determines if the named request attribute is used to pass information - * about the TLS configuration of the connection to the application. Both - * the standard request attributes defined by the Servlet specification and + * Determines if the named request attribute is used to pass information about the TLS configuration of the + * connection to the application. Both the standard request attributes defined by the Servlet specification and * Tomcat specific attributes are supported. * - * @param name The attribute name to test + * @param name The attribute name to test * - * @return {@code true} if the attribute is used to pass TLS configuration - * information, otherwise {@code false} + * @return {@code true} if the attribute is used to pass TLS configuration information, otherwise {@code false} */ @SuppressWarnings("deprecation") public static boolean isTLSRequestAttribute(String name) { diff --git a/java/org/apache/catalina/util/TimeBucketCounter.java b/java/org/apache/catalina/util/TimeBucketCounter.java index e106e24e76..3b4726f7ff 100644 --- a/java/org/apache/catalina/util/TimeBucketCounter.java +++ b/java/org/apache/catalina/util/TimeBucketCounter.java @@ -64,7 +64,7 @@ public class TimeBucketCounter { /** * Creates a new TimeBucketCounter with the specified lifetime. * - * @param bucketDuration duration in seconds, e.g. for 1 minute pass 60 + * @param bucketDuration duration in seconds, e.g. for 1 minute pass 60 * @param executorService the executor service which will be used to run the maintenance */ public TimeBucketCounter(int bucketDuration, ScheduledExecutorService executorService) { @@ -89,8 +89,7 @@ public class TimeBucketCounter { // Start our thread if (sleeptime > 0) { - monitorFuture = executorService - .scheduleWithFixedDelay(new MaintenanceMonitor(), 0, 60, TimeUnit.SECONDS); + monitorFuture = executorService.scheduleWithFixedDelay(new MaintenanceMonitor(), 0, 60, TimeUnit.SECONDS); } } @@ -202,8 +201,7 @@ public class TimeBucketCounter { private class MaintenanceMonitor implements Runnable { @Override public void run() { - if (sleeptime > 0 && - (maintenanceFuture == null || maintenanceFuture.isDone())) { + if (sleeptime > 0 && (maintenanceFuture == null || maintenanceFuture.isDone())) { if (maintenanceFuture != null && maintenanceFuture.isDone()) { // There was an error executing the scheduled task, get it and log it try { diff --git a/java/org/apache/catalina/util/ToStringUtil.java b/java/org/apache/catalina/util/ToStringUtil.java index d1602bf423..4ba530f5ba 100644 --- a/java/org/apache/catalina/util/ToStringUtil.java +++ b/java/org/apache/catalina/util/ToStringUtil.java @@ -21,8 +21,7 @@ import org.apache.catalina.Container; import org.apache.catalina.Manager; /** - * Utility class used to help generate return values for calls to - * {@link Object#toString()}. + * Utility class used to help generate return values for calls to {@link Object#toString()}. */ public class ToStringUtil { @@ -46,8 +45,7 @@ public class ToStringUtil { } - private static String containedToString(Object contained, Object container, - String containerTypeName) { + private static String containedToString(Object contained, Object container, String containerTypeName) { StringBuilder sb = new StringBuilder(contained.getClass().getSimpleName()); sb.append('['); if (container == null) { diff --git a/java/org/apache/catalina/util/TomcatCSS.java b/java/org/apache/catalina/util/TomcatCSS.java index 21ffbcbe18..5f66d66396 100644 --- a/java/org/apache/catalina/util/TomcatCSS.java +++ b/java/org/apache/catalina/util/TomcatCSS.java @@ -19,14 +19,9 @@ package org.apache.catalina.util; public class TomcatCSS { - public static final String TOMCAT_CSS = - "body {font-family:Tahoma,Arial,sans-serif;} " + - "h1, h2, h3, b {color:white;background-color:#525D76;} " + - "h1 {font-size:22px;} " + - "h2 {font-size:16px;} " + - "h3 {font-size:14px;} " + - "p {font-size:12px;} " + - "a {color:black;} " + - ".line {height:1px;background-color:#525D76;border:none;}"; + public static final String TOMCAT_CSS = "body {font-family:Tahoma,Arial,sans-serif;} " + + "h1, h2, h3, b {color:white;background-color:#525D76;} " + "h1 {font-size:22px;} " + + "h2 {font-size:16px;} " + "h3 {font-size:14px;} " + "p {font-size:12px;} " + "a {color:black;} " + + ".line {height:1px;background-color:#525D76;border:none;}"; } diff --git a/java/org/apache/catalina/util/URLEncoder.java b/java/org/apache/catalina/util/URLEncoder.java index 2ac1d66a66..776c0a48e9 100644 --- a/java/org/apache/catalina/util/URLEncoder.java +++ b/java/org/apache/catalina/util/URLEncoder.java @@ -23,12 +23,9 @@ import java.nio.charset.Charset; import java.util.BitSet; /** - * This class is very similar to the java.net.URLEncoder class. - * - * Unfortunately, with java.net.URLEncoder there is no way to specify to the - * java.net.URLEncoder which characters should NOT be encoded. - * - * This code was moved from DefaultServlet.java + * This class is very similar to the java.net.URLEncoder class. Unfortunately, with java.net.URLEncoder there is no way + * to specify to the java.net.URLEncoder which characters should NOT be encoded. This code was moved from + * DefaultServlet.java * * @author Craig R. McClanahan * @author Remy Maucherat @@ -36,7 +33,7 @@ import java.util.BitSet; public final class URLEncoder implements Cloneable { private static final char[] hexadecimal = - {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; public static final URLEncoder DEFAULT = new URLEncoder(); public static final URLEncoder QUERY = new URLEncoder(); @@ -47,10 +44,9 @@ public final class URLEncoder implements Cloneable { * * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" * - * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" * - * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" - * / "*" / "+" / "," / ";" / "=" + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" */ // ALPHA and DIGIT are always treated as safe characters // Add the remaining unreserved characters @@ -79,11 +75,13 @@ public final class URLEncoder implements Cloneable { /* * Encoder for query strings * https://www.w3.org/TR/html5/forms.html#application/x-www-form-urlencoded-encoding-algorithm + * // @formatter:off * 0x20 ' ' -> '+' * 0x2A, 0x2D, 0x2E, 0x30 to 0x39, 0x41 to 0x5A, 0x5F, 0x61 to 0x7A as-is * '*', '-', '.', '0' to '9', 'A' to 'Z', '_', 'a' to 'z' * Also '=' and '&' are not encoded * Everything else %nn encoded + * // @formatter:on */ // Special encoding for space QUERY.setEncodeSpaceAsPlus(true); @@ -97,7 +95,7 @@ public final class URLEncoder implements Cloneable { QUERY.addSafeCharacter('&'); } - //Array containing the safe characters set. + // Array containing the safe characters set. private final BitSet safeCharacters; private boolean encodeSpaceAsPlus = false; @@ -141,8 +139,8 @@ public final class URLEncoder implements Cloneable { /** * URL encodes the provided path using the given character set. * - * @param path The path to encode - * @param charset The character set to use to convert the path to bytes + * @param path The path to encode + * @param charset The character set to use to convert the path to bytes * * @return The encoded path */ @@ -156,15 +154,15 @@ public final class URLEncoder implements Cloneable { for (int i = 0; i < path.length(); i++) { int c = path.charAt(i); if (safeCharacters.get(c)) { - rewrittenPath.append((char)c); + rewrittenPath.append((char) c); } else if (encodeSpaceAsPlus && c == ' ') { rewrittenPath.append('+'); } else { // convert to external encoding before hex conversion try { - writer.write((char)c); + writer.write((char) c); writer.flush(); - } catch(IOException e) { + } catch (IOException e) { buf.reset(); continue; } diff --git a/java/org/apache/catalina/util/XMLWriter.java b/java/org/apache/catalina/util/XMLWriter.java index 143c305f34..a8789bbe84 100644 --- a/java/org/apache/catalina/util/XMLWriter.java +++ b/java/org/apache/catalina/util/XMLWriter.java @@ -74,8 +74,7 @@ public class XMLWriter { /** - * New XML writer utility that will store its data in an internal buffer - * and can write it to the specified writer. + * New XML writer utility that will store its data in an internal buffer and can write it to the specified writer. * <p> * See {@link #sendData()} * @@ -103,8 +102,8 @@ public class XMLWriter { * Write property to the XML. * * @param namespace Namespace - * @param name Property name - * @param value Property value + * @param name Property name + * @param value Property value */ public void writeProperty(String namespace, String name, String value) { writeElement(namespace, name, OPENING); @@ -116,9 +115,9 @@ public class XMLWriter { /** * Write an element. * - * @param name Element name + * @param name Element name * @param namespace Namespace abbreviation - * @param type Element type + * @param type Element type */ public void writeElement(String namespace, String name, int type) { writeElement(namespace, null, name, type); @@ -128,68 +127,65 @@ public class XMLWriter { /** * Write an element. * - * @param namespace Namespace abbreviation + * @param namespace Namespace abbreviation * @param namespaceInfo Namespace info - * @param name Element name - * @param type Element type + * @param name Element name + * @param type Element type */ - public void writeElement(String namespace, String namespaceInfo, - String name, int type) { + public void writeElement(String namespace, String namespaceInfo, String name, int type) { if ((namespace != null) && (namespace.length() > 0)) { switch (type) { - case OPENING: - if (lastWriteWasOpen) { - buffer.append('\n'); - } - if (namespaceInfo != null) { - buffer.append("<" + namespace + ":" + name + " xmlns:" - + namespace + "=\"" - + namespaceInfo + "\">"); - } else { - buffer.append("<" + namespace + ":" + name + ">"); - } - lastWriteWasOpen = true; - break; - case CLOSING: - buffer.append("</" + namespace + ":" + name + ">\n"); - lastWriteWasOpen = false; - break; - case NO_CONTENT: - default: - if (lastWriteWasOpen) { - buffer.append('\n'); - } - if (namespaceInfo != null) { - buffer.append("<" + namespace + ":" + name + " xmlns:" - + namespace + "=\"" - + namespaceInfo + "\"/>\n"); - } else { - buffer.append("<" + namespace + ":" + name + "/>\n"); - } - lastWriteWasOpen = false; - break; + case OPENING: + if (lastWriteWasOpen) { + buffer.append('\n'); + } + if (namespaceInfo != null) { + buffer.append( + "<" + namespace + ":" + name + " xmlns:" + namespace + "=\"" + namespaceInfo + "\">"); + } else { + buffer.append("<" + namespace + ":" + name + ">"); + } + lastWriteWasOpen = true; + break; + case CLOSING: + buffer.append("</" + namespace + ":" + name + ">\n"); + lastWriteWasOpen = false; + break; + case NO_CONTENT: + default: + if (lastWriteWasOpen) { + buffer.append('\n'); + } + if (namespaceInfo != null) { + buffer.append("<" + namespace + ":" + name + " xmlns:" + namespace + "=\"" + namespaceInfo + + "\"/>\n"); + } else { + buffer.append("<" + namespace + ":" + name + "/>\n"); + } + lastWriteWasOpen = false; + break; } } else { switch (type) { - case OPENING: - if (lastWriteWasOpen) { - buffer.append('\n'); - } - buffer.append("<" + name + ">"); - lastWriteWasOpen = true; - break; - case CLOSING: - buffer.append("</" + name + ">\n"); - lastWriteWasOpen = false; - break; - case NO_CONTENT: - default: - if (lastWriteWasOpen) { - buffer.append('\n'); - } - buffer.append("<" + name + "/>\n"); - lastWriteWasOpen = false; - break; + case OPENING: + if (lastWriteWasOpen) { + buffer.append('\n'); + } + buffer.append("<" + name + ">"); + lastWriteWasOpen = true; + break; + case CLOSING: + buffer.append("</" + name + ">\n"); + lastWriteWasOpen = false; + break; + case NO_CONTENT: + default: + if (lastWriteWasOpen) { + buffer.append('\n'); + } + buffer.append("<" + name + "/>\n"); + lastWriteWasOpen = false; + break; } } } @@ -235,10 +231,10 @@ public class XMLWriter { /** * Send data and reinitializes buffer, if a writer has been specified. + * * @throws IOException Error writing XML data */ - public void sendData() - throws IOException { + public void sendData() throws IOException { if (writer != null) { writer.write(buffer.toString()); buffer = new StringBuilder(); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org