You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2024/01/15 13:34:07 UTC
(tomcat) 01/02: Code clean-up. Formatting. No functional change.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 5d509be3ede12e9616b5b8549613dc50c2e3b16b
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jan 15 13:23:30 2024 +0000
Code clean-up. Formatting. No functional change.
---
.../catalina/ssi/ByteArrayServletOutputStream.java | 4 +-
.../apache/catalina/ssi/ExpressionParseTree.java | 74 ++++----
.../apache/catalina/ssi/ExpressionTokenizer.java | 39 ++--
.../catalina/ssi/ResponseIncludeWrapper.java | 49 +++--
java/org/apache/catalina/ssi/SSICommand.java | 29 ++-
java/org/apache/catalina/ssi/SSIConditional.java | 25 ++-
.../apache/catalina/ssi/SSIConditionalState.java | 11 +-
java/org/apache/catalina/ssi/SSIConfig.java | 14 +-
java/org/apache/catalina/ssi/SSIEcho.java | 15 +-
java/org/apache/catalina/ssi/SSIExec.java | 18 +-
.../apache/catalina/ssi/SSIExternalResolver.java | 26 ++-
java/org/apache/catalina/ssi/SSIFilter.java | 45 ++---
java/org/apache/catalina/ssi/SSIFlastmod.java | 20 +--
java/org/apache/catalina/ssi/SSIFsize.java | 25 ++-
java/org/apache/catalina/ssi/SSIInclude.java | 23 +--
java/org/apache/catalina/ssi/SSIMediator.java | 70 +++-----
java/org/apache/catalina/ssi/SSIPrintenv.java | 8 +-
java/org/apache/catalina/ssi/SSIProcessor.java | 113 +++++-------
java/org/apache/catalina/ssi/SSIServlet.java | 86 ++++-----
.../catalina/ssi/SSIServletExternalResolver.java | 197 ++++++++-------------
.../apache/catalina/ssi/SSIServletRequestUtil.java | 18 +-
java/org/apache/catalina/ssi/SSISet.java | 12 +-
.../catalina/ssi/SSIStopProcessingException.java | 5 +-
23 files changed, 389 insertions(+), 537 deletions(-)
diff --git a/java/org/apache/catalina/ssi/ByteArrayServletOutputStream.java b/java/org/apache/catalina/ssi/ByteArrayServletOutputStream.java
index 25cb0ee826..2b364e18a1 100644
--- a/java/org/apache/catalina/ssi/ByteArrayServletOutputStream.java
+++ b/java/org/apache/catalina/ssi/ByteArrayServletOutputStream.java
@@ -23,10 +23,10 @@ import javax.servlet.WriteListener;
/**
- * Class that extends ServletOutputStream, used as a wrapper from within
- * <code>SsiInclude</code>
+ * Class that extends ServletOutputStream, used as a wrapper from within <code>SsiInclude</code>
*
* @author Bip Thelin
+ *
* @see ServletOutputStream and ByteArrayOutputStream
*/
public class ByteArrayServletOutputStream extends ServletOutputStream {
diff --git a/java/org/apache/catalina/ssi/ExpressionParseTree.java b/java/org/apache/catalina/ssi/ExpressionParseTree.java
index 17774e4ee8..c79623814a 100644
--- a/java/org/apache/catalina/ssi/ExpressionParseTree.java
+++ b/java/org/apache/catalina/ssi/ExpressionParseTree.java
@@ -32,13 +32,13 @@ import org.apache.tomcat.util.ExceptionUtils;
*/
public class ExpressionParseTree {
/**
- * Contains the current set of completed nodes. This is a workspace for the
- * parser. Needs to be LinkedList since it can contain {@code null}s.
+ * Contains the current set of completed nodes. This is a workspace for the parser. Needs to be LinkedList since it
+ * can contain {@code null}s.
*/
private final LinkedList<Node> nodeStack = new LinkedList<>();
/**
- * Contains operator nodes that don't yet have values. This is a workspace
- * for the parser. Needs to be LinkedList since it can contain {@code null}s.
+ * Contains operator nodes that don't yet have values. This is a workspace for the parser. Needs to be LinkedList
+ * since it can contain {@code null}s.
*/
private final LinkedList<OppNode> oppStack = new LinkedList<>();
/**
@@ -53,20 +53,20 @@ public class ExpressionParseTree {
/**
* Creates a new parse tree for the specified expression.
- * @param expr The expression string
+ *
+ * @param expr The expression string
* @param ssiMediator Used to evaluated the expressions
+ *
* @throws ParseException a parsing error occurred
*/
- public ExpressionParseTree(String expr, SSIMediator ssiMediator)
- throws ParseException {
+ public ExpressionParseTree(String expr, SSIMediator ssiMediator) throws ParseException {
this.ssiMediator = ssiMediator;
parseExpression(expr);
}
/**
- * Evaluates the tree and returns true or false. The specified SSIMediator
- * is used to resolve variable references.
+ * Evaluates the tree and returns true or false. The specified SSIMediator is used to resolve variable references.
*
* @return the evaluation result
*
@@ -83,8 +83,8 @@ public class ExpressionParseTree {
/**
- * Pushes a new operator onto the opp stack, resolving existing opps as
- * needed.
+ * Pushes a new operator onto the opp stack, resolving existing opps as needed.
+ *
* @param node The operator node
*/
private void pushOpp(OppNode node) {
@@ -121,8 +121,7 @@ public class ExpressionParseTree {
/**
- * Resolves all pending opp nodes on the stack until the next group marker
- * is reached.
+ * Resolves all pending opp nodes on the stack until the next group marker is reached.
*/
private void resolveGroup() {
OppNode top = null;
@@ -137,7 +136,9 @@ public class ExpressionParseTree {
/**
* Parses the specified expression into a tree of parse nodes.
+ *
* @param expr The expression to parse
+ *
* @throws ParseException a parsing error occurred
*/
private void parseExpression(String expr) throws ParseException {
@@ -152,7 +153,7 @@ public class ExpressionParseTree {
currStringNode = null;
}
switch (token) {
- case ExpressionTokenizer.TOKEN_STRING :
+ case ExpressionTokenizer.TOKEN_STRING:
if (currStringNode == null) {
currStringNode = new StringNode(et.getTokenValue());
nodeStack.add(0, currStringNode);
@@ -162,51 +163,51 @@ public class ExpressionParseTree {
currStringNode.value.append(et.getTokenValue());
}
break;
- case ExpressionTokenizer.TOKEN_AND :
+ case ExpressionTokenizer.TOKEN_AND:
pushOpp(new AndNode());
break;
- case ExpressionTokenizer.TOKEN_OR :
+ case ExpressionTokenizer.TOKEN_OR:
pushOpp(new OrNode());
break;
- case ExpressionTokenizer.TOKEN_NOT :
+ case ExpressionTokenizer.TOKEN_NOT:
pushOpp(new NotNode());
break;
- case ExpressionTokenizer.TOKEN_EQ :
+ case ExpressionTokenizer.TOKEN_EQ:
pushOpp(new EqualNode());
break;
- case ExpressionTokenizer.TOKEN_NOT_EQ :
+ case ExpressionTokenizer.TOKEN_NOT_EQ:
pushOpp(new NotNode());
// Sneak the regular node in. The NOT will
// be resolved when the next opp comes along.
oppStack.add(0, new EqualNode());
break;
- case ExpressionTokenizer.TOKEN_RBRACE :
+ case ExpressionTokenizer.TOKEN_RBRACE:
// Closeout the current group
resolveGroup();
break;
- case ExpressionTokenizer.TOKEN_LBRACE :
+ case ExpressionTokenizer.TOKEN_LBRACE:
// Push a group marker
pushOpp(null);
break;
- case ExpressionTokenizer.TOKEN_GE :
+ case ExpressionTokenizer.TOKEN_GE:
pushOpp(new NotNode());
// Similar strategy to NOT_EQ above, except this
// is NOT less than
oppStack.add(0, new LessThanNode());
break;
- case ExpressionTokenizer.TOKEN_LE :
+ case ExpressionTokenizer.TOKEN_LE:
pushOpp(new NotNode());
// Similar strategy to NOT_EQ above, except this
// is NOT greater than
oppStack.add(0, new GreaterThanNode());
break;
- case ExpressionTokenizer.TOKEN_GT :
+ case ExpressionTokenizer.TOKEN_GT:
pushOpp(new GreaterThanNode());
break;
- case ExpressionTokenizer.TOKEN_LT :
+ case ExpressionTokenizer.TOKEN_LT:
pushOpp(new LessThanNode());
break;
- case ExpressionTokenizer.TOKEN_END :
+ case ExpressionTokenizer.TOKEN_END:
break;
}
}
@@ -233,6 +234,7 @@ public class ExpressionParseTree {
*/
public abstract boolean evaluate();
}
+
/**
* A node the represents a String value
*/
@@ -293,15 +295,13 @@ public class ExpressionParseTree {
/**
- * @return a precedence level suitable for comparison to other OppNode
- * preference levels.
+ * @return a precedence level suitable for comparison to other OppNode preference levels.
*/
public abstract int getPrecedence();
/**
- * Lets the node pop its own branch nodes off the front of the
- * specified list. The default pulls two.
+ * Lets the node pop its own branch nodes off the front of the specified list. The default pulls two.
*
* @param values The list from which to pop the values
*/
@@ -310,6 +310,7 @@ public class ExpressionParseTree {
left = values.remove(0);
}
}
+
private static final class NotNode extends OppNode {
@Override
public boolean evaluate() {
@@ -337,6 +338,7 @@ public class ExpressionParseTree {
return left + " NOT";
}
}
+
private static final class AndNode extends OppNode {
@Override
public boolean evaluate() {
@@ -358,6 +360,7 @@ public class ExpressionParseTree {
return left + " " + right + " AND";
}
}
+
private static final class OrNode extends OppNode {
@Override
public boolean evaluate() {
@@ -379,14 +382,14 @@ public class ExpressionParseTree {
return left + " " + right + " OR";
}
}
+
private abstract class CompareNode extends OppNode {
protected int compareBranches() {
- String val1 = ((StringNode)left).getValue();
- String val2 = ((StringNode)right).getValue();
+ String val1 = ((StringNode) left).getValue();
+ String val2 = ((StringNode) right).getValue();
int val2Len = val2.length();
- if (val2Len > 1 && val2.charAt(0) == '/' &&
- val2.charAt(val2Len - 1) == '/') {
+ if (val2Len > 1 && val2.charAt(0) == '/' && val2.charAt(val2Len - 1) == '/') {
// Treat as a regular expression
String expr = val2.substring(1, val2Len - 1);
try {
@@ -406,6 +409,7 @@ public class ExpressionParseTree {
return val1.compareTo(val2);
}
}
+
private final class EqualNode extends CompareNode {
@Override
public boolean evaluate() {
@@ -424,6 +428,7 @@ public class ExpressionParseTree {
return left + " " + right + " EQ";
}
}
+
private final class GreaterThanNode extends CompareNode {
@Override
public boolean evaluate() {
@@ -442,6 +447,7 @@ public class ExpressionParseTree {
return left + " " + right + " GT";
}
}
+
private final class LessThanNode extends CompareNode {
@Override
public boolean evaluate() {
diff --git a/java/org/apache/catalina/ssi/ExpressionTokenizer.java b/java/org/apache/catalina/ssi/ExpressionTokenizer.java
index 967b3fee57..59e9dbef78 100644
--- a/java/org/apache/catalina/ssi/ExpressionTokenizer.java
+++ b/java/org/apache/catalina/ssi/ExpressionTokenizer.java
@@ -18,9 +18,8 @@ package org.apache.catalina.ssi;
/**
- * Parses an expression string to return the individual tokens. This is
- * patterned similar to the StreamTokenizer in the JDK but customized for SSI
- * conditional expression parsing.
+ * Parses an expression string to return the individual tokens. This is patterned similar to the StreamTokenizer in the
+ * JDK but customized for SSI conditional expression parsing.
*
* @author Paul Speed
*/
@@ -46,6 +45,7 @@ public class ExpressionTokenizer {
/**
* Creates a new parser for the specified expression.
+ *
* @param expr The expression
*/
public ExpressionTokenizer(String expr) {
@@ -71,14 +71,13 @@ public class ExpressionTokenizer {
protected boolean isMetaChar(char c) {
- return Character.isWhitespace(c) || c == '(' || c == ')' || c == '!'
- || c == '<' || c == '>' || c == '|' || c == '&' || c == '=';
+ return Character.isWhitespace(c) || c == '(' || c == ')' || c == '!' || c == '<' || c == '>' || c == '|' ||
+ c == '&' || c == '=';
}
/**
- * @return the next token type and initializes any state variables
- * accordingly.
+ * @return the next token type and initializes any state variables accordingly.
*/
public int nextToken() {
// Skip any leading white space
@@ -87,56 +86,55 @@ public class ExpressionTokenizer {
}
// Clear the current token val
tokenVal = null;
- if (index == length)
- {
+ if (index == length) {
return TOKEN_END; // End of string
}
int start = index;
char currentChar = expr[index];
- char nextChar = (char)0;
+ char nextChar = (char) 0;
index++;
if (index < length) {
nextChar = expr[index];
}
// Check for a known token start
switch (currentChar) {
- case '(' :
+ case '(':
return TOKEN_LBRACE;
- case ')' :
+ case ')':
return TOKEN_RBRACE;
- case '=' :
+ case '=':
return TOKEN_EQ;
- case '!' :
+ case '!':
if (nextChar == '=') {
index++;
return TOKEN_NOT_EQ;
}
return TOKEN_NOT;
- case '|' :
+ case '|':
if (nextChar == '|') {
index++;
return TOKEN_OR;
}
break;
- case '&' :
+ case '&':
if (nextChar == '&') {
index++;
return TOKEN_AND;
}
break;
- case '>' :
+ case '>':
if (nextChar == '=') {
index++;
return TOKEN_GE; // Greater than or equal
}
return TOKEN_GT; // Greater than
- case '<' :
+ case '<':
if (nextChar == '=') {
index++;
return TOKEN_LE; // Less than or equal
}
return TOKEN_LT; // Less than
- default :
+ default:
// Otherwise it's a string
break;
}
@@ -189,8 +187,7 @@ public class ExpressionTokenizer {
/**
- * @return the String value of the token if it was type TOKEN_STRING.
- * Otherwise null is returned.
+ * @return the String value of the token if it was type TOKEN_STRING. Otherwise null is returned.
*/
public String getTokenValue() {
return tokenVal;
diff --git a/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java b/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java
index d758ba707a..9b2faa4835 100644
--- a/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java
+++ b/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java
@@ -31,8 +31,7 @@ import javax.servlet.http.HttpServletResponseWrapper;
import org.apache.tomcat.util.ExceptionUtils;
/**
- * An HttpServletResponseWrapper, used from
- * <code>SSIServletExternalResolver</code>
+ * An HttpServletResponseWrapper, used from <code>SSIServletExternalResolver</code>
*
* @author Bip Thelin
* @author David Becker
@@ -60,23 +59,21 @@ public class ResponseIncludeWrapper extends HttpServletResponseWrapper {
}
/**
- * Initialize our wrapper with the current HttpServletResponse and
- * ServletOutputStream.
+ * Initialize our wrapper with the current HttpServletResponse and ServletOutputStream.
*
- * @param response The response to use
+ * @param response The response to use
* @param captureServletOutputStream The ServletOutputStream to use
*/
- public ResponseIncludeWrapper(HttpServletResponse response,
- ServletOutputStream captureServletOutputStream) {
+ public ResponseIncludeWrapper(HttpServletResponse response, ServletOutputStream captureServletOutputStream) {
super(response);
this.captureServletOutputStream = captureServletOutputStream;
}
/**
- * Flush the servletOutputStream or printWriter ( only one will be non-null )
- * This must be called after a requestDispatcher.include, since we can't
- * assume that the included servlet flushed its stream.
+ * Flush the servletOutputStream or printWriter ( only one will be non-null ) This must be called after a
+ * requestDispatcher.include, since we can't assume that the included servlet flushed its stream.
+ *
* @throws IOException an IO error occurred
*/
public void flushOutputStreamOrWriter() throws IOException {
@@ -90,21 +87,19 @@ public class ResponseIncludeWrapper extends HttpServletResponseWrapper {
/**
- * Return a printwriter, throws and exception if a OutputStream already
- * been returned.
+ * Return a printwriter, throws and exception if a OutputStream already been returned.
*
* @return a PrintWriter object
- * @exception java.io.IOException
- * if the outputstream already been called
+ *
+ * @exception java.io.IOException if the outputstream already been called
*/
@Override
public PrintWriter getWriter() throws IOException {
if (servletOutputStream == null) {
if (printWriter == null) {
setCharacterEncoding(getCharacterEncoding());
- printWriter = new PrintWriter(
- new OutputStreamWriter(captureServletOutputStream,
- getCharacterEncoding()));
+ printWriter =
+ new PrintWriter(new OutputStreamWriter(captureServletOutputStream, getCharacterEncoding()));
}
return printWriter;
}
@@ -113,12 +108,11 @@ public class ResponseIncludeWrapper extends HttpServletResponseWrapper {
/**
- * Return a OutputStream, throws and exception if a printwriter already
- * been returned.
+ * Return a OutputStream, throws and exception if a printwriter already been returned.
*
* @return a OutputStream object
- * @exception java.io.IOException
- * if the printwriter already been called
+ *
+ * @exception java.io.IOException if the printwriter already been called
*/
@Override
public ServletOutputStream getOutputStream() throws IOException {
@@ -133,12 +127,11 @@ public class ResponseIncludeWrapper extends HttpServletResponseWrapper {
/**
- * Returns the value of the <code>last-modified</code> header field. The
- * result is the number of milliseconds since January 1, 1970 GMT.
+ * Returns the value of the <code>last-modified</code> header field. The result is the number of milliseconds since
+ * January 1, 1970 GMT.
*
- * @return the date the resource referenced by this
- * <code>ResponseIncludeWrapper</code> was last modified, or -1 if not
- * known.
+ * @return the date the resource referenced by this <code>ResponseIncludeWrapper</code> was last modified, or -1 if
+ * not known.
*/
public long getLastModified() {
return lastModified;
@@ -159,7 +152,7 @@ public class ResponseIncludeWrapper extends HttpServletResponseWrapper {
String lname = name.toLowerCase(Locale.ENGLISH);
if (lname.equals(LAST_MODIFIED)) {
try {
- synchronized(RFC1123_FORMAT) {
+ synchronized (RFC1123_FORMAT) {
lastModified = RFC1123_FORMAT.parse(value).getTime();
}
} catch (Throwable ignore) {
@@ -183,7 +176,7 @@ public class ResponseIncludeWrapper extends HttpServletResponseWrapper {
String lname = name.toLowerCase(Locale.ENGLISH);
if (lname.equals(LAST_MODIFIED)) {
try {
- synchronized(RFC1123_FORMAT) {
+ synchronized (RFC1123_FORMAT) {
lastModified = RFC1123_FORMAT.parse(value).getTime();
}
} catch (Throwable ignore) {
diff --git a/java/org/apache/catalina/ssi/SSICommand.java b/java/org/apache/catalina/ssi/SSICommand.java
index ef195b70a8..83b630f58b 100644
--- a/java/org/apache/catalina/ssi/SSICommand.java
+++ b/java/org/apache/catalina/ssi/SSICommand.java
@@ -18,9 +18,9 @@ package org.apache.catalina.ssi;
import java.io.PrintWriter;
+
/**
- * The interface that all SSI commands ( SSIEcho, SSIInclude, ...) must
- * implement.
+ * The interface that all SSI commands ( SSIEcho, SSIInclude, ...) must implement.
*
* @author Bip Thelin
* @author Dan Sandberg
@@ -30,21 +30,16 @@ public interface SSICommand {
/**
* Write the output of the command to the writer.
*
- * @param ssiMediator
- * the ssi mediator
- * @param commandName
- * the name of the actual command ( ie. echo )
- * @param paramNames
- * The parameter names
- * @param paramValues
- * The parameter values
- * @param writer
- * the writer to output to
+ * @param ssiMediator the ssi mediator
+ * @param commandName the name of the actual command ( ie. echo )
+ * @param paramNames The parameter names
+ * @param paramValues The parameter values
+ * @param writer the writer to output to
+ *
* @return the most current modified date resulting from any SSI commands
- * @throws SSIStopProcessingException
- * if SSI processing should be aborted
+ *
+ * @throws SSIStopProcessingException if SSI processing should be aborted
*/
- long process(SSIMediator ssiMediator, String commandName,
- String[] paramNames, String[] paramValues, PrintWriter writer)
- throws SSIStopProcessingException;
+ long process(SSIMediator ssiMediator, String commandName, String[] paramNames, String[] paramValues,
+ PrintWriter writer) throws SSIStopProcessingException;
}
\ No newline at end of file
diff --git a/java/org/apache/catalina/ssi/SSIConditional.java b/java/org/apache/catalina/ssi/SSIConditional.java
index 3a3af58d3c..780c9c3b64 100644
--- a/java/org/apache/catalina/ssi/SSIConditional.java
+++ b/java/org/apache/catalina/ssi/SSIConditional.java
@@ -19,6 +19,7 @@ package org.apache.catalina.ssi;
import java.io.PrintWriter;
import java.text.ParseException;
+
/**
* SSI command that handles all conditional directives.
*
@@ -30,9 +31,8 @@ public class SSIConditional implements SSICommand {
* @see SSICommand
*/
@Override
- public long process(SSIMediator ssiMediator, String commandName,
- String[] paramNames, String[] paramValues, PrintWriter writer)
- throws SSIStopProcessingException {
+ public long process(SSIMediator ssiMediator, String commandName, String[] paramNames, String[] paramValues,
+ PrintWriter writer) throws SSIStopProcessingException {
// Assume anything using conditionals was modified by it
long lastModified = System.currentTimeMillis();
// Retrieve the current state information
@@ -103,7 +103,7 @@ public class SSIConditional implements SSICommand {
state.branchTaken = true;
} else {
throw new SSIStopProcessingException();
- //throw new SsiCommandException( "Not a conditional command:" +
+ // throw new SsiCommandException( "Not a conditional command:" +
// cmdName );
}
return lastModified;
@@ -111,30 +111,27 @@ public class SSIConditional implements SSICommand {
/**
- * Retrieves the expression from the specified arguments and performs the
- * necessary evaluation steps.
+ * Retrieves the expression from the specified arguments and performs the necessary evaluation steps.
*/
- private boolean evaluateArguments(String[] names, String[] values,
- SSIMediator ssiMediator) throws SSIStopProcessingException {
+ private boolean evaluateArguments(String[] names, String[] values, SSIMediator ssiMediator)
+ throws SSIStopProcessingException {
String expr = getExpression(names, values);
if (expr == null) {
throw new SSIStopProcessingException();
- //throw new SsiCommandException( "No expression specified." );
+ // throw new SsiCommandException( "No expression specified." );
}
try {
- ExpressionParseTree tree = new ExpressionParseTree(expr,
- ssiMediator);
+ ExpressionParseTree tree = new ExpressionParseTree(expr, ssiMediator);
return tree.evaluateTree();
} catch (ParseException e) {
- //throw new SsiCommandException( "Error parsing expression." );
+ // throw new SsiCommandException( "Error parsing expression." );
throw new SSIStopProcessingException();
}
}
/**
- * Returns the "expr" if the arg name is appropriate, otherwise returns
- * null.
+ * Returns the "expr" if the arg name is appropriate, otherwise returns null.
*/
private String getExpression(String[] paramNames, String[] paramValues) {
if ("expr".equalsIgnoreCase(paramNames[0])) {
diff --git a/java/org/apache/catalina/ssi/SSIConditionalState.java b/java/org/apache/catalina/ssi/SSIConditionalState.java
index 5c9ca2904f..e678dd9407 100644
--- a/java/org/apache/catalina/ssi/SSIConditionalState.java
+++ b/java/org/apache/catalina/ssi/SSIConditionalState.java
@@ -18,17 +18,15 @@ package org.apache.catalina.ssi;
/**
- * This class is used by SSIMediator and SSIConditional to keep track of state
- * information necessary to process the nested conditional commands ( if, elif,
- * else, endif ).
+ * This class is used by SSIMediator and SSIConditional to keep track of state information necessary to process the
+ * nested conditional commands ( if, elif, else, endif ).
*
* @author Dan Sandberg
* @author Paul Speed
*/
class SSIConditionalState {
/**
- * Set to true if the current conditional has already been completed, i.e.:
- * a branch was taken.
+ * Set to true if the current conditional has already been completed, i.e.: a branch was taken.
*/
boolean branchTaken = false;
/**
@@ -36,8 +34,7 @@ class SSIConditionalState {
*/
int nestingCount = 0;
/**
- * Set to true if only conditional commands ( if, elif, else, endif )
- * should be processed.
+ * Set to true if only conditional commands ( if, elif, else, endif ) should be processed.
*/
boolean processConditionalCommandsOnly = false;
}
\ No newline at end of file
diff --git a/java/org/apache/catalina/ssi/SSIConfig.java b/java/org/apache/catalina/ssi/SSIConfig.java
index 4c638fa0a6..874c8e762c 100644
--- a/java/org/apache/catalina/ssi/SSIConfig.java
+++ b/java/org/apache/catalina/ssi/SSIConfig.java
@@ -18,6 +18,7 @@ package org.apache.catalina.ssi;
import java.io.PrintWriter;
+
/**
* Implements the Server-side #exec command
*
@@ -31,13 +32,12 @@ public final class SSIConfig implements SSICommand {
* @see SSICommand
*/
@Override
- public long process(SSIMediator ssiMediator, String commandName,
- String[] paramNames, String[] paramValues, PrintWriter writer) {
+ public long process(SSIMediator ssiMediator, String commandName, String[] paramNames, String[] paramValues,
+ PrintWriter writer) {
for (int i = 0; i < paramNames.length; i++) {
String paramName = paramNames[i];
String paramValue = paramValues[i];
- String substitutedValue = ssiMediator
- .substituteVariables(paramValue);
+ String substitutedValue = ssiMediator.substituteVariables(paramValue);
if (paramName.equalsIgnoreCase("errmsg")) {
ssiMediator.setConfigErrMsg(substitutedValue);
} else if (paramName.equalsIgnoreCase("sizefmt")) {
@@ -46,9 +46,7 @@ public final class SSIConfig implements SSICommand {
ssiMediator.setConfigTimeFmt(substitutedValue);
} else {
ssiMediator.log("#config--Invalid attribute: " + paramName);
- //We need to fetch this value each time, since it may change
- // during the
- // loop
+ // We need to fetch this value each time, since it may change during the loop
String configErrMsg = ssiMediator.getConfigErrMsg();
writer.write(configErrMsg);
}
@@ -56,4 +54,4 @@ public final class SSIConfig implements SSICommand {
// Setting config options doesn't really change the page
return 0;
}
-}
\ No newline at end of file
+}
diff --git a/java/org/apache/catalina/ssi/SSIEcho.java b/java/org/apache/catalina/ssi/SSIEcho.java
index df09cfc4f1..14ebaef767 100644
--- a/java/org/apache/catalina/ssi/SSIEcho.java
+++ b/java/org/apache/catalina/ssi/SSIEcho.java
@@ -18,6 +18,7 @@ package org.apache.catalina.ssi;
import java.io.PrintWriter;
+
/**
* Return the result associated with the supplied Server Variable.
*
@@ -35,8 +36,8 @@ public class SSIEcho implements SSICommand {
* @see SSICommand
*/
@Override
- public long process(SSIMediator ssiMediator, String commandName,
- String[] paramNames, String[] paramValues, PrintWriter writer) {
+ public long process(SSIMediator ssiMediator, String commandName, String[] paramNames, String[] paramValues,
+ PrintWriter writer) {
String encoding = DEFAULT_ENCODING;
String originalValue = null;
String errorMessage = ssiMediator.getConfigErrMsg();
@@ -57,8 +58,8 @@ public class SSIEcho implements SSICommand {
writer.write(ssiMediator.encode(errorMessage, SSIMediator.ENCODING_ENTITY));
}
}
- String variableValue = (originalValue == null) ? MISSING_VARIABLE_VALUE
- : ssiMediator.getVariableValue(originalValue, encoding);
+ String variableValue = (originalValue == null) ? MISSING_VARIABLE_VALUE :
+ ssiMediator.getVariableValue(originalValue, encoding);
if (variableValue == null) {
variableValue = MISSING_VARIABLE_VALUE;
}
@@ -68,8 +69,8 @@ public class SSIEcho implements SSICommand {
protected boolean isValidEncoding(String encoding) {
- return encoding.equalsIgnoreCase(SSIMediator.ENCODING_URL)
- || encoding.equalsIgnoreCase(SSIMediator.ENCODING_ENTITY)
- || encoding.equalsIgnoreCase(SSIMediator.ENCODING_NONE);
+ return encoding.equalsIgnoreCase(SSIMediator.ENCODING_URL) ||
+ encoding.equalsIgnoreCase(SSIMediator.ENCODING_ENTITY) ||
+ encoding.equalsIgnoreCase(SSIMediator.ENCODING_NONE);
}
}
\ No newline at end of file
diff --git a/java/org/apache/catalina/ssi/SSIExec.java b/java/org/apache/catalina/ssi/SSIExec.java
index 729281be7b..80d8d2a6c6 100644
--- a/java/org/apache/catalina/ssi/SSIExec.java
+++ b/java/org/apache/catalina/ssi/SSIExec.java
@@ -16,13 +16,13 @@
*/
package org.apache.catalina.ssi;
-
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import org.apache.catalina.util.IOTools;
+
/**
* Implements the Server-side #exec command
*
@@ -41,17 +41,16 @@ public class SSIExec implements SSICommand {
* @see SSICommand
*/
@Override
- public long process(SSIMediator ssiMediator, String commandName,
- String[] paramNames, String[] paramValues, PrintWriter writer) {
+ public long process(SSIMediator ssiMediator, String commandName, String[] paramNames, String[] paramValues,
+ PrintWriter writer) {
long lastModified = 0;
String configErrMsg = ssiMediator.getConfigErrMsg();
String paramName = paramNames[0];
String paramValue = paramValues[0];
String substitutedValue = ssiMediator.substituteVariables(paramValue);
if (paramName.equalsIgnoreCase("cgi")) {
- lastModified = ssiInclude.process(ssiMediator, "include",
- new String[]{"virtual"}, new String[]{substitutedValue},
- writer);
+ lastModified = ssiInclude.process(ssiMediator, "include", new String[] { "virtual" },
+ new String[] { substitutedValue }, writer);
} else if (paramName.equalsIgnoreCase("cmd")) {
boolean foundProgram = false;
try {
@@ -60,7 +59,8 @@ public class SSIExec implements SSICommand {
foundProgram = true;
char[] buf = new char[BUFFER_SIZE];
try (BufferedReader stdOutReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
- BufferedReader stdErrReader = new BufferedReader(new InputStreamReader(proc.getErrorStream()));) {
+ BufferedReader stdErrReader =
+ new BufferedReader(new InputStreamReader(proc.getErrorStream()));) {
IOTools.flow(stdErrReader, writer, buf);
IOTools.flow(stdOutReader, writer, buf);
}
@@ -71,7 +71,7 @@ public class SSIExec implements SSICommand {
writer.write(configErrMsg);
} catch (IOException e) {
if (!foundProgram) {
- //apache doesn't output an error message if it can't find
+ // apache doesn't output an error message if it can't find
// a program
}
ssiMediator.log("Couldn't exec file: " + substitutedValue, e);
@@ -79,4 +79,4 @@ public class SSIExec implements SSICommand {
}
return lastModified;
}
-}
\ No newline at end of file
+}
diff --git a/java/org/apache/catalina/ssi/SSIExternalResolver.java b/java/org/apache/catalina/ssi/SSIExternalResolver.java
index 469e4f54f3..5d0a6728bb 100644
--- a/java/org/apache/catalina/ssi/SSIExternalResolver.java
+++ b/java/org/apache/catalina/ssi/SSIExternalResolver.java
@@ -20,9 +20,9 @@ package org.apache.catalina.ssi;
import java.io.IOException;
import java.util.Collection;
import java.util.Date;
+
/**
- * Interface used by SSIMediator to talk to the 'outside world' ( usually a
- * servlet )
+ * Interface used by SSIMediator to talk to the 'outside world' ( usually a servlet )
*
* @author Dan Sandberg
*/
@@ -30,8 +30,7 @@ public interface SSIExternalResolver {
/**
* Adds any external variables to the variableNames collection.
*
- * @param variableNames
- * the collection to add to
+ * @param variableNames the collection to add to
*/
void addVariableNames(Collection<String> variableNames);
@@ -40,22 +39,18 @@ public interface SSIExternalResolver {
/**
- * Set the named variable to the specified value. If value is null, then
- * the variable will be removed ( ie. a call to getVariableValue will
- * return null )
+ * Set the named variable to the specified value. If value is null, then the variable will be removed ( ie. a call
+ * to getVariableValue will return null )
*
- * @param name
- * of the variable
- * @param value
- * of the variable
+ * @param name of the variable
+ * @param value of the variable
*/
void setVariableValue(String name, String value);
/**
- * Returns the current date. This is useful for putting the SSI stuff in a
- * regression test. Since you can make the current date a constant, it
- * makes testing easier since the output won't change.
+ * Returns the current date. This is useful for putting the SSI stuff in a regression test. Since you can make the
+ * current date a constant, it makes testing easier since the output won't change.
*
* @return the data
*/
@@ -65,8 +60,7 @@ public interface SSIExternalResolver {
long getFileSize(String path, boolean virtual) throws IOException;
- long getFileLastModified(String path, boolean virtual)
- throws IOException;
+ long getFileLastModified(String path, boolean virtual) throws IOException;
String getFileText(String path, boolean virtual) throws IOException;
diff --git a/java/org/apache/catalina/ssi/SSIFilter.java b/java/org/apache/catalina/ssi/SSIFilter.java
index f49db33365..40141c9baf 100644
--- a/java/org/apache/catalina/ssi/SSIFilter.java
+++ b/java/org/apache/catalina/ssi/SSIFilter.java
@@ -36,11 +36,12 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
/**
- * Filter to process SSI requests within a webpage. Mapped to a content types
- * from within web.xml.
+ * Filter to process SSI requests within a webpage. Mapped to a content types from within web.xml.
*
* @author David Becker
+ *
* @see org.apache.catalina.ssi.SSIServlet
*/
public class SSIFilter implements Filter {
@@ -54,8 +55,7 @@ public class SSIFilter implements Filter {
/** regex pattern to match when evaluating content types */
protected Pattern contentTypeRegEx = null;
/** default pattern for ssi filter content type matching */
- protected final Pattern shtmlRegEx =
- Pattern.compile("text/x-server-parsed-html(;.*)?");
+ protected final Pattern shtmlRegEx = Pattern.compile("text/x-server-parsed-html(;.*)?");
/** Allow exec (normally blocked for security) */
protected boolean allowExec = false;
@@ -74,8 +74,7 @@ public class SSIFilter implements Filter {
contentTypeRegEx = shtmlRegEx;
}
- isVirtualWebappRelative =
- Boolean.parseBoolean(config.getInitParameter("isVirtualWebappRelative"));
+ isVirtualWebappRelative = Boolean.parseBoolean(config.getInitParameter("isVirtualWebappRelative"));
if (config.getInitParameter("expires") != null) {
expires = Long.valueOf(config.getInitParameter("expires"));
@@ -84,17 +83,16 @@ public class SSIFilter implements Filter {
allowExec = Boolean.parseBoolean(config.getInitParameter("allowExec"));
if (debug > 0) {
- config.getServletContext().log(
- "SSIFilter.init() SSI invoker started with 'debug'=" + debug);
+ config.getServletContext().log("SSIFilter.init() SSI invoker started with 'debug'=" + debug);
}
}
@Override
- public void doFilter(ServletRequest request, ServletResponse response,
- FilterChain chain) throws IOException, ServletException {
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+ throws IOException, ServletException {
// cast once
- HttpServletRequest req = (HttpServletRequest)request;
- HttpServletResponse res = (HttpServletResponse)response;
+ HttpServletRequest req = (HttpServletRequest) request;
+ HttpServletResponse res = (HttpServletResponse) response;
// setup to capture output
ByteArrayServletOutputStream basos = new ByteArrayServletOutputStream();
@@ -115,22 +113,17 @@ public class SSIFilter implements Filter {
String encoding = res.getCharacterEncoding();
// set up SSI processing
- SSIExternalResolver ssiExternalResolver =
- new SSIServletExternalResolver(config.getServletContext(), req,
- res, isVirtualWebappRelative, debug, encoding);
- SSIProcessor ssiProcessor = new SSIProcessor(ssiExternalResolver,
- debug, allowExec);
+ SSIExternalResolver ssiExternalResolver = new SSIServletExternalResolver(config.getServletContext(), req,
+ res, isVirtualWebappRelative, debug, encoding);
+ SSIProcessor ssiProcessor = new SSIProcessor(ssiExternalResolver, debug, allowExec);
// prepare readers/writers
- Reader reader =
- new InputStreamReader(new ByteArrayInputStream(bytes), encoding);
+ Reader reader = new InputStreamReader(new ByteArrayInputStream(bytes), encoding);
ByteArrayOutputStream ssiout = new ByteArrayOutputStream();
- PrintWriter writer =
- new PrintWriter(new OutputStreamWriter(ssiout, encoding));
+ PrintWriter writer = new PrintWriter(new OutputStreamWriter(ssiout, encoding));
// do SSI processing
- long lastModified = ssiProcessor.process(reader,
- responseIncludeWrapper.getLastModified(), writer);
+ long lastModified = ssiProcessor.process(reader, responseIncludeWrapper.getLastModified(), writer);
// set output bytes
writer.flush();
@@ -138,16 +131,14 @@ public class SSIFilter implements Filter {
// override headers
if (expires != null) {
- res.setDateHeader("expires", (new java.util.Date()).getTime()
- + expires.longValue() * 1000);
+ res.setDateHeader("expires", (new java.util.Date()).getTime() + expires.longValue() * 1000);
}
if (lastModified > 0) {
res.setDateHeader("last-modified", lastModified);
}
res.setContentLength(bytes.length);
- Matcher shtmlMatcher =
- shtmlRegEx.matcher(responseIncludeWrapper.getContentType());
+ Matcher shtmlMatcher = shtmlRegEx.matcher(responseIncludeWrapper.getContentType());
if (shtmlMatcher.matches()) {
// Convert shtml mime type to ordinary html mime type but preserve
// encoding, if any.
diff --git a/java/org/apache/catalina/ssi/SSIFlastmod.java b/java/org/apache/catalina/ssi/SSIFlastmod.java
index 924b1d96ac..5d37899608 100644
--- a/java/org/apache/catalina/ssi/SSIFlastmod.java
+++ b/java/org/apache/catalina/ssi/SSIFlastmod.java
@@ -36,33 +36,27 @@ public final class SSIFlastmod implements SSICommand {
* @see SSICommand
*/
@Override
- public long process(SSIMediator ssiMediator, String commandName,
- String[] paramNames, String[] paramValues, PrintWriter writer) {
+ public long process(SSIMediator ssiMediator, String commandName, String[] paramNames, String[] paramValues,
+ PrintWriter writer) {
long lastModified = 0;
String configErrMsg = ssiMediator.getConfigErrMsg();
for (int i = 0; i < paramNames.length; i++) {
String paramName = paramNames[i];
String paramValue = paramValues[i];
- String substitutedValue = ssiMediator
- .substituteVariables(paramValue);
+ String substitutedValue = ssiMediator.substituteVariables(paramValue);
try {
- if (paramName.equalsIgnoreCase("file")
- || paramName.equalsIgnoreCase("virtual")) {
+ if (paramName.equalsIgnoreCase("file") || paramName.equalsIgnoreCase("virtual")) {
boolean virtual = paramName.equalsIgnoreCase("virtual");
- lastModified = ssiMediator.getFileLastModified(
- substitutedValue, virtual);
+ lastModified = ssiMediator.getFileLastModified(substitutedValue, virtual);
Date date = new Date(lastModified);
String configTimeFmt = ssiMediator.getConfigTimeFmt();
writer.write(formatDate(date, configTimeFmt));
} else {
- ssiMediator.log("#flastmod--Invalid attribute: "
- + paramName);
+ ssiMediator.log("#flastmod--Invalid attribute: " + paramName);
writer.write(configErrMsg);
}
} catch (IOException e) {
- ssiMediator.log(
- "#flastmod--Couldn't get last modified for file: "
- + substitutedValue, e);
+ ssiMediator.log("#flastmod--Couldn't get last modified for file: " + substitutedValue, e);
writer.write(configErrMsg);
}
}
diff --git a/java/org/apache/catalina/ssi/SSIFsize.java b/java/org/apache/catalina/ssi/SSIFsize.java
index 8bb504d1f7..6c5042f8ef 100644
--- a/java/org/apache/catalina/ssi/SSIFsize.java
+++ b/java/org/apache/catalina/ssi/SSIFsize.java
@@ -20,6 +20,7 @@ package org.apache.catalina.ssi;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
+
/**
* Implements the Server-side #fsize command
*
@@ -37,23 +38,19 @@ public final class SSIFsize implements SSICommand {
* @see SSICommand
*/
@Override
- public long process(SSIMediator ssiMediator, String commandName,
- String[] paramNames, String[] paramValues, PrintWriter writer) {
+ public long process(SSIMediator ssiMediator, String commandName, String[] paramNames, String[] paramValues,
+ PrintWriter writer) {
long lastModified = 0;
String configErrMsg = ssiMediator.getConfigErrMsg();
for (int i = 0; i < paramNames.length; i++) {
String paramName = paramNames[i];
String paramValue = paramValues[i];
- String substitutedValue = ssiMediator
- .substituteVariables(paramValue);
+ String substitutedValue = ssiMediator.substituteVariables(paramValue);
try {
- if (paramName.equalsIgnoreCase("file")
- || paramName.equalsIgnoreCase("virtual")) {
+ if (paramName.equalsIgnoreCase("file") || paramName.equalsIgnoreCase("virtual")) {
boolean virtual = paramName.equalsIgnoreCase("virtual");
- lastModified = ssiMediator.getFileLastModified(
- substitutedValue, virtual);
- long size = ssiMediator.getFileSize(substitutedValue,
- virtual);
+ lastModified = ssiMediator.getFileLastModified(substitutedValue, virtual);
+ long size = ssiMediator.getFileSize(substitutedValue, virtual);
String configSizeFmt = ssiMediator.getConfigSizeFmt();
writer.write(formatSize(size, configSizeFmt));
} else {
@@ -61,8 +58,7 @@ public final class SSIFsize implements SSICommand {
writer.write(configErrMsg);
}
} catch (IOException e) {
- ssiMediator.log("#fsize--Couldn't get size for file: "
- + substitutedValue, e);
+ ssiMediator.log("#fsize--Couldn't get size for file: " + substitutedValue, e);
writer.write(configErrMsg);
}
}
@@ -112,10 +108,9 @@ public final class SSIFsize implements SSICommand {
retString += "k";
} else if (size < 99 * ONE_MEBIBYTE) {
DecimalFormat decimalFormat = new DecimalFormat("0.0M");
- retString = decimalFormat.format(size / (double)ONE_MEBIBYTE);
+ retString = decimalFormat.format(size / (double) ONE_MEBIBYTE);
} else {
- retString = Long.toString((size + (529 * ONE_KIBIBYTE))
- / ONE_MEBIBYTE);
+ retString = Long.toString((size + (529 * ONE_KIBIBYTE)) / ONE_MEBIBYTE);
retString += "M";
}
retString = padLeft(retString, 5);
diff --git a/java/org/apache/catalina/ssi/SSIInclude.java b/java/org/apache/catalina/ssi/SSIInclude.java
index 9200b8e0e4..b48fb25f46 100644
--- a/java/org/apache/catalina/ssi/SSIInclude.java
+++ b/java/org/apache/catalina/ssi/SSIInclude.java
@@ -19,6 +19,7 @@ package org.apache.catalina.ssi;
import java.io.IOException;
import java.io.PrintWriter;
+
/**
* Implements the Server-side #include command
*
@@ -32,32 +33,26 @@ public final class SSIInclude implements SSICommand {
* @see SSICommand
*/
@Override
- public long process(SSIMediator ssiMediator, String commandName,
- String[] paramNames, String[] paramValues, PrintWriter writer) {
+ public long process(SSIMediator ssiMediator, String commandName, String[] paramNames, String[] paramValues,
+ PrintWriter writer) {
long lastModified = 0;
String configErrMsg = ssiMediator.getConfigErrMsg();
for (int i = 0; i < paramNames.length; i++) {
String paramName = paramNames[i];
String paramValue = paramValues[i];
- String substitutedValue = ssiMediator
- .substituteVariables(paramValue);
+ String substitutedValue = ssiMediator.substituteVariables(paramValue);
try {
- if (paramName.equalsIgnoreCase("file")
- || paramName.equalsIgnoreCase("virtual")) {
+ if (paramName.equalsIgnoreCase("file") || paramName.equalsIgnoreCase("virtual")) {
boolean virtual = paramName.equalsIgnoreCase("virtual");
- lastModified = ssiMediator.getFileLastModified(
- substitutedValue, virtual);
- String text = ssiMediator.getFileText(substitutedValue,
- virtual);
+ lastModified = ssiMediator.getFileLastModified(substitutedValue, virtual);
+ String text = ssiMediator.getFileText(substitutedValue, virtual);
writer.write(text);
} else {
- ssiMediator.log("#include--Invalid attribute: "
- + paramName);
+ ssiMediator.log("#include--Invalid attribute: " + paramName);
writer.write(configErrMsg);
}
} catch (IOException e) {
- ssiMediator.log("#include--Couldn't include file: "
- + substitutedValue, e);
+ ssiMediator.log("#include--Couldn't include file: " + substitutedValue, e);
writer.write(configErrMsg);
}
}
diff --git a/java/org/apache/catalina/ssi/SSIMediator.java b/java/org/apache/catalina/ssi/SSIMediator.java
index 7be56deeb9..b6ef502fda 100644
--- a/java/org/apache/catalina/ssi/SSIMediator.java
+++ b/java/org/apache/catalina/ssi/SSIMediator.java
@@ -31,8 +31,7 @@ import org.apache.catalina.util.URLEncoder;
import org.apache.tomcat.util.security.Escape;
/**
- * Allows the different SSICommand implementations to share data/talk to each
- * other
+ * Allows the different SSICommand implementations to share data/talk to each other
*
* @author Bip Thelin
* @author Amy Roh
@@ -59,8 +58,7 @@ public class SSIMediator {
protected final SSIConditionalState conditionalState = new SSIConditionalState();
- public SSIMediator(SSIExternalResolver ssiExternalResolver,
- long lastModifiedDate) {
+ public SSIMediator(SSIExternalResolver ssiExternalResolver, long lastModifiedDate) {
this.ssiExternalResolver = ssiExternalResolver;
this.lastModifiedDate = lastModifiedDate;
setConfigTimeFmt(DEFAULT_CONFIG_TIME_FMT, true);
@@ -80,9 +78,10 @@ public class SSIMediator {
public void setConfigTimeFmt(String configTimeFmt, boolean fromConstructor) {
this.configTimeFmt = configTimeFmt;
this.strftime = new Strftime(configTimeFmt, Locale.US);
- //Variables like DATE_LOCAL, DATE_GMT, and LAST_MODIFIED need to be
- // updated when
- //the timefmt changes. This is what Apache SSI does.
+ /*
+ * Variables like DATE_LOCAL, DATE_GMT, and LAST_MODIFIED need to be updated when the timefmt changes. This is
+ * what Apache SSI does.
+ */
setDateVariables(fromConstructor);
}
@@ -114,14 +113,12 @@ public class SSIMediator {
public Collection<String> getVariableNames() {
Set<String> variableNames = new HashSet<>();
- //These built-in variables are supplied by the mediator ( if not
- // over-written by
- // the user ) and always exist
+ // These built-in variables are supplied by the mediator (if not over-written by the user) and always exist
variableNames.add("DATE_GMT");
variableNames.add("DATE_LOCAL");
variableNames.add("LAST_MODIFIED");
ssiExternalResolver.addVariableNames(variableNames);
- //Remove any variables that are reserved by this class
+ // Remove any variables that are reserved by this class
Iterator<String> iter = variableNames.iterator();
while (iter.hasNext()) {
String name = iter.next();
@@ -138,8 +135,7 @@ public class SSIMediator {
}
- public long getFileLastModified(String path, boolean virtual)
- throws IOException {
+ public long getFileLastModified(String path, boolean virtual) throws IOException {
return ssiExternalResolver.getFileLastModified(path, virtual);
}
@@ -170,14 +166,13 @@ public class SSIMediator {
String lowerCaseVariableName = variableName.toLowerCase(Locale.ENGLISH);
String variableValue = null;
if (!isNameReserved(lowerCaseVariableName)) {
- //Try getting it externally first, if it fails, try getting the
+ // Try getting it externally first, if it fails, try getting the
// 'built-in'
// value
variableValue = ssiExternalResolver.getVariableValue(variableName);
if (variableValue == null) {
variableName = variableName.toUpperCase(Locale.ENGLISH);
- variableValue = ssiExternalResolver
- .getVariableValue(className + "." + variableName);
+ variableValue = ssiExternalResolver.getVariableValue(className + "." + variableName);
}
if (variableValue != null) {
variableValue = encode(variableValue, encoding);
@@ -188,9 +183,10 @@ public class SSIMediator {
/**
- * Applies variable substitution to the specified String and returns the
- * new resolved string.
+ * Applies variable substitution to the specified String and returns the new resolved string.
+ *
* @param val The value which should be checked
+ *
* @return the value after variable substitution
*/
public String substituteVariables(String val) {
@@ -211,8 +207,7 @@ public class SSIMediator {
while (charStart > -1) {
int charEnd = sb.indexOf(";", charStart);
if (charEnd > -1) {
- char c = (char) Integer.parseInt(
- sb.substring(charStart + 2, charEnd));
+ char c = (char) Integer.parseInt(sb.substring(charStart + 2, charEnd));
sb.delete(charStart, charEnd + 1);
sb.insert(charStart, c);
charStart = sb.indexOf("&#");
@@ -278,9 +273,9 @@ public class SSIMediator {
protected String formatDate(Date date, TimeZone timeZone) {
String retVal;
if (timeZone != null) {
- //we temporarily change strftime. Since SSIMediator is inherently
+ // we temporarily change strftime. Since SSIMediator is inherently
// single-threaded, this
- //isn't a problem
+ // isn't a problem
TimeZone oldTimeZone = strftime.getTimeZone();
strftime.setTimeZone(timeZone);
retVal = strftime.format(date);
@@ -301,7 +296,7 @@ public class SSIMediator {
} else if (encoding.equalsIgnoreCase(ENCODING_ENTITY)) {
retVal = Escape.htmlElementContent(value);
} else {
- //This shouldn't be possible
+ // This shouldn't be possible
throw new IllegalArgumentException("Unknown encoding: " + encoding);
}
return retVal;
@@ -319,32 +314,25 @@ public class SSIMediator {
protected void setDateVariables(boolean fromConstructor) {
- boolean alreadySet = ssiExternalResolver.getVariableValue(className
- + ".alreadyset") != null;
- //skip this if we are being called from the constructor, and this has
- // already
- // been set
+ boolean alreadySet = ssiExternalResolver.getVariableValue(className + ".alreadyset") != null;
+ // skip this if we are being called from the constructor, and this has already been set
if (!(fromConstructor && alreadySet)) {
- ssiExternalResolver.setVariableValue(className + ".alreadyset",
- "true");
+ ssiExternalResolver.setVariableValue(className + ".alreadyset", "true");
Date date = new Date();
TimeZone timeZone = TimeZone.getTimeZone("GMT");
String retVal = formatDate(date, timeZone);
- //If we are setting on of the date variables, we want to remove
- // them from the
- // user
- //defined list of variables, because this is what Apache does
+ /*
+ * If we are setting on of the date variables, we want to remove them from the user defined list of
+ * variables, because this is what Apache does.
+ */
setVariableValue("DATE_GMT", null);
- ssiExternalResolver.setVariableValue(className + ".DATE_GMT",
- retVal);
+ ssiExternalResolver.setVariableValue(className + ".DATE_GMT", retVal);
retVal = formatDate(date, null);
setVariableValue("DATE_LOCAL", null);
- ssiExternalResolver.setVariableValue(className + ".DATE_LOCAL",
- retVal);
+ ssiExternalResolver.setVariableValue(className + ".DATE_LOCAL", retVal);
retVal = formatDate(new Date(lastModifiedDate), null);
setVariableValue("LAST_MODIFIED", null);
- ssiExternalResolver.setVariableValue(className + ".LAST_MODIFIED",
- retVal);
+ ssiExternalResolver.setVariableValue(className + ".LAST_MODIFIED", retVal);
}
}
-}
\ No newline at end of file
+}
diff --git a/java/org/apache/catalina/ssi/SSIPrintenv.java b/java/org/apache/catalina/ssi/SSIPrintenv.java
index 7efa8b70ab..84d35f9b9d 100644
--- a/java/org/apache/catalina/ssi/SSIPrintenv.java
+++ b/java/org/apache/catalina/ssi/SSIPrintenv.java
@@ -31,10 +31,10 @@ public class SSIPrintenv implements SSICommand {
* @see SSICommand
*/
@Override
- public long process(SSIMediator ssiMediator, String commandName,
- String[] paramNames, String[] paramValues, PrintWriter writer) {
+ public long process(SSIMediator ssiMediator, String commandName, String[] paramNames, String[] paramValues,
+ PrintWriter writer) {
long lastModified = 0;
- //any arguments should produce an error
+ // any arguments should produce an error
if (paramNames.length > 0) {
String errorMessage = ssiMediator.getConfigErrMsg();
writer.write(errorMessage);
@@ -42,7 +42,7 @@ public class SSIPrintenv implements SSICommand {
Collection<String> variableNames = ssiMediator.getVariableNames();
for (String variableName : variableNames) {
String variableValue = ssiMediator.getVariableValue(variableName, SSIMediator.ENCODING_ENTITY);
- //This shouldn't happen, since all the variable names must
+ // This shouldn't happen, since all the variable names must
// have values
if (variableValue == null) {
variableValue = "(none)";
diff --git a/java/org/apache/catalina/ssi/SSIProcessor.java b/java/org/apache/catalina/ssi/SSIProcessor.java
index f9f60b188d..f4e2dc9cb6 100644
--- a/java/org/apache/catalina/ssi/SSIProcessor.java
+++ b/java/org/apache/catalina/ssi/SSIProcessor.java
@@ -26,10 +26,10 @@ import java.util.Locale;
import java.util.StringTokenizer;
import org.apache.catalina.util.IOTools;
+
/**
- * The entry point to SSI processing. This class does the actual parsing,
- * delegating to the SSIMediator, SSICommand, and SSIExternalResolver as
- * necessary[
+ * The entry point to SSI processing. This class does the actual parsing, delegating to the SSIMediator, SSICommand, and
+ * SSIExternalResolver as necessary.
*
* @author Dan Sandberg
* @author David Becker
@@ -45,8 +45,7 @@ public class SSIProcessor {
protected final boolean allowExec;
- public SSIProcessor(SSIExternalResolver ssiExternalResolver, int debug,
- boolean allowExec) {
+ public SSIProcessor(SSIExternalResolver ssiExternalResolver, int debug, boolean allowExec) {
this.ssiExternalResolver = ssiExternalResolver;
this.debug = debug;
this.allowExec = allowExec;
@@ -79,24 +78,20 @@ public class SSIProcessor {
/**
- * Process a file with server-side commands, reading from reader and
- * writing the processed version to writer. NOTE: We really should be doing
- * this in a streaming way rather than converting it to an array first.
+ * Process a file with server-side commands, reading from reader and writing the processed version to writer. NOTE:
+ * We really should be doing this in a streaming way rather than converting it to an array first.
*
- * @param reader
- * the reader to read the file containing SSIs from
+ * @param reader the reader to read the file containing SSIs from
* @param lastModifiedDate resource last modification date
- * @param writer
- * the writer to write the file with the SSIs processed.
+ * @param writer the writer to write the file with the SSIs processed.
+ *
* @return the most current modified date resulting from any SSI commands
- * @throws IOException
- * when things go horribly awry. Should be unlikely since the
- * SSICommand usually catches 'normal' IOExceptions.
+ *
+ * @throws IOException when things go horribly awry. Should be unlikely since the SSICommand usually catches
+ * 'normal' IOExceptions.
*/
- public long process(Reader reader, long lastModifiedDate,
- PrintWriter writer) throws IOException {
- SSIMediator ssiMediator = new SSIMediator(ssiExternalResolver,
- lastModifiedDate);
+ public long process(Reader reader, long lastModifiedDate, PrintWriter writer) throws IOException {
+ SSIMediator ssiMediator = new SSIMediator(ssiExternalResolver, lastModifiedDate);
StringWriter stringWriter = new StringWriter();
IOTools.flow(reader, stringWriter);
String fileContents = stringWriter.toString();
@@ -108,11 +103,10 @@ public class SSIProcessor {
while (index < fileContents.length()) {
char c = fileContents.charAt(index);
if (!inside) {
- if (c == COMMAND_START.charAt(0)
- && charCmp(fileContents, index, COMMAND_START)) {
+ if (c == COMMAND_START.charAt(0) && charCmp(fileContents, index, COMMAND_START)) {
inside = true;
index += COMMAND_START.length();
- command.setLength(0); //clear the command string
+ command.setLength(0); // clear the command string
} else {
if (!ssiMediator.getConditionalState().processConditionalCommandsOnly) {
writer.write(c);
@@ -120,43 +114,34 @@ public class SSIProcessor {
index++;
}
} else {
- if (c == COMMAND_END.charAt(0)
- && charCmp(fileContents, index, COMMAND_END)) {
+ if (c == COMMAND_END.charAt(0) && charCmp(fileContents, index, COMMAND_END)) {
inside = false;
index += COMMAND_END.length();
String strCmd = parseCmd(command);
if (debug > 0) {
- ssiExternalResolver.log(
- "SSIProcessor.process -- processing command: "
- + strCmd, null);
+ ssiExternalResolver.log("SSIProcessor.process -- processing command: " + strCmd, null);
}
- String[] paramNames = parseParamNames(command, strCmd
- .length());
- String[] paramValues = parseParamValues(command,
- strCmd.length(), paramNames.length);
- //We need to fetch this value each time, since it may
- // change
- // during the loop
+ String[] paramNames = parseParamNames(command, strCmd.length());
+ String[] paramValues = parseParamValues(command, strCmd.length(), paramNames.length);
+ // We need to fetch this value each time, since it may change during the loop
String configErrMsg = ssiMediator.getConfigErrMsg();
- SSICommand ssiCommand =
- commands.get(strCmd.toLowerCase(Locale.ENGLISH));
+ SSICommand ssiCommand = commands.get(strCmd.toLowerCase(Locale.ENGLISH));
String errorMessage = null;
if (ssiCommand == null) {
errorMessage = "Unknown command: " + strCmd;
} else if (paramValues == null) {
errorMessage = "Error parsing directive parameters.";
} else if (paramNames.length != paramValues.length) {
- errorMessage = "Parameter names count does not match parameter values count on command: "
- + strCmd;
+ errorMessage =
+ "Parameter names count does not match parameter values count on command: " + strCmd;
} else {
- // don't process the command if we are processing
- // conditional
- // commands only and the
- // command is not conditional
- if (!ssiMediator.getConditionalState().processConditionalCommandsOnly
- || ssiCommand instanceof SSIConditional) {
- long lmd = ssiCommand.process(ssiMediator, strCmd,
- paramNames, paramValues, writer);
+ /*
+ * Don't process the command if we are processing conditional commands only and the command
+ * is not conditional
+ */
+ if (!ssiMediator.getConditionalState().processConditionalCommandsOnly ||
+ ssiCommand instanceof SSIConditional) {
+ long lmd = ssiCommand.process(ssiMediator, strCmd, paramNames, paramValues, writer);
if (lmd > lastModifiedDate) {
lastModifiedDate = lmd;
}
@@ -173,20 +158,18 @@ public class SSIProcessor {
}
}
} catch (SSIStopProcessingException e) {
- //If we are here, then we have already stopped processing, so all
- // is good
+ // If we are here, then we have already stopped processing, so all is good
}
return lastModifiedDate;
}
/**
- * Parse a StringBuilder and take out the param type token. Called from
- * <code>requestHandler</code>
+ * Parse a StringBuilder and take out the param type token. Called from <code>requestHandler</code>
*
- * @param cmd
- * a value of type 'StringBuilder'
+ * @param cmd a value of type 'StringBuilder'
* @param start index on which parsing will start
+ *
* @return an array with the parameter names
*/
protected String[] parseParamNames(StringBuilder cmd, int start) {
@@ -237,13 +220,12 @@ public class SSIProcessor {
/**
- * Parse a StringBuilder and take out the param token. Called from
- * <code>requestHandler</code>
+ * Parse a StringBuilder and take out the param token. Called from <code>requestHandler</code>
*
- * @param cmd
- * a value of type 'StringBuilder'
+ * @param cmd a value of type 'StringBuilder'
* @param start index on which parsing will start
* @param count number of values which should be parsed
+ *
* @return an array with the parameter values
*/
protected String[] parseParamValues(StringBuilder cmd, int start, int count) {
@@ -275,17 +257,17 @@ public class SSIProcessor {
if (c == endQuote && !escaped) {
break;
}
- // Since parsing of attributes and var
- // substitution is done in separate places,
- // we need to leave escape in the string
+ /*
+ * Since parsing of attributes and var substitution is done in separate places, we need to leave
+ * escape in the string
+ */
if (c == '$' && escaped) {
sb.append('\\');
}
escaped = false;
sb.append(c);
}
- // If we hit the end without seeing a quote
- // the signal an error
+ // If we hit the end without seeing a quote the signal an error
if (bIdx == cmd.length()) {
return null;
}
@@ -299,11 +281,10 @@ public class SSIProcessor {
/**
- * Parse a StringBuilder and take out the command token. Called from
- * <code>requestHandler</code>
+ * Parse a StringBuilder and take out the command token. Called from <code>requestHandler</code>
+ *
+ * @param cmd a value of type 'StringBuilder'
*
- * @param cmd
- * a value of type 'StringBuilder'
* @return a value of type 'String', or null if there is none
*/
private String parseCmd(StringBuilder cmd) {
@@ -344,4 +325,4 @@ public class SSIProcessor {
protected boolean isQuote(char c) {
return c == '\'' || c == '\"' || c == '`';
}
-}
\ No newline at end of file
+}
diff --git a/java/org/apache/catalina/ssi/SSIServlet.java b/java/org/apache/catalina/ssi/SSIServlet.java
index 1adb61ed79..e767b978b6 100644
--- a/java/org/apache/catalina/ssi/SSIServlet.java
+++ b/java/org/apache/catalina/ssi/SSIServlet.java
@@ -32,9 +32,9 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
/**
- * Servlet to process SSI requests within a webpage. Mapped to a path from
- * within web.xml.
+ * Servlet to process SSI requests within a webpage. Mapped to a path from within web.xml.
*
* @author Bip Thelin
* @author Amy Roh
@@ -60,12 +60,11 @@ public class SSIServlet extends HttpServlet {
protected boolean allowExec = false;
- //----------------- Public methods.
+ // ----------------- Public methods.
/**
* Initialize this servlet.
*
- * @exception ServletException
- * if an error occurs
+ * @exception ServletException if an error occurs
*/
@Override
public void init() throws ServletException {
@@ -74,8 +73,7 @@ public class SSIServlet extends HttpServlet {
debug = Integer.parseInt(getServletConfig().getInitParameter("debug"));
}
- isVirtualWebappRelative =
- Boolean.parseBoolean(getServletConfig().getInitParameter("isVirtualWebappRelative"));
+ isVirtualWebappRelative = Boolean.parseBoolean(getServletConfig().getInitParameter("isVirtualWebappRelative"));
if (getServletConfig().getInitParameter("expires") != null) {
expires = Long.valueOf(getServletConfig().getInitParameter("expires"));
@@ -89,8 +87,7 @@ public class SSIServlet extends HttpServlet {
outputEncoding = getServletConfig().getInitParameter("outputEncoding");
}
- allowExec = Boolean.parseBoolean(
- getServletConfig().getInitParameter("allowExec"));
+ allowExec = Boolean.parseBoolean(getServletConfig().getInitParameter("allowExec"));
if (debug > 0) {
log("SSIServlet.init() SSI invoker started with 'debug'=" + debug);
@@ -102,18 +99,14 @@ public class SSIServlet extends HttpServlet {
/**
* Process and forward the GET request to our <code>requestHandler()</code>*
*
- * @param req
- * a value of type 'HttpServletRequest'
- * @param res
- * a value of type 'HttpServletResponse'
- * @exception IOException
- * if an error occurs
- * @exception ServletException
- * if an error occurs
+ * @param req a value of type 'HttpServletRequest'
+ * @param res a value of type 'HttpServletResponse'
+ *
+ * @exception IOException if an error occurs
+ * @exception ServletException if an error occurs
*/
@Override
- public void doGet(HttpServletRequest req, HttpServletResponse res)
- throws IOException, ServletException {
+ public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
if (debug > 0) {
log("SSIServlet.doGet()");
}
@@ -122,21 +115,16 @@ public class SSIServlet extends HttpServlet {
/**
- * Process and forward the POST request to our
- * <code>requestHandler()</code>.
+ * Process and forward the POST request to our <code>requestHandler()</code>.
*
- * @param req
- * a value of type 'HttpServletRequest'
- * @param res
- * a value of type 'HttpServletResponse'
- * @exception IOException
- * if an error occurs
- * @exception ServletException
- * if an error occurs
+ * @param req a value of type 'HttpServletRequest'
+ * @param res a value of type 'HttpServletResponse'
+ *
+ * @exception IOException if an error occurs
+ * @exception ServletException if an error occurs
*/
@Override
- public void doPost(HttpServletRequest req, HttpServletResponse res)
- throws IOException, ServletException {
+ public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
if (debug > 0) {
log("SSIServlet.doPost()");
}
@@ -147,25 +135,22 @@ public class SSIServlet extends HttpServlet {
/**
* Process our request and locate right SSI command.
*
- * @param req
- * a value of type 'HttpServletRequest'
- * @param res
- * a value of type 'HttpServletResponse'
+ * @param req a value of type 'HttpServletRequest'
+ * @param res a value of type 'HttpServletResponse'
+ *
* @throws IOException an IO error occurred
*/
- protected void requestHandler(HttpServletRequest req,
- HttpServletResponse res) throws IOException {
+ protected void requestHandler(HttpServletRequest req, HttpServletResponse res) throws IOException {
ServletContext servletContext = getServletContext();
String path = SSIServletRequestUtil.getRelativePath(req);
if (debug > 0) {
- log("SSIServlet.requestHandler()\n" + "Serving "
- + (buffered?"buffered ":"unbuffered ") + "resource '"
- + path + "'");
+ log("SSIServlet.requestHandler()\n" + "Serving " + (buffered ? "buffered " : "unbuffered ") + "resource '" +
+ path + "'");
}
// Exclude any resource in the /WEB-INF and /META-INF subdirectories
// (the "toUpperCase()" avoids problems on Windows systems)
- if (path == null || path.toUpperCase(Locale.ENGLISH).startsWith("/WEB-INF")
- || path.toUpperCase(Locale.ENGLISH).startsWith("/META-INF")) {
+ if (path == null || path.toUpperCase(Locale.ENGLISH).startsWith("/WEB-INF") ||
+ path.toUpperCase(Locale.ENGLISH).startsWith("/META-INF")) {
res.sendError(HttpServletResponse.SC_NOT_FOUND);
log("Can't serve file: " + path);
return;
@@ -182,20 +167,16 @@ public class SSIServlet extends HttpServlet {
}
res.setContentType(resourceMimeType + ";charset=" + outputEncoding);
if (expires != null) {
- res.setDateHeader("Expires", (new java.util.Date()).getTime()
- + expires.longValue() * 1000);
+ res.setDateHeader("Expires", (new java.util.Date()).getTime() + expires.longValue() * 1000);
}
processSSI(req, res, resource);
}
- protected void processSSI(HttpServletRequest req, HttpServletResponse res,
- URL resource) throws IOException {
- SSIExternalResolver ssiExternalResolver =
- new SSIServletExternalResolver(getServletContext(), req, res,
- isVirtualWebappRelative, debug, inputEncoding);
- SSIProcessor ssiProcessor = new SSIProcessor(ssiExternalResolver,
- debug, allowExec);
+ protected void processSSI(HttpServletRequest req, HttpServletResponse res, URL resource) throws IOException {
+ SSIExternalResolver ssiExternalResolver = new SSIServletExternalResolver(getServletContext(), req, res,
+ isVirtualWebappRelative, debug, inputEncoding);
+ SSIProcessor ssiProcessor = new SSIProcessor(ssiExternalResolver, debug, allowExec);
PrintWriter printWriter = null;
StringWriter stringWriter = null;
if (buffered) {
@@ -219,8 +200,7 @@ public class SSIServlet extends HttpServlet {
}
try (BufferedReader bufferedReader = new BufferedReader(isr)) {
- long lastModified = ssiProcessor.process(bufferedReader,
- resourceInfo.getLastModified(), printWriter);
+ long lastModified = ssiProcessor.process(bufferedReader, resourceInfo.getLastModified(), printWriter);
if (lastModified > 0) {
res.setDateHeader("last-modified", lastModified);
}
diff --git a/java/org/apache/catalina/ssi/SSIServletExternalResolver.java b/java/org/apache/catalina/ssi/SSIServletExternalResolver.java
index 44ddfc87da..1219713762 100644
--- a/java/org/apache/catalina/ssi/SSIServletExternalResolver.java
+++ b/java/org/apache/catalina/ssi/SSIServletExternalResolver.java
@@ -47,16 +47,12 @@ import org.apache.tomcat.util.http.RequestUtil;
* @author David Becker
*/
public class SSIServletExternalResolver implements SSIExternalResolver {
- protected final String VARIABLE_NAMES[] = {"AUTH_TYPE", "CONTENT_LENGTH",
- "CONTENT_TYPE", "DOCUMENT_NAME", "DOCUMENT_URI",
- "GATEWAY_INTERFACE", "HTTP_ACCEPT", "HTTP_ACCEPT_ENCODING",
- "HTTP_ACCEPT_LANGUAGE", "HTTP_CONNECTION", "HTTP_HOST",
- "HTTP_REFERER", "HTTP_USER_AGENT", "PATH_INFO", "PATH_TRANSLATED",
- "QUERY_STRING", "QUERY_STRING_UNESCAPED", "REMOTE_ADDR",
- "REMOTE_HOST", "REMOTE_PORT", "REMOTE_USER", "REQUEST_METHOD",
- "REQUEST_URI", "SCRIPT_FILENAME", "SCRIPT_NAME", "SERVER_ADDR",
- "SERVER_NAME", "SERVER_PORT", "SERVER_PROTOCOL", "SERVER_SOFTWARE",
- "UNIQUE_ID"};
+ protected final String VARIABLE_NAMES[] = { "AUTH_TYPE", "CONTENT_LENGTH", "CONTENT_TYPE", "DOCUMENT_NAME",
+ "DOCUMENT_URI", "GATEWAY_INTERFACE", "HTTP_ACCEPT", "HTTP_ACCEPT_ENCODING", "HTTP_ACCEPT_LANGUAGE",
+ "HTTP_CONNECTION", "HTTP_HOST", "HTTP_REFERER", "HTTP_USER_AGENT", "PATH_INFO", "PATH_TRANSLATED",
+ "QUERY_STRING", "QUERY_STRING_UNESCAPED", "REMOTE_ADDR", "REMOTE_HOST", "REMOTE_PORT", "REMOTE_USER",
+ "REQUEST_METHOD", "REQUEST_URI", "SCRIPT_FILENAME", "SCRIPT_NAME", "SERVER_ADDR", "SERVER_NAME",
+ "SERVER_PORT", "SERVER_PROTOCOL", "SERVER_SOFTWARE", "UNIQUE_ID" };
protected final ServletContext context;
protected final HttpServletRequest req;
protected final HttpServletResponse res;
@@ -64,8 +60,7 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
protected final int debug;
protected final String inputEncoding;
- public SSIServletExternalResolver(ServletContext context,
- HttpServletRequest req, HttpServletResponse res,
+ public SSIServletExternalResolver(ServletContext context, HttpServletRequest req, HttpServletResponse res,
boolean isVirtualWebappRelative, int debug, String inputEncoding) {
this.context = context;
this.req = req;
@@ -78,9 +73,10 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
@Override
public void log(String message, Throwable throwable) {
- //We can't assume that Servlet.log( message, null )
- //is the same as Servlet.log( message ), since API
- //doesn't seem to say so.
+ /*
+ * We can't assume that Servlet.log(message, null) is the same as Servlet.log( message ), since API doesn't seem
+ * to say so.
+ */
if (throwable != null) {
context.log(message, throwable);
} else {
@@ -115,8 +111,7 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
Enumeration<String> e = req.getAttributeNames();
while (e.hasMoreElements()) {
String name = e.nextElement();
- if (targetName.equalsIgnoreCase(name)
- && !isNameReserved(name)) {
+ if (targetName.equalsIgnoreCase(name) && !isNameReserved(name)) {
object = req.getAttribute(name);
if (object != null) {
break;
@@ -130,8 +125,7 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
protected boolean isNameReserved(String name) {
- return name.startsWith("java.") || name.startsWith("javax.")
- || name.startsWith("sun.");
+ return name.startsWith("java.") || name.startsWith("javax.") || name.startsWith("sun.");
}
@@ -164,12 +158,11 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
if (nameParts[0].equals("PATH")) {
requiredParts = 1;
}
- }
- else if (nameParts[0].equals("AUTH")) {
+ } else if (nameParts[0].equals("AUTH")) {
if (nameParts[1].equals("TYPE")) {
retVal = req.getAuthType();
}
- } else if(nameParts[0].equals("CONTENT")) {
+ } else if (nameParts[0].equals("CONTENT")) {
if (nameParts[1].equals("LENGTH")) {
long contentLength = req.getContentLengthLong();
if (contentLength >= 0) {
@@ -203,27 +196,22 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
Enumeration<String> acceptHeaders = req.getHeaders(accept);
if (acceptHeaders != null) {
if (acceptHeaders.hasMoreElements()) {
- StringBuilder rv = new StringBuilder(
- acceptHeaders.nextElement());
+ StringBuilder rv = new StringBuilder(acceptHeaders.nextElement());
while (acceptHeaders.hasMoreElements()) {
rv.append(", ");
rv.append(acceptHeaders.nextElement());
}
- retVal = rv.toString();
- }
+ retVal = rv.toString();
+ }
}
}
- }
- else if (nameParts[1].equals("CONNECTION")) {
+ } else if (nameParts[1].equals("CONNECTION")) {
retVal = req.getHeader("Connection");
- }
- else if (nameParts[1].equals("HOST")) {
+ } else if (nameParts[1].equals("HOST")) {
retVal = req.getHeader("Host");
- }
- else if (nameParts[1].equals("REFERER")) {
+ } else if (nameParts[1].equals("REFERER")) {
retVal = req.getHeader("Referer");
- }
- else if (nameParts[1].equals("USER")) {
+ } else if (nameParts[1].equals("USER")) {
if (nameParts.length == 3) {
if (nameParts[2].equals("AGENT")) {
requiredParts = 3;
@@ -242,7 +230,7 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
if (nameParts[1].equals("STRING")) {
String queryString = req.getQueryString();
if (nameParts.length == 2) {
- //apache displays this as an empty string rather than (none)
+ // apache displays this as an empty string rather than (none)
retVal = nullToEmptyString(queryString);
} else if (nameParts[2].equals("UNESCAPED")) {
requiredParts = 3;
@@ -251,15 +239,14 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
Charset requestCharset = null;
boolean useBodyEncodingForURI = false;
- // Get encoding settings from request / connector if
- // possible
+ // Get encoding settings from request / connector if possible
if (req instanceof Request) {
try {
- requestCharset = ((Request)req).getCoyoteRequest().getCharset();
+ requestCharset = ((Request) req).getCoyoteRequest().getCharset();
} catch (UnsupportedEncodingException e) {
// Ignore
}
- Connector connector = ((Request)req).getConnector();
+ Connector connector = ((Request) req).getConnector();
uriCharset = connector.getURICharset();
useBodyEncodingForURI = connector.getUseBodyEncodingForURI();
}
@@ -280,7 +267,7 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
}
}
}
- } else if(nameParts[0].equals("REMOTE")) {
+ } else if (nameParts[0].equals("REMOTE")) {
if (nameParts[1].equals("ADDR")) {
retVal = req.getRemoteAddr();
} else if (nameParts[1].equals("HOST")) {
@@ -288,28 +275,25 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
} else if (nameParts[1].equals("IDENT")) {
// Not implemented
} else if (nameParts[1].equals("PORT")) {
- retVal = Integer.toString( req.getRemotePort());
+ retVal = Integer.toString(req.getRemotePort());
} else if (nameParts[1].equals("USER")) {
retVal = req.getRemoteUser();
}
- } else if(nameParts[0].equals("REQUEST")) {
+ } else if (nameParts[0].equals("REQUEST")) {
if (nameParts[1].equals("METHOD")) {
retVal = req.getMethod();
- }
- else if (nameParts[1].equals("URI")) {
+ } else if (nameParts[1].equals("URI")) {
// If this is an error page, get the original URI
- retVal = (String) req.getAttribute(
- RequestDispatcher.FORWARD_REQUEST_URI);
+ retVal = (String) req.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
if (retVal == null) {
- retVal=req.getRequestURI();
+ retVal = req.getRequestURI();
}
}
} else if (nameParts[0].equals("SCRIPT")) {
String scriptName = req.getServletPath();
if (nameParts[1].equals("FILENAME")) {
retVal = context.getRealPath(scriptName);
- }
- else if (nameParts[1].equals("NAME")) {
+ } else if (nameParts[1].equals("NAME")) {
retVal = scriptName;
}
} else if (nameParts[0].equals("SERVER")) {
@@ -338,7 +322,7 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
if (requiredParts != nameParts.length) {
return null;
}
- return retVal;
+ return retVal;
}
@Override
@@ -360,15 +344,14 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
String retVal = null;
int lastSlash = servletPath.lastIndexOf('/');
if (lastSlash >= 0) {
- //cut off file name
+ // cut off file name
retVal = servletPath.substring(0, lastSlash + 1);
}
return retVal;
}
- protected String getPathWithoutContext(final String contextPath,
- final String servletPath) {
+ protected String getPathWithoutContext(final String contextPath, final String servletPath) {
if (servletPath.startsWith(contextPath)) {
return servletPath.substring(contextPath.length());
}
@@ -380,42 +363,35 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
String pathWithoutContext = SSIServletRequestUtil.getRelativePath(req);
String prefix = getPathWithoutFileName(pathWithoutContext);
if (prefix == null) {
- throw new IOException("Couldn't remove filename from path: "
- + pathWithoutContext);
+ throw new IOException("Couldn't remove filename from path: " + pathWithoutContext);
}
String fullPath = prefix + path;
String retVal = RequestUtil.normalize(fullPath);
if (retVal == null) {
- throw new IOException("Normalization yielded null on path: "
- + fullPath);
+ throw new IOException("Normalization yielded null on path: " + fullPath);
}
return retVal;
}
- protected ServletContextAndPath getServletContextAndPathFromNonVirtualPath(
- String nonVirtualPath) throws IOException {
+ protected ServletContextAndPath getServletContextAndPathFromNonVirtualPath(String nonVirtualPath)
+ throws IOException {
if (nonVirtualPath.startsWith("/") || nonVirtualPath.startsWith("\\")) {
- throw new IOException("A non-virtual path can't be absolute: "
- + nonVirtualPath);
+ throw new IOException("A non-virtual path can't be absolute: " + nonVirtualPath);
}
if (nonVirtualPath.indexOf("../") >= 0) {
- throw new IOException("A non-virtual path can't contain '../' : "
- + nonVirtualPath);
+ throw new IOException("A non-virtual path can't contain '../' : " + nonVirtualPath);
}
String path = getAbsolutePath(nonVirtualPath);
- ServletContextAndPath csAndP = new ServletContextAndPath(
- context, path);
+ ServletContextAndPath csAndP = new ServletContextAndPath(context, path);
return csAndP;
}
- protected ServletContextAndPath getServletContextAndPathFromVirtualPath(
- String virtualPath) throws IOException {
+ protected ServletContextAndPath getServletContextAndPathFromVirtualPath(String virtualPath) throws IOException {
if (!virtualPath.startsWith("/") && !virtualPath.startsWith("\\")) {
- return new ServletContextAndPath(context,
- getAbsolutePath(virtualPath));
+ return new ServletContextAndPath(context, getAbsolutePath(virtualPath));
}
String normalized = RequestUtil.normalize(virtualPath);
@@ -425,20 +401,14 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
ServletContext normContext = context.getContext(normalized);
if (normContext == null) {
- throw new IOException("Couldn't get context for path: "
- + normalized);
+ throw new IOException("Couldn't get context for path: " + normalized);
}
- //If it's the root context, then there is no context element
- // to remove,
- // ie:
- // '/file1.shtml' vs '/appName1/file1.shtml'
+ // If it's the root context, then there is no context element to remove.
+ // ie: '/file1.shtml' vs '/appName1/file1.shtml'
if (!isRootContext(normContext)) {
- String noContext = getPathWithoutContext(
- normContext.getContextPath(), normalized);
+ String noContext = getPathWithoutContext(normContext.getContextPath(), normalized);
if (noContext == null) {
- throw new IOException(
- "Couldn't remove context from path: "
- + normalized);
+ throw new IOException("Couldn't remove context from path: " + normalized);
}
return new ServletContextAndPath(normContext, noContext);
}
@@ -447,25 +417,19 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
}
- //Assumes servletContext is not-null
- //Assumes that identity comparison will be true for the same context
- //Assuming the above, getContext("/") will be non-null as long as the root
- // context is
- // accessible.
- //If it isn't, then servletContext can't be the root context anyway, hence
- // they will
- // not match.
+ // Assumes servletContext is not-null
+ // Assumes that identity comparison will be true for the same context
+ // Assuming the above, getContext("/") will be non-null as long as the root context is accessible.
+ // If it isn't, then servletContext can't be the root context anyway, hence they will not match.
protected boolean isRootContext(ServletContext servletContext) {
return servletContext == servletContext.getContext("/");
}
- protected ServletContextAndPath getServletContextAndPath(
- String originalPath, boolean virtual) throws IOException {
+ protected ServletContextAndPath getServletContextAndPath(String originalPath, boolean virtual) throws IOException {
ServletContextAndPath csAndP = null;
if (debug > 0) {
- log("SSIServletExternalResolver.getServletContextAndPath( "
- + originalPath + ", " + virtual + ")", null);
+ log("SSIServletExternalResolver.getServletContextAndPath( " + originalPath + ", " + virtual + ")", null);
}
if (virtual) {
csAndP = getServletContextAndPathFromVirtualPath(originalPath);
@@ -476,10 +440,8 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
}
- protected URLConnection getURLConnection(String originalPath,
- boolean virtual) throws IOException {
- ServletContextAndPath csAndP = getServletContextAndPath(originalPath,
- virtual);
+ protected URLConnection getURLConnection(String originalPath, boolean virtual) throws IOException {
+ ServletContextAndPath csAndP = getServletContextAndPath(originalPath, virtual);
ServletContext context = csAndP.getServletContext();
String path = csAndP.getPath();
URL url = context.getResource(path);
@@ -492,8 +454,7 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
@Override
- public long getFileLastModified(String path, boolean virtual)
- throws IOException {
+ public long getFileLastModified(String path, boolean virtual) throws IOException {
long lastModified = 0;
try {
URLConnection urlConnection = getURLConnection(path, virtual);
@@ -518,49 +479,46 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
}
- //We are making lots of unnecessary copies of the included data here. If
- //someone ever complains that this is slow, we should connect the included
- // stream to the print writer that SSICommand uses.
+ /*
+ * We are making lots of unnecessary copies of the included data here. If someone ever complains that this is slow,
+ * we should connect the included stream to the print writer that SSICommand uses.
+ */
@Override
- public String getFileText(String originalPath, boolean virtual)
- throws IOException {
+ public String getFileText(String originalPath, boolean virtual) throws IOException {
try {
- ServletContextAndPath csAndP = getServletContextAndPath(
- originalPath, virtual);
+ ServletContextAndPath csAndP = getServletContextAndPath(originalPath, virtual);
ServletContext context = csAndP.getServletContext();
String path = csAndP.getPath();
RequestDispatcher rd = context.getRequestDispatcher(path);
if (rd == null) {
- throw new IOException(
- "Couldn't get request dispatcher for path: " + path);
+ throw new IOException("Couldn't get request dispatcher for path: " + path);
}
ByteArrayServletOutputStream basos = new ByteArrayServletOutputStream();
ResponseIncludeWrapper responseIncludeWrapper = new ResponseIncludeWrapper(res, basos);
rd.include(req, responseIncludeWrapper);
- //We can't assume the included servlet flushed its output
+ // We can't assume the included servlet flushed its output
responseIncludeWrapper.flushOutputStreamOrWriter();
byte[] bytes = basos.toByteArray();
- //Assume platform default encoding unless otherwise specified
+ // Assume platform default encoding unless otherwise specified
String retVal;
if (inputEncoding == null) {
- retVal = new String( bytes );
+ retVal = new String(bytes);
} else {
- retVal = new String (bytes,
- B2CConverter.getCharset(inputEncoding));
+ retVal = new String(bytes, B2CConverter.getCharset(inputEncoding));
}
- //make an assumption that an empty response is a failure. This is
- // a problem
- // if a truly empty file
- //were included, but not sure how else to tell.
+ /*
+ * Make an assumption that an empty response is a failure. This is a problem if a truly empty file were
+ * included, but not sure how else to tell.
+ */
if (retVal.equals("") && !req.getMethod().equalsIgnoreCase("HEAD")) {
throw new IOException("Couldn't find file: " + path);
}
return retVal;
} catch (ServletException e) {
- throw new IOException("Couldn't include file: " + originalPath
- + " because of ServletException: " + e.getMessage());
+ throw new IOException(
+ "Couldn't include file: " + originalPath + " because of ServletException: " + e.getMessage());
}
}
@@ -569,8 +527,7 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
protected final String path;
- public ServletContextAndPath(ServletContext servletContext,
- String path) {
+ public ServletContextAndPath(ServletContext servletContext, String path) {
this.servletContext = servletContext;
this.path = path;
}
diff --git a/java/org/apache/catalina/ssi/SSIServletRequestUtil.java b/java/org/apache/catalina/ssi/SSIServletRequestUtil.java
index 8dd4eb01a1..2bc0379d4b 100644
--- a/java/org/apache/catalina/ssi/SSIServletRequestUtil.java
+++ b/java/org/apache/catalina/ssi/SSIServletRequestUtil.java
@@ -23,23 +23,19 @@ import org.apache.tomcat.util.http.RequestUtil;
public class SSIServletRequestUtil {
/**
- * Return the relative path associated with this servlet. Taken from
- * DefaultServlet.java. Perhaps this should be put in
- * org.apache.catalina.util somewhere? Seems like it would be widely used.
+ * Return the relative path associated with this servlet. Taken from DefaultServlet.java. Perhaps this should be put
+ * in org.apache.catalina.util somewhere? Seems like it would be widely used.
+ *
+ * @param request The servlet request we are processing
*
- * @param request
- * The servlet request we are processing
* @return the relative path
*/
public static String getRelativePath(HttpServletRequest request) {
// Are we being processed by a RequestDispatcher.include()?
- if (request.getAttribute(
- RequestDispatcher.INCLUDE_REQUEST_URI) != null) {
- String result = (String)request.getAttribute(
- RequestDispatcher.INCLUDE_PATH_INFO);
+ if (request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null) {
+ String result = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
if (result == null) {
- result = (String)request.getAttribute(
- RequestDispatcher.INCLUDE_SERVLET_PATH);
+ result = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
}
if ((result == null) || (result.equals(""))) {
result = "/";
diff --git a/java/org/apache/catalina/ssi/SSISet.java b/java/org/apache/catalina/ssi/SSISet.java
index 235bb2b6f2..8af6dc3877 100644
--- a/java/org/apache/catalina/ssi/SSISet.java
+++ b/java/org/apache/catalina/ssi/SSISet.java
@@ -18,6 +18,7 @@ package org.apache.catalina.ssi;
import java.io.PrintWriter;
+
/**
* Implements the Server-side #set command
*
@@ -30,9 +31,8 @@ public class SSISet implements SSICommand {
* @see SSICommand
*/
@Override
- public long process(SSIMediator ssiMediator, String commandName,
- String[] paramNames, String[] paramValues, PrintWriter writer)
- throws SSIStopProcessingException {
+ public long process(SSIMediator ssiMediator, String commandName, String[] paramNames, String[] paramValues,
+ PrintWriter writer) throws SSIStopProcessingException {
long lastModified = 0;
String errorMessage = ssiMediator.getConfigErrMsg();
String variableName = null;
@@ -43,10 +43,8 @@ public class SSISet implements SSICommand {
variableName = paramValue;
} else if (paramName.equalsIgnoreCase("value")) {
if (variableName != null) {
- String substitutedValue = ssiMediator
- .substituteVariables(paramValue);
- ssiMediator.setVariableValue(variableName,
- substitutedValue);
+ String substitutedValue = ssiMediator.substituteVariables(paramValue);
+ ssiMediator.setVariableValue(variableName, substitutedValue);
lastModified = System.currentTimeMillis();
} else {
ssiMediator.log("#set--no variable specified");
diff --git a/java/org/apache/catalina/ssi/SSIStopProcessingException.java b/java/org/apache/catalina/ssi/SSIStopProcessingException.java
index c31bd7baf7..be8c7008df 100644
--- a/java/org/apache/catalina/ssi/SSIStopProcessingException.java
+++ b/java/org/apache/catalina/ssi/SSIStopProcessingException.java
@@ -18,9 +18,8 @@ package org.apache.catalina.ssi;
/**
- * Exception used to tell SSIProcessor that it should stop processing SSI
- * commands. This is used to mimic the Apache behavior in #set with invalid
- * attributes.
+ * Exception used to tell SSIProcessor that it should stop processing SSI commands. This is used to mimic the Apache
+ * behavior in #set with invalid attributes.
*
* @author Paul Speed
* @author Dan Sandberg
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org