You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ds...@apache.org on 2002/11/24 07:22:37 UTC
cvs commit: jakarta-tomcat-4.0/tester/web/golden SSIVarSub06.txt SSIVarSub01.txt SSIVarSub04.txt SSIVarSub05.txt
dsandberg 2002/11/23 22:22:37
Modified: catalina/src/share/org/apache/catalina/ssi SSIConfig.java
SSIExec.java SSIFlastmod.java SSIFsize.java
SSIInclude.java SSIMediator.java SSISet.java
tester/src/bin tester.xml
tester/web SSIConditional03.shtml SSIVarSub05.shtml
tester/web/golden SSIVarSub01.txt SSIVarSub04.txt
SSIVarSub05.txt
Added: tester/web/golden SSIVarSub06.txt
Log:
Added back Paul Speed's variable substitution SSI enhancement. Updated code/regression tests to better emulate Apache SSI.
Revision Changes Path
1.2 +8 -7 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSIConfig.java
Index: SSIConfig.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSIConfig.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SSIConfig.java 24 May 2002 04:38:58 -0000 1.1
+++ SSIConfig.java 24 Nov 2002 06:22:36 -0000 1.2
@@ -87,13 +87,14 @@
for(int i=0;i<paramNames.length;i++) {
String paramName = paramNames[i];
String paramValue = paramValues[i];
+ String substitutedValue = ssiMediator.substituteVariables( paramValue );
if ( paramName.equalsIgnoreCase("errmsg") ) {
- ssiMediator.setConfigErrMsg( paramValue );
+ ssiMediator.setConfigErrMsg( substitutedValue );
} else if ( paramName.equalsIgnoreCase("sizefmt") ) {
- ssiMediator.setConfigSizeFmt( paramValue );
+ ssiMediator.setConfigSizeFmt( substitutedValue );
} else if ( paramName.equalsIgnoreCase("timefmt") ) {
- ssiMediator.setConfigTimeFmt( paramValue );
+ 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
1.2 +9 -8 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSIExec.java
Index: SSIExec.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSIExec.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SSIExec.java 24 May 2002 04:38:58 -0000 1.1
+++ SSIExec.java 24 Nov 2002 06:22:36 -0000 1.2
@@ -108,14 +108,15 @@
String configErrMsg = ssiMediator.getConfigErrMsg();
String paramName = paramNames[0];
String paramValue = paramValues[0];
+ String substitutedValue = ssiMediator.substituteVariables( paramValue );
if ( paramName.equalsIgnoreCase("cgi") ) {
- ssiInclude.process( ssiMediator, new String[] {"virtual"}, new String[] {paramValue}, writer );
+ ssiInclude.process( ssiMediator, new String[] {"virtual"}, new String[] {substitutedValue}, writer );
} else if ( paramName.equalsIgnoreCase("cmd") ) {
boolean foundProgram = false;
try {
Runtime rt = Runtime.getRuntime();
- Process proc = rt.exec( paramValue );
+ Process proc = rt.exec( substitutedValue );
foundProgram = true;
BufferedReader stdOutReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
@@ -126,13 +127,13 @@
IOTools.flow( stdOutReader, writer, buf );
proc.waitFor();
} catch ( InterruptedException e ) {
- ssiMediator.log( "Couldn't exec file: " + paramValue, e );
+ ssiMediator.log( "Couldn't exec file: " + substitutedValue, e );
writer.write( configErrMsg );
} catch ( IOException e ) {
if ( !foundProgram ) {
//apache doesn't output an error message if it can't find a program
}
- ssiMediator.log( "Couldn't exec file: " + paramValue, e );
+ ssiMediator.log( "Couldn't exec file: " + substitutedValue, e );
}
}
}
1.2 +7 -6 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSIFlastmod.java
Index: SSIFlastmod.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSIFlastmod.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SSIFlastmod.java 24 May 2002 04:38:58 -0000 1.1
+++ SSIFlastmod.java 24 Nov 2002 06:22:36 -0000 1.2
@@ -93,12 +93,13 @@
for(int i=0;i<paramNames.length;i++) {
String paramName = paramNames[i];
String paramValue = paramValues[i];
+ String substitutedValue = ssiMediator.substituteVariables( paramValue );
try {
if ( paramName.equalsIgnoreCase("file") ||
paramName.equalsIgnoreCase("virtual") ) {
boolean virtual = paramName.equalsIgnoreCase("virtual");
- long lastModified = ssiMediator.getFileLastModified( paramValue, virtual );
+ long lastModified = ssiMediator.getFileLastModified( substitutedValue, virtual );
Date date = new Date( lastModified );
String configTimeFmt = ssiMediator.getConfigTimeFmt();
writer.write( formatDate(date, configTimeFmt ) );
@@ -107,7 +108,7 @@
writer.write( configErrMsg );
}
} catch ( IOException e ) {
- ssiMediator.log("#flastmod--Couldn't get last modified for file: " + paramValue, e );
+ ssiMediator.log("#flastmod--Couldn't get last modified for file: " + substitutedValue, e );
writer.write( configErrMsg );
}
}
1.3 +7 -6 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSIFsize.java
Index: SSIFsize.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSIFsize.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SSIFsize.java 5 Jun 2002 19:09:17 -0000 1.2
+++ SSIFsize.java 24 Nov 2002 06:22:36 -0000 1.3
@@ -91,12 +91,13 @@
for(int i=0;i<paramNames.length;i++) {
String paramName = paramNames[i];
String paramValue = paramValues[i];
+ String substitutedValue = ssiMediator.substituteVariables( paramValue );
try {
if ( paramName.equalsIgnoreCase("file") ||
paramName.equalsIgnoreCase("virtual") ) {
boolean virtual = paramName.equalsIgnoreCase("virtual");
- long size = ssiMediator.getFileSize( paramValue, virtual );
+ long size = ssiMediator.getFileSize( substitutedValue, virtual );
String configSizeFmt = ssiMediator.getConfigSizeFmt();
writer.write( formatSize(size, configSizeFmt ) );
} else {
@@ -104,7 +105,7 @@
writer.write( configErrMsg );
}
} catch ( IOException e ) {
- ssiMediator.log("#fsize--Couldn't get size for file: " + paramValue, e );
+ ssiMediator.log("#fsize--Couldn't get size for file: " + substitutedValue, e );
writer.write( configErrMsg );
}
}
1.2 +7 -6 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSIInclude.java
Index: SSIInclude.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSIInclude.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SSIInclude.java 24 May 2002 04:38:58 -0000 1.1
+++ SSIInclude.java 24 Nov 2002 06:22:36 -0000 1.2
@@ -92,19 +92,20 @@
for ( int i=0; i < paramNames.length; i++ ) {
String paramName = paramNames[i];
String paramValue = paramValues[i];
+ String substitutedValue = ssiMediator.substituteVariables( paramValue );
try {
if ( paramName.equalsIgnoreCase("file") ||
paramName.equalsIgnoreCase("virtual") ) {
boolean virtual = paramName.equalsIgnoreCase("virtual");
- String text = ssiMediator.getFileText( paramValue, virtual );
+ String text = ssiMediator.getFileText( substitutedValue, virtual );
writer.write( text );
} else {
ssiMediator.log("#include--Invalid attribute: " + paramName );
writer.write( configErrMsg );
}
} catch ( IOException e ) {
- ssiMediator.log("#include--Couldn't include file: " + paramValue, e );
+ ssiMediator.log("#include--Couldn't include file: " + substitutedValue, e );
writer.write( configErrMsg );
}
}
1.2 +77 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSIMediator.java
Index: SSIMediator.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSIMediator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SSIMediator.java 24 May 2002 04:38:58 -0000 1.1
+++ SSIMediator.java 24 Nov 2002 06:22:36 -0000 1.2
@@ -228,6 +228,79 @@
return variableValue;
}
+ /**
+ * Applies variable substitution to the specified String and
+ * returns the new resolved string.
+ */
+ public String substituteVariables( String val ) {
+
+ // If it has no variable references then no work
+ // need to be done
+ if (val.indexOf( '$' ) < 0)
+ return val;
+
+ StringBuffer sb = new StringBuffer( val );
+ for (int i = 0; i < sb.length();) {
+
+ // Find the next $
+ for (; i < sb.length(); i++) {
+ if (sb.charAt(i) == '$') {
+ i++;
+ break;
+ }
+ }
+
+ if (i == sb.length())
+ break;
+
+ // Check to see if the $ is escaped
+ if (i > 1 && sb.charAt(i-2) == '\\') {
+ sb.deleteCharAt(i-2);
+ i--;
+ continue;
+ }
+
+ int nameStart = i;
+ int start = i - 1;
+ int end = -1;
+ int nameEnd = -1;
+ char endChar = ' ';
+
+ // Check for {} wrapped var
+ if (sb.charAt(i) == '{') {
+ nameStart++;
+ endChar = '}';
+ }
+
+ // Find the end of the var reference
+ for (; i < sb.length(); i++) {
+ if (sb.charAt(i) == endChar)
+ break;
+ }
+ end = i;
+ nameEnd = end;
+
+ if (endChar == '}')
+ end++;
+
+ // We should now have enough to extract the var name
+ String varName = sb.substring( nameStart, nameEnd );
+
+ String value = getVariableValue( varName );
+ if (value == null)
+ value = "";
+
+ // Replace the var name with its value
+ sb.replace( start, end, value );
+
+ // Start searching for the next $ after the value
+ // that was just substituted.
+ i = start + value.length();
+ }
+
+ return sb.toString();
+ }
+
protected String formatDate( Date date, TimeZone timeZone ) {
String retVal;
1.2 +6 -5 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSISet.java
Index: SSISet.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ssi/SSISet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SSISet.java 24 May 2002 04:38:58 -0000 1.1
+++ SSISet.java 24 Nov 2002 06:22:36 -0000 1.2
@@ -92,7 +92,8 @@
variableName = paramValue;
} else if ( paramName.equalsIgnoreCase("value") ) {
if ( variableName != null ) {
- ssiMediator.setVariableValue( variableName, paramValue );
+ String substitutedValue = ssiMediator.substituteVariables( paramValue );
+ ssiMediator.setVariableValue( variableName, substitutedValue );
} else {
ssiMediator.log("#set--no variable specified");
writer.write( errorMessage );
1.84 +24 -0 jakarta-tomcat-4.0/tester/src/bin/tester.xml
Index: tester.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/src/bin/tester.xml,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- tester.xml 14 Mar 2002 20:41:38 -0000 1.83
+++ tester.xml 24 Nov 2002 06:22:36 -0000 1.84
@@ -1848,6 +1848,30 @@
request="${context.path}/SSIFsize08.shtml" debug="${debug}"
golden="${golden.path}/SSIFsize02.txt"/>
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/SSIVarSub01.shtml" debug="${debug}"
+ golden="${golden.path}/SSIVarSub01.txt"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/SSIVarSub02.shtml" debug="${debug}"
+ golden="${golden.path}/SSIVarSub02.txt"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/SSIVarSub03.shtml" debug="${debug}"
+ golden="${golden.path}/SSIVarSub03.txt"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/SSIVarSub04.shtml" debug="${debug}"
+ golden="${golden.path}/SSIVarSub04.txt"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/SSIVarSub05.shtml" debug="${debug}"
+ golden="${golden.path}/SSIVarSub05.txt"/>
+
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/SSIVarSub06.shtml" debug="${debug}"
+ golden="${golden.path}/SSIVarSub06.txt"/>
+
</target>
-->
1.2 +1 -1 jakarta-tomcat-4.0/tester/web/SSIConditional03.shtml
Index: SSIConditional03.shtml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/SSIConditional03.shtml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SSIConditional03.shtml 29 Nov 2001 03:52:27 -0000 1.1
+++ SSIConditional03.shtml 24 Nov 2002 06:22:36 -0000 1.2
@@ -1,6 +1,6 @@
Before if block.
<!--#set var="test" value="unquoted multi-word value" -->
-<!--#if expr="\"$test\" = unquoted multi-word value" -->
+<!--#if expr="$test = unquoted multi-word value" -->
test = "unquoted multi-word value"
<!--#else -->
test = not "unquoted multi-word value"
1.2 +0 -1 jakarta-tomcat-4.0/tester/web/SSIVarSub05.shtml
Index: SSIVarSub05.shtml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/SSIVarSub05.shtml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SSIVarSub05.shtml 29 Nov 2001 03:52:27 -0000 1.1
+++ SSIVarSub05.shtml 24 Nov 2002 06:22:36 -0000 1.2
@@ -2,4 +2,3 @@
<!--#set var="test2" value="value of test2" -->
<!--#set var="test3" value="${test}|${test2}" -->
<!--#echo var="test3" -->
-
1.2 +1 -1 jakarta-tomcat-4.0/tester/web/golden/SSIVarSub01.txt
Index: SSIVarSub01.txt
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/golden/SSIVarSub01.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SSIVarSub01.txt 29 Nov 2001 03:53:00 -0000 1.1
+++ SSIVarSub01.txt 24 Nov 2002 06:22:37 -0000 1.2
@@ -1,3 +1,3 @@
-/SSIVarSub01.shtml
+/tester/SSIVarSub01.shtml
1.2 +1 -1 jakarta-tomcat-4.0/tester/web/golden/SSIVarSub04.txt
Index: SSIVarSub04.txt
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/golden/SSIVarSub04.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SSIVarSub04.txt 29 Nov 2001 03:53:00 -0000 1.1
+++ SSIVarSub04.txt 24 Nov 2002 06:22:37 -0000 1.2
@@ -1,5 +1,5 @@
-value of test|value of test2
+value of test value of test2
1.2 +2 -1 jakarta-tomcat-4.0/tester/web/golden/SSIVarSub05.txt
Index: SSIVarSub05.txt
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/golden/SSIVarSub05.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SSIVarSub05.txt 29 Nov 2001 03:53:00 -0000 1.1
+++ SSIVarSub05.txt 24 Nov 2002 06:22:37 -0000 1.2
@@ -1,3 +1,4 @@
-value of test\${test2}
+
+value of test|value of test2
1.1 jakarta-tomcat-4.0/tester/web/golden/SSIVarSub06.txt
Index: SSIVarSub06.txt
===================================================================
value of test${test2}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>