This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 99754a3941 Code clean-up. Formatting. No functional change.
99754a3941 is described below
commit 99754a3941769ff6b89fd530c63571ea1fba6641
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Jan 15 13:03:24 2024 +0000
Code clean-up. Formatting. No functional change.
---
.../catalina/ssi/ByteArrayServletOutputStream.java | 4 +-
.../apache/catalina/ssi/ExpressionParseTree.java | 75 +++++----
.../apache/catalina/ssi/ExpressionTokenizer.java | 39 +++--
.../catalina/ssi/ResponseIncludeWrapper.java | 45 +++---
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 | 13 +-
java/org/apache/catalina/ssi/SSIEcho.java | 15 +-
java/org/apache/catalina/ssi/SSIExec.java | 13 +-
.../apache/catalina/ssi/SSIExternalResolver.java | 26 ++--
java/org/apache/catalina/ssi/SSIFilter.java | 42 ++---
java/org/apache/catalina/ssi/SSIFlastmod.java | 14 +-
java/org/apache/catalina/ssi/SSIFsize.java | 22 ++-
java/org/apache/catalina/ssi/SSIInclude.java | 18 +--
java/org/apache/catalina/ssi/SSIMediator.java | 78 ++++------
java/org/apache/catalina/ssi/SSIPrintenv.java | 8 +-
java/org/apache/catalina/ssi/SSIProcessor.java | 111 ++++++-------
java/org/apache/catalina/ssi/SSIServlet.java | 86 ++++-------
.../catalina/ssi/SSIServletExternalResolver.java | 171 +++++++++------------
.../apache/catalina/ssi/SSIServletRequestUtil.java | 18 +--
java/org/apache/catalina/ssi/SSISet.java | 13 +-
.../catalina/ssi/SSIStopProcessingException.java | 5 +-
23 files changed, 375 insertions(+), 506 deletions(-)
diff --git a/java/org/apache/catalina/ssi/ByteArrayServletOutputStream.java
b/java/org/apache/catalina/ssi/ByteArrayServletOutputStream.java
index 4f1f8d7039..aa713db084 100644
--- a/java/org/apache/catalina/ssi/ByteArrayServletOutputStream.java
+++ b/java/org/apache/catalina/ssi/ByteArrayServletOutputStream.java
@@ -23,10 +23,10 @@ import jakarta.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 ce535d268e..af181050e3 100644
--- a/java/org/apache/catalina/ssi/ExpressionParseTree.java
+++ b/java/org/apache/catalina/ssi/ExpressionParseTree.java
@@ -26,6 +26,7 @@ import java.util.regex.PatternSyntaxException;
import org.apache.tomcat.util.ExceptionUtils;
import org.apache.tomcat.util.res.StringManager;
+
/**
* Represents a parsed expression.
*
@@ -34,13 +35,13 @@ import org.apache.tomcat.util.res.StringManager;
public class ExpressionParseTree {
private static final StringManager sm =
StringManager.getManager(ExpressionParseTree.class);
/**
- * 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<>();
/**
@@ -55,20 +56,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
*
@@ -85,8 +86,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) {
@@ -123,8 +124,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;
@@ -139,7 +139,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 {
@@ -154,7 +156,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);
@@ -164,51 +166,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;
}
}
@@ -235,6 +237,7 @@ public class ExpressionParseTree {
*/
public abstract boolean evaluate();
}
+
/**
* A node the represents a String value
*/
@@ -295,15 +298,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
*/
@@ -312,6 +313,7 @@ public class ExpressionParseTree {
left = values.remove(0);
}
}
+
private static final class NotNode extends OppNode {
@Override
public boolean evaluate() {
@@ -339,6 +341,7 @@ public class ExpressionParseTree {
return left + " NOT";
}
}
+
private static final class AndNode extends OppNode {
@Override
public boolean evaluate() {
@@ -360,6 +363,7 @@ public class ExpressionParseTree {
return left + " " + right + " AND";
}
}
+
private static final class OrNode extends OppNode {
@Override
public boolean evaluate() {
@@ -381,14 +385,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);
ssiMediator.clearMatchGroups();
@@ -411,6 +415,7 @@ public class ExpressionParseTree {
return val1.compareTo(val2);
}
}
+
private final class EqualNode extends CompareNode {
@Override
public boolean evaluate() {
@@ -429,6 +434,7 @@ public class ExpressionParseTree {
return left + " " + right + " EQ";
}
}
+
private final class GreaterThanNode extends CompareNode {
@Override
public boolean evaluate() {
@@ -447,6 +453,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 45a52110ca..7a06d27735 100644
--- a/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java
+++ b/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java
@@ -28,8 +28,7 @@ import jakarta.servlet.http.HttpServletResponseWrapper;
import org.apache.tomcat.util.http.FastHttpDateFormat;
/**
- * An HttpServletResponseWrapper, used from
- * <code>SSIServletExternalResolver</code>
+ * An HttpServletResponseWrapper, used from
<code>SSIServletExternalResolver</code>
*
* @author Bip Thelin
* @author David Becker
@@ -50,23 +49,21 @@ public class ResponseIncludeWrapper extends
HttpServletResponseWrapper {
protected PrintWriter printWriter;
/**
- * 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 {
@@ -80,21 +77,19 @@ public class ResponseIncludeWrapper extends
HttpServletResponseWrapper {
/**
- * Return a printwriter, throws and exception if an OutputStream already
- * been returned.
+ * Return a printwriter, throws and exception if an 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;
}
@@ -103,12 +98,11 @@ public class ResponseIncludeWrapper extends
HttpServletResponseWrapper {
/**
- * Return an OutputStream, throws and exception if a printwriter already
- * been returned.
+ * Return an OutputStream, throws and exception if a printwriter already
been returned.
*
* @return an 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 {
@@ -123,12 +117,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;
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 3e7fd8cda0..22066091cc 100644
--- a/java/org/apache/catalina/ssi/SSIConfig.java
+++ b/java/org/apache/catalina/ssi/SSIConfig.java
@@ -20,6 +20,7 @@ package org.apache.catalina.ssi;
import java.io.PrintWriter;
import org.apache.tomcat.util.res.StringManager;
+
/**
* Implements the Server-side #exec command
*
@@ -30,17 +31,17 @@ import org.apache.tomcat.util.res.StringManager;
*/
public final class SSIConfig implements SSICommand {
private static final StringManager sm =
StringManager.getManager(SSIConfig.class);
+
/**
* @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")) {
@@ -49,9 +50,7 @@ public final class SSIConfig implements SSICommand {
ssiMediator.setConfigTimeFmt(substitutedValue);
} else {
ssiMediator.log(sm.getString("ssiCommand.invalidAttribute",
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);
}
diff --git a/java/org/apache/catalina/ssi/SSIEcho.java
b/java/org/apache/catalina/ssi/SSIEcho.java
index 2601b1296b..c0e90b77b9 100644
--- a/java/org/apache/catalina/ssi/SSIEcho.java
+++ b/java/org/apache/catalina/ssi/SSIEcho.java
@@ -20,6 +20,7 @@ package org.apache.catalina.ssi;
import java.io.PrintWriter;
import org.apache.tomcat.util.res.StringManager;
+
/**
* Return the result associated with the supplied Server Variable.
*
@@ -38,8 +39,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();
@@ -60,8 +61,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;
}
@@ -71,8 +72,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 997ef08703..cbb01dc9c1 100644
--- a/java/org/apache/catalina/ssi/SSIExec.java
+++ b/java/org/apache/catalina/ssi/SSIExec.java
@@ -24,6 +24,7 @@ import java.util.StringTokenizer;
import org.apache.catalina.util.IOTools;
import org.apache.tomcat.util.res.StringManager;
+
/**
* Implements the Server-side #exec command
*
@@ -43,17 +44,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 {
@@ -67,7 +67,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);
}
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 57e62438a3..25a247f0a0 100644
--- a/java/org/apache/catalina/ssi/SSIFilter.java
+++ b/java/org/apache/catalina/ssi/SSIFilter.java
@@ -35,11 +35,12 @@ import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.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 extends GenericFilter {
@@ -53,8 +54,7 @@ public class SSIFilter extends GenericFilter {
/** 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;
@@ -80,17 +80,16 @@ public class SSIFilter extends GenericFilter {
allowExec = Boolean.parseBoolean(getInitParameter("allowExec"));
if (debug > 0) {
- getServletContext().log(
- "SSIFilter.init() SSI invoker started with 'debug'=" +
debug);
+ 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();
@@ -111,22 +110,17 @@ public class SSIFilter extends GenericFilter {
String encoding = res.getCharacterEncoding();
// set up SSI processing
- SSIExternalResolver ssiExternalResolver =
- new SSIServletExternalResolver(getServletContext(), req,
- res, isVirtualWebappRelative, debug, encoding);
- SSIProcessor ssiProcessor = new SSIProcessor(ssiExternalResolver,
- debug, allowExec);
+ SSIExternalResolver ssiExternalResolver = new
SSIServletExternalResolver(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();
@@ -134,16 +128,14 @@ public class SSIFilter extends GenericFilter {
// 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 17afc5ef4d..ff14afd180 100644
--- a/java/org/apache/catalina/ssi/SSIFlastmod.java
+++ b/java/org/apache/catalina/ssi/SSIFlastmod.java
@@ -34,25 +34,23 @@ import org.apache.tomcat.util.res.StringManager;
*/
public final class SSIFlastmod implements SSICommand {
private static final StringManager sm =
StringManager.getManager(SSIFlastmod.class);
+
/**
* @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));
diff --git a/java/org/apache/catalina/ssi/SSIFsize.java
b/java/org/apache/catalina/ssi/SSIFsize.java
index 59a2ba9bb3..cc03b85fc6 100644
--- a/java/org/apache/catalina/ssi/SSIFsize.java
+++ b/java/org/apache/catalina/ssi/SSIFsize.java
@@ -22,6 +22,7 @@ import java.io.PrintWriter;
import java.text.DecimalFormat;
import org.apache.tomcat.util.res.StringManager;
+
/**
* Implements the Server-side #fsize command
*
@@ -40,23 +41,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 {
@@ -114,10 +111,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 b8e035bb45..b1eb84b029 100644
--- a/java/org/apache/catalina/ssi/SSIInclude.java
+++ b/java/org/apache/catalina/ssi/SSIInclude.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import org.apache.tomcat.util.res.StringManager;
+
/**
* Implements the Server-side #include command
*
@@ -31,27 +32,24 @@ import org.apache.tomcat.util.res.StringManager;
*/
public final class SSIInclude implements SSICommand {
private static final StringManager sm =
StringManager.getManager(SSIInclude.class);
+
/**
* @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(sm.getString("ssiCommand.invalidAttribute", paramName));
diff --git a/java/org/apache/catalina/ssi/SSIMediator.java
b/java/org/apache/catalina/ssi/SSIMediator.java
index 82ae5c5e35..e7c4c5737f 100644
--- a/java/org/apache/catalina/ssi/SSIMediator.java
+++ b/java/org/apache/catalina/ssi/SSIMediator.java
@@ -32,8 +32,7 @@ import org.apache.tomcat.util.res.StringManager;
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
@@ -60,11 +59,10 @@ public class SSIMediator {
protected final long lastModifiedDate;
protected Strftime strftime;
protected final SSIConditionalState conditionalState = new
SSIConditionalState();
- protected int lastMatchCount = 0;
+ protected int lastMatchCount = 0;
- public SSIMediator(SSIExternalResolver ssiExternalResolver,
- long lastModifiedDate) {
+ public SSIMediator(SSIExternalResolver ssiExternalResolver, long
lastModifiedDate) {
this.ssiExternalResolver = ssiExternalResolver;
this.lastModifiedDate = lastModifiedDate;
setConfigTimeFmt(DEFAULT_CONFIG_TIME_FMT, true);
@@ -84,9 +82,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);
}
@@ -118,14 +117,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
variableNames.removeIf(this::isNameReserved);
return variableNames;
}
@@ -136,8 +133,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);
}
@@ -168,14 +164,11 @@ 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
- // 'built-in'
- // value
+ // 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);
@@ -186,14 +179,14 @@ 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) {
- // If it has no references or HTML entities then no work
- // need to be done
+ // If it has no references or HTML entities then no work need to be
done
if (val.indexOf('$') < 0 && val.indexOf('&') < 0) {
return val;
}
@@ -209,8 +202,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("&#");
@@ -265,8 +257,7 @@ public class SSIMediator {
}
// Replace the var name with its value
sb.replace(start, end, value);
- // Start searching for the next $ after the value
- // that was just substituted.
+ // Start searching for the next $ after the value that was just
substituted.
i = start + value.length();
}
return sb.toString();
@@ -276,9 +267,7 @@ public class SSIMediator {
protected String formatDate(Date date, TimeZone timeZone) {
String retVal;
if (timeZone != null) {
- //we temporarily change strftime. Since SSIMediator is inherently
- // single-threaded, this
- //isn't a problem
+ // we temporarily change strftime. Since SSIMediator is inherently
single-threaded, this isn't a problem
TimeZone oldTimeZone = strftime.getTimeZone();
strftime.setTimeZone(timeZone);
retVal = strftime.format(date);
@@ -299,7 +288,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(sm.getString("ssiMediator.unknownEncoding", encoding));
}
return retVal;
@@ -317,32 +306,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);
}
}
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..64a175a954 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) {
diff --git a/java/org/apache/catalina/ssi/SSIServlet.java
b/java/org/apache/catalina/ssi/SSIServlet.java
index c77ffaac4a..3c9c5e0d7d 100644
--- a/java/org/apache/catalina/ssi/SSIServlet.java
+++ b/java/org/apache/catalina/ssi/SSIServlet.java
@@ -32,9 +32,9 @@ import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.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);
return;
}
@@ -180,20 +165,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) {
@@ -217,8 +198,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 12cc6ad2dd..386a138353 100644
--- a/java/org/apache/catalina/ssi/SSIServletExternalResolver.java
+++ b/java/org/apache/catalina/ssi/SSIServletExternalResolver.java
@@ -48,16 +48,12 @@ import org.apache.tomcat.util.res.StringManager;
*/
public class SSIServletExternalResolver implements SSIExternalResolver {
private static final StringManager sm =
StringManager.getManager(SSIServletExternalResolver.class);
- 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;
@@ -65,8 +61,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;
@@ -79,9 +74,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 {
@@ -116,8 +112,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;
@@ -131,8 +126,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.");
}
@@ -165,12 +159,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) {
@@ -204,27 +197,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;
@@ -243,7 +231,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;
@@ -252,11 +240,10 @@ 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) {
- requestCharset =
((Request)req).getCoyoteRequest().getCharsetHolder().getCharset();
- Connector connector =
((Request)req).getConnector();
+ requestCharset = ((Request)
req).getCoyoteRequest().getCharsetHolder().getCharset();
+ Connector connector = ((Request)
req).getConnector();
uriCharset = connector.getURICharset();
useBodyEncodingForURI =
connector.getUseBodyEncodingForURI();
}
@@ -277,7 +264,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")) {
@@ -285,28 +272,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")) {
@@ -335,7 +319,7 @@ public class SSIServletExternalResolver implements
SSIExternalResolver {
if (requiredParts != nameParts.length) {
return null;
}
- return retVal;
+ return retVal;
}
@Override
@@ -357,15 +341,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());
}
@@ -388,27 +371,25 @@ public class SSIServletExternalResolver implements
SSIExternalResolver {
}
- protected ServletContextAndPath getServletContextAndPathFromNonVirtualPath(
- String nonVirtualPath) throws IOException {
+ protected ServletContextAndPath
getServletContextAndPathFromNonVirtualPath(String nonVirtualPath)
+ throws IOException {
if (nonVirtualPath.startsWith("/") || nonVirtualPath.startsWith("\\"))
{
throw new
IOException(sm.getString("ssiServletExternalResolver.absoluteNonVirtualPath",
nonVirtualPath));
}
if (nonVirtualPath.contains("../")) {
- throw new
IOException(sm.getString("ssiServletExternalResolver.pathTraversalNonVirtualPath",
nonVirtualPath));
+ throw new IOException(
+
sm.getString("ssiServletExternalResolver.pathTraversalNonVirtualPath",
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);
@@ -420,10 +401,8 @@ public class SSIServletExternalResolver implements
SSIExternalResolver {
if (normContext == null) {
throw new
IOException(sm.getString("ssiServletExternalResolver.noContext", 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);
return new ServletContextAndPath(normContext, noContext);
@@ -433,25 +412,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);
@@ -462,10 +435,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);
@@ -478,8 +449,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);
@@ -504,15 +474,14 @@ 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);
@@ -522,23 +491,22 @@ public class SSIServletExternalResolver implements
SSIExternalResolver {
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(sm.getString("ssiServletExternalResolver.noFile", path));
}
@@ -553,8 +521,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 b8c28afa82..f664c41718 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 3baedb2958..8817e66899 100644
--- a/java/org/apache/catalina/ssi/SSISet.java
+++ b/java/org/apache/catalina/ssi/SSISet.java
@@ -20,6 +20,7 @@ package org.apache.catalina.ssi;
import java.io.PrintWriter;
import org.apache.tomcat.util.res.StringManager;
+
/**
* Implements the Server-side #set command
*
@@ -29,13 +30,13 @@ import org.apache.tomcat.util.res.StringManager;
*/
public class SSISet implements SSICommand {
private static final StringManager sm =
StringManager.getManager(SSISet.class);
+
/**
* @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;
@@ -46,10 +47,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(sm.getString("ssiSet.noVariable"));
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: [email protected]
For additional commands, e-mail: [email protected]