tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi FileReference.java SsiCommandException.java SsiDispatcher.java SsiEnvironment.java SsiSet.java ResponseIncludeWrapper.java ServletOutputStreamWrapper.java SsiCommand.java SsiConfig.java SsiEcho.java SsiExec.java SsiFlastmod.java SsiFsize.java SsiInclude.java
Date Fri, 26 Oct 2001 19:35:24 GMT
bip         01/10/26 12:35:24

  Modified:    catalina/src/share/org/apache/catalina/util/ssi
                        ResponseIncludeWrapper.java
                        ServletOutputStreamWrapper.java SsiCommand.java
                        SsiConfig.java SsiEcho.java SsiExec.java
                        SsiFlastmod.java SsiFsize.java SsiInclude.java
  Added:       catalina/src/share/org/apache/catalina/util/ssi
                        FileReference.java SsiCommandException.java
                        SsiDispatcher.java SsiEnvironment.java SsiSet.java
  Log:
  Update and refactoring, also bugfixes.
  
  Submitted by: Paul Speed [pspeed <at> progeeks.com]
  
  Revision  Changes    Path
  1.4       +4 -4      jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/ResponseIncludeWrapper.java
  
  Index: ResponseIncludeWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/ResponseIncludeWrapper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ResponseIncludeWrapper.java	2001/07/22 20:25:15	1.3
  +++ ResponseIncludeWrapper.java	2001/10/26 19:35:23	1.4
  @@ -1,8 +1,8 @@
   /*
    * ResponseIncludeWrapper.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/ResponseIncludeWrapper.java,v 1.3 2001/07/22 20:25:15 pier Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/07/22 20:25:15 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/ResponseIncludeWrapper.java,v 1.4 2001/10/26 19:35:23 bip Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/10/26 19:35:23 $
    *
    * ====================================================================
    *
  @@ -74,7 +74,7 @@
    * A HttpServletResponseWrapper, used from <code>SsiInclude</code>
    *
    * @author Bip Thelin
  - * @version $Revision: 1.3 $, $Date: 2001/07/22 20:25:15 $
  + * @version $Revision: 1.4 $, $Date: 2001/10/26 19:35:23 $
    */
   public final class ResponseIncludeWrapper
       extends HttpServletResponseWrapper {
  
  
  
  1.3       +4 -4      jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/ServletOutputStreamWrapper.java
  
  Index: ServletOutputStreamWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/ServletOutputStreamWrapper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ServletOutputStreamWrapper.java	2001/04/26 22:58:49	1.2
  +++ ServletOutputStreamWrapper.java	2001/10/26 19:35:23	1.3
  @@ -1,8 +1,8 @@
   /*
    * ServletOutputStreamWrapper.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/ServletOutputStreamWrapper.java,v 1.2 2001/04/26 22:58:49 bip Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/04/26 22:58:49 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/ServletOutputStreamWrapper.java,v 1.3 2001/10/26 19:35:23 bip Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/10/26 19:35:23 $
    *
    * ====================================================================
    *
  @@ -74,7 +74,7 @@
    * from within <code>SsiInclude</code>
    *
    * @author Bip Thelin
  - * @version $Revision: 1.2 $, $Date: 2001/04/26 22:58:49 $
  + * @version $Revision: 1.3 $, $Date: 2001/10/26 19:35:23 $
    * @see ServletOutputStream
    */
   public final class ServletOutputStreamWrapper
  
  
  
  1.3       +24 -37    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiCommand.java
  
  Index: SsiCommand.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiCommand.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SsiCommand.java	2001/04/26 22:58:49	1.2
  +++ SsiCommand.java	2001/10/26 19:35:23	1.3
  @@ -1,8 +1,8 @@
   /*
    * SsiCommand.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiCommand.java,v 1.2 2001/04/26 22:58:49 bip Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/04/26 22:58:49 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiCommand.java,v 1.3 2001/10/26 19:35:23 bip Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/10/26 19:35:23 $
    *
    * ====================================================================
    *
  @@ -64,49 +64,36 @@
   
   package org.apache.catalina.util.ssi;
   
  +import java.io.IOException;
  +import javax.servlet.ServletOutputStream;
  +
   /**
    * Interface implemented by the different SsiCommands.
    *
    * @author Bip Thelin
  - * @version $Revision: 1.2 $, $Date: 2001/04/26 22:58:49 $
  + * @author Paul Speed
  + * @version $Revision: 1.3 $, $Date: 2001/10/26 19:35:23 $
    */
   public interface SsiCommand {
  -    /**
  -     * Get the processed result of this SsiCommands,
  -     * called after and only if <code>isPrintable()</code>
  -     * returns <code>true</code>
  -     *
  -     * @param strParamType The type of parameter
  -     * @param strParam The value of the parameter
  -     * @return result from this SsiCommand
  -     */
  -    public String getStream(String[] strParamType,
  -                            String[] strParam);
   
       /**
  -     * Process this request, used if <code>isPrintable()</code>
  -     * returns false
  +     *  Runs this command using the specified parameters.
        *
  -     * @param strParamType The type of parameter
  -     * @param strParam The value of the parameter
  +     *  @param cmdName  The name that was used to lookup this
  +     *                  command instance.
  +     *  @param argNames String array containing the parameter
  +     *                  names for the command.
  +     *  @param argVals  String array containing the paramater
  +     *                  values for the command.
  +     *  @param ssiEnv   The environment to use for command
  +     *                  execution.
  +     *  @param out      A convenient place for commands to
  +     *                  write their output.
        */
  -    public void process(String[] strParamType,
  -                        String[] strParam);
  +    public void execute( String cmdName, String[] argNames,
  +                         String[] argVals, SsiEnvironment ssiEnv,
  +                         ServletOutputStream out )
  +                                    throws IOException,
  +                                           SsiCommandException;
   
  -    /**
  -     * Called before <code>getStream()</code> and
  -     * <code>process()</code>. Return <code>true</code>
  -     * if this SsiCommand provide an output else <code>false</code>
  -     *
  -     * @return boolean result
  -     */
  -    public boolean isPrintable();
  -
  -    /**
  -     * Return <code>true</code> if this SsiCommand
  -     * has been modified since the last request.
  -     *
  -     * @return a value of type 'boolean'
  -     */
  -    public boolean isModified();
   }
  
  
  
  1.4       +39 -121   jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiConfig.java
  
  Index: SsiConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiConfig.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SsiConfig.java	2001/07/22 20:25:15	1.3
  +++ SsiConfig.java	2001/10/26 19:35:23	1.4
  @@ -1,8 +1,8 @@
   /*
    * SsiConfig.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiConfig.java,v 1.3 2001/07/22 20:25:15 pier Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/07/22 20:25:15 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiConfig.java,v 1.4 2001/10/26 19:35:23 bip Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/10/26 19:35:23 $
    *
    * ====================================================================
    *
  @@ -66,37 +66,19 @@
   
   import java.util.Properties;
   
  +import javax.servlet.ServletOutputStream;
  +
   /**
    * Implementation of the SsiCommand config, example of usage:
    * &lt;!--#config sizefmt="abbrev" errmsg="An error occured!"--&gt;
    *
    * @author Bip Thelin
  - * @version $Revision: 1.3 $, $Date: 2001/07/22 20:25:15 $
  + * @author Paul Speed
  + * @version $Revision: 1.4 $, $Date: 2001/10/26 19:35:23 $
    */
  -public final class SsiConfig
  -    extends SsiMediator implements SsiCommand {
  -
  -    /**
  -     * Variable to hold if this SsiCommand modified or not
  -     */
  -    private boolean modified = false;
  +public final class SsiConfig implements SsiCommand {
   
       /**
  -     * Variable to hold the errmsg to return
  -     */
  -    private byte[] errmsg;
  -
  -    /**
  -     * Variable to hold which sizefmt to use
  -     */
  -    private String sizefmt;
  -
  -    /**
  -     * Variable to hold which timefmt to use
  -     */
  -    private String timefmt;
  -
  -    /**
        * Variable to hold the patterns for translation
        */
       private static Properties translate;
  @@ -131,95 +113,43 @@
           translate.put("z","z");
       }
   
  -    /**
  -     * Initialize this SsiCommand
  -     *
  -     */
  -    public SsiConfig() {
  -        init();
  -    }
  -
  -    /**
  -     * <code>process()</code> should be used since this SsiCommand
  -     * does not return anything.
  -     *
  -     * @param strParamType a value of type 'String[]'
  -     * @param strParam a value of type 'String[]'
  -     * @return a value of type 'String'
  -     */
  -    public String getStream(String[] strParamType, String[] strParam) {
  -        return "";
  -    }
  -
       /**
  -     * Process request.
  +     *  Runs this command using the specified parameters.
        *
  -     * @param strParamType a value of type 'String[]'
  -     * @param strParam a value of type 'String[]'
  -     */
  -    public final void process(String[] strParamType, String[] strParam) {
  -        modified = true;
  -
  -        for(int i=0;i<strParamType.length;i++) {
  -            if(strParamType[i].equals("errmsg"))
  -                errmsg = strParam[i].getBytes();
  -            else if(strParamType[i].equals("sizefmt"))
  -                sizefmt = strParam[i];
  -            else if(strParamType[i].equals("timefmt"))
  -                timefmt = convertFormat(strParam[i]);
  +     *  @param cmdName  The name that was used to lookup this
  +     *                  command instance.
  +     *  @param argNames String array containing the parameter
  +     *                  names for the command.
  +     *  @param argVals  String array containing the paramater
  +     *                  values for the command.
  +     *  @param ssiEnv   The environment to use for command
  +     *                  execution.
  +     *  @param out      A convenient place for commands to
  +     *                  write their output.
  +     */
  +    public void execute( String cmdName, String[] argNames,
  +                         String[] argVals, SsiEnvironment ssiEnv,
  +                         ServletOutputStream out )
  +                                    throws SsiCommandException {
  +
  +        // Set the configuration variables that we understand
  +        for (int i = 0; i < argNames.length; i++) {
  +            String name = argNames[i];
  +            String value = argVals[i];
  +            if ("errmsg".equals(name)) {
  +                ssiEnv.setConfiguration( name,
  +                                         ssiEnv.substituteVariables(value) );
  +            } else if ("sizefmt".equals(name)) {
  +                ssiEnv.setConfiguration( name,
  +                                         ssiEnv.substituteVariables(value) );
  +            } else if ("timefmt".equals(name)) {
  +                value = convertFormat( ssiEnv.substituteVariables(value) );
  +                ssiEnv.setConfiguration( name, value );
  +            }
           }
       }
   
       /**
  -     * Return the current error message.
  -     *
  -     * @return a value of type 'byte[]'
  -     */
  -    public final byte[] getError() {
  -        return errmsg;
  -    }
  -
  -    /**
  -     * Return the current Size format.
  -     *
  -     * @return a value of type 'String'
  -     */
  -    public final String getSizefmt() {
  -        return sizefmt;
  -    }
  -
  -    /**
  -     * Return the current Time format.
  -     *
  -     * @return a value of type 'String'
  -     */
  -    public final String getTimefmt() {
  -        return timefmt;
  -    }
  -
  -    /**
  -     * Initialize, run once per page being parsed.
  -     *
  -     */
  -    public final void flush() {
  -        init();
  -    }
  -
  -    /**
  -     * Returns true if SSI Command does any output.
  -     *
  -     * @return a value of type 'boolean'
  -     */
  -    public final boolean isPrintable() { return false;}
  -
  -    /**
  -     * Return true if we're modified.
  -     *
  -     * @return a value of type 'boolean'
  -     */
  -    public final boolean isModified() { return modified; }
  -
  -    /**
        * Search the provided pattern and get the C standard
        * Date/Time formatting rules and convert them to the
        * Java equivalent.
  @@ -281,17 +211,5 @@
           String retCommand = translate.getProperty("".valueOf(c));
   
           return retCommand==null?"":retCommand;
  -    }
  -
  -    /**
  -     * Called from <code>flush</code> Initialize internal parameters
  -     * in their default setting.
  -     *
  -     */
  -    private void init() {
  -        errmsg =
  -            "[an error occurred while processing this directive]".getBytes();
  -        sizefmt = "abbrev";
  -        timefmt = "EEE, dd MMM yyyyy HH:mm:ss z";
       }
   }
  
  
  
  1.3       +31 -44    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiEcho.java
  
  Index: SsiEcho.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiEcho.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SsiEcho.java	2001/04/26 22:58:49	1.2
  +++ SsiEcho.java	2001/10/26 19:35:23	1.3
  @@ -1,8 +1,8 @@
   /*
    * SsiEcho.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiEcho.java,v 1.2 2001/04/26 22:58:49 bip Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/04/26 22:58:49 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiEcho.java,v 1.3 2001/10/26 19:35:23 bip Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/10/26 19:35:23 $
    *
    * ====================================================================
    *
  @@ -64,55 +64,42 @@
   
   package org.apache.catalina.util.ssi;
   
  +import java.io.IOException;
  +import javax.servlet.ServletOutputStream;
  +
   /**
  - * Return the result associated with the supplied Server Variable.
  + * Writes the variable value to the servlet stream.
    *
    * @author Bip Thelin
  - * @version $Revision: 1.2 $, $Date: 2001/04/26 22:58:49 $
  + * @author Paul Speed
  + * @version $Revision: 1.3 $, $Date: 2001/10/26 19:35:23 $
    */
  -public final class SsiEcho
  -    extends SsiMediator implements SsiCommand {
  -
  -    /**
  -     * Get the value associated with this parameter
  -     *
  -     * @param strParamType The parameter type
  -     * @param strParam The value, only "var" accepted
  -     * @return a value The computed result
  -     */
  -    public final String getStream(String[] strParamType,
  -                                  String[] strParam) {
  -        String retString;
  -
  -        if(strParamType[0].equals("var"))
  -            retString = super.getServerVariable(strParam[0]);
  -        else
  -            retString = new String(super.getError());
  -
  -        return retString;
  -    }
  +public final class SsiEcho implements SsiCommand {
   
       /**
  -     * Not used since this SsiCommand return a stream, use
  -     * <code>getStream()</code> instead.
  +     *  Runs this command using the specified parameters.
        *
  -     * @param strParamType a value of type 'String[]'
  -     * @param strParam a value of type 'String[]'
  +     *  @param cmdName  The name that was used to lookup this
  +     *                  command instance.
  +     *  @param argNames String array containing the parameter
  +     *                  names for the command.
  +     *  @param argVals  String array containing the paramater
  +     *                  values for the command.
  +     *  @param ssiEnv   The environment to use for command
  +     *                  execution.
  +     *  @param out      A convenient place for commands to
  +     *                  write their output.
        */
  -    public final void process(String[] strParamType, String[] strParam) {}
  +    public void execute( String cmdName, String[] argNames,
  +                         String[] argVals, SsiEnvironment ssiEnv,
  +                         ServletOutputStream out )
  +                                    throws IOException,
  +                                           SsiCommandException {
  +        if (!"var".equals(argNames[0]))
  +            throw new SsiCommandException( "Unknown parameter:" + argNames[0] );
   
  -    /**
  -     * Returns <code>true</code> this SsiCommand is always prnitable
  -     * and should therefore be accsessed through <code>getStream()</code>
  -     *
  -     * @return a value of type 'boolean'
  -     */
  -    public final boolean isPrintable() { return true; }
  +        String val = ssiEnv.getVariable(argVals[0]);
   
  -    /**
  -     * Returns <code>false</code>, this SsiCommands is never buffered.
  -     *
  -     * @return a value of type 'boolean'
  -     */
  -    public final boolean isModified() { return false; }
  +        out.print( (val==null)?"(none)":val );
  +    }
   }
  
  
  
  1.4       +96 -72    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiExec.java
  
  Index: SsiExec.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiExec.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SsiExec.java	2001/07/22 20:25:15	1.3
  +++ SsiExec.java	2001/10/26 19:35:23	1.4
  @@ -1,8 +1,8 @@
   /*
    * SsiExec.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiExec.java,v 1.3 2001/07/22 20:25:15 pier Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/07/22 20:25:15 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiExec.java,v 1.4 2001/10/26 19:35:23 bip Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/10/26 19:35:23 $
    *
    * ====================================================================
    *
  @@ -74,95 +74,119 @@
   import java.io.InputStream;
   import java.net.MalformedURLException;
   import java.net.URL;
  -import javax.servlet.ServletException;
  -import javax.servlet.ServletContext;
   import javax.servlet.ServletOutputStream;
  -import javax.servlet.RequestDispatcher;
   
   /**
    * @author Bip Thelin
    * @author Amy Roh
  - * @version $Revision: 1.3 $, $Date: 2001/07/22 20:25:15 $
  + * @author Paul Speed
  + * @version $Revision: 1.4 $, $Date: 2001/10/26 19:35:23 $
    *
    */
  -public final class SsiExec
  -    extends SsiMediator implements SsiCommand {
  +public final class SsiExec implements SsiCommand {
   
  -    public SsiExec() {}
  +    /**
  +     *  Runs this command using the specified parameters.
  +     *
  +     *  @param cmdName  The name that was used to lookup this
  +     *                  command instance.
  +     *  @param argNames String array containing the parameter
  +     *                  names for the command.
  +     *  @param argVals  String array containing the paramater
  +     *                  values for the command.
  +     *  @param ssiEnv   The environment to use for command
  +     *                  execution.
  +     *  @param out      A convenient place for commands to
  +     *                  write their output.
  +     */
  +    public void execute( String cmdName, String[] argNames,
  +                         String[] argVals, SsiEnvironment ssiEnv,
  +                         ServletOutputStream out )
  +                                    throws IOException,
  +                                           SsiCommandException {
  +
  +        if ("cgi".equals(argNames[0])) {
  +            String path = getCGIPath(argVals[0], ssiEnv.getContextPath());
  +            if (path == null)
  +                throw new SsiCommandException( "Invalid path:" + argVals[0] );
  +
  +            // Stream the CGI output back to the client
  +            URL u = new URL(path);
  +            InputStream istream = u.openStream();
  +            int i;
  +            while ((i = istream.read()) != -1) {
  +                out.write(i);
  +            }
  +        } else if ("cmd".equals(argNames[0])) {
  +            String path = getCommandPath(argVals[0]);
  +            if (path == null)
  +                throw new SsiCommandException( "Invalid path:" + argVals[0] );
  +
  +            BufferedReader commandsStdOut = null;
  +            BufferedReader commandsStdErr = null;
  +            BufferedOutputStream commandsStdIn = null;
  +            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
  +            //byte[] bBuf = new byte[1024];
  +            char[] cBuf = new char[1024];
  +            int bufRead = -1;
  +
  +            Runtime rt = null;
  +            Process proc = null;
  +
  +            try {
  +                rt = Runtime.getRuntime();
  +                proc = rt.exec(path);
   
  -    public final String getStream(String[] strParamType,
  -                                  String[] strParam) {
  +                commandsStdIn = new BufferedOutputStream(proc.getOutputStream());
  +                //boolean isRunning = true;
  +                commandsStdOut = new BufferedReader(new InputStreamReader(proc.getInputStream()));
  +                commandsStdErr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
  +                BufferedWriter servletContainerStdout = null;
   
  -        String retString = "";
  -        String path = "";
  -
  -        if(strParamType[0].equals("cgi")) {
  -            path = super.getCGIPath(strParam[0]);
  -            if (path != null) {
  -                try {
  -                    URL url = new URL(path);
  -                    InputStream istream = url.openStream();
  -                    int i = istream.read();
  -                    while (i != -1) {
  -                        super.out.write(i);
  -                        i = istream.read();
  -                    }
  -                } catch (IOException e) {
  -                    retString = new String(super.getError());
  +                while ((bufRead = commandsStdErr.read(cBuf)) != -1) {
  +                    writer.write(cBuf, 0, bufRead);
                   }
  -            } else {
  -                retString = new String(super.getError());
  -            }
  -        } else if(strParamType[0].equals("cmd"))
   
  -            path = super.getCommandPath(strParam[0]);
  +                cBuf = new char[1024];
  +                while ((bufRead = commandsStdOut.read(cBuf)) != -1) {
  +                    writer.write(cBuf, 0, bufRead);
  +                }
   
  -            if (path!=null) {
  -                    BufferedReader commandsStdOut = null;
  -                    BufferedReader commandsStdErr = null;
  -                    BufferedOutputStream commandsStdIn = null;
  -                BufferedWriter out = new BufferedWriter(new OutputStreamWriter(super.out));
  -                    //byte[] bBuf = new byte[1024];
  -                    char[] cBuf = new char[1024];
  -                    int bufRead = -1;
  -
  -                Runtime rt = null;
  -                Process proc = null;
  -
  -                try {
  -                    rt = Runtime.getRuntime();
  -                    proc = rt.exec(path);
  +                out.flush();
   
  -                commandsStdIn = new BufferedOutputStream(proc.getOutputStream());
  -                    //boolean isRunning = true;
  -                    commandsStdOut = new BufferedReader(new InputStreamReader(proc.getInputStream()));
  -                    commandsStdErr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
  -                    BufferedWriter servletContainerStdout = null;
  -
  -                        while ((bufRead = commandsStdErr.read(cBuf)) != -1) {
  -                                out.write(cBuf, 0, bufRead);
  -                            }
  -
  -                    cBuf = new char[1024];
  -                    while ((bufRead = commandsStdOut.read(cBuf)) != -1) {
  -                                out.write(cBuf, 0, bufRead);
  -                            }
  +                proc.exitValue();
  +            } catch (IOException ex) {
  +            }
  +        }
  +    }
   
  -                        super.out.flush();
  +    protected String getCGIPath( String path, String contextPath ) {
   
  -                        proc.exitValue();
  -                } catch (IOException ex) {
  -                }
  +        String cgibinStr = "/cgi-bin/";
  +
  +        if (path == null)
  +            return null;
  +
  +        if (!path.startsWith(cgibinStr)) {
  +            return null;
           } else {
  -            retString = new String(super.getError());
  +            //normalized = normalized.substring(1, cgibinStr.length());
  +            //normalized = cgiPathPrefix + File.separator + normalized;
  +            path = "http://localhost:8080" + contextPath + path;
           }
  -
  -        return retString;
  +        return (path);
       }
  +
  +    protected String getCommandPath(String path) {
   
  -    public final void process(String[] strParamType, String[] strParam) {}
  +        String commandShellStr = "/bin/sh";
   
  -    public final boolean isPrintable() { return true; }
  +        if (path == null)
  +            return null;
   
  -    public final boolean isModified() { return false; }
  +        if (!path.startsWith("/"))
  +            path = "/" + path;
  +        path = commandShellStr + path;
  +        return (path);
  +    }
   }
  
  
  
  1.4       +39 -94    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiFlastmod.java
  
  Index: SsiFlastmod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiFlastmod.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SsiFlastmod.java	2001/07/22 20:25:15	1.3
  +++ SsiFlastmod.java	2001/10/26 19:35:23	1.4
  @@ -1,8 +1,8 @@
   /*
    * SsiFlastmod.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiFlastmod.java,v 1.3 2001/07/22 20:25:15 pier Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/07/22 20:25:15 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiFlastmod.java,v 1.4 2001/10/26 19:35:23 bip Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/10/26 19:35:23 $
    *
    * ====================================================================
    *
  @@ -69,109 +69,54 @@
   import java.net.URL;
   import java.net.MalformedURLException;
   import javax.servlet.ServletContext;
  +import javax.servlet.ServletOutputStream;
   
   /**
    * Get the last modified date for a file, the date is subject
    * of formatting.
    *
    * @author Bip Thelin
  - * @version $Revision: 1.3 $, $Date: 2001/07/22 20:25:15 $
  + * @author Paul Speed
  + * @version $Revision: 1.4 $, $Date: 2001/10/26 19:35:23 $
    */
  -public final class SsiFlastmod
  -    extends SsiMediator implements SsiCommand {
  +public final class SsiFlastmod implements SsiCommand {
   
       /**
  -     * Get the date of a file and format it correctly
  +     *  Runs this command using the specified parameters.
        *
  -     * @param strParamType The type of parameter
  -     * @param strParam The value of the parameter
  -     * @return The date of the file
  +     *  @param cmdName  The name that was used to lookup this
  +     *                  command instance.
  +     *  @param argNames String array containing the parameter
  +     *                  names for the command.
  +     *  @param argVals  String array containing the paramater
  +     *                  values for the command.
  +     *  @param ssiEnv   The environment to use for command
  +     *                  execution.
  +     *  @param out      A convenient place for commands to
  +     *                  write their output.
        */
  -    public final String getStream(String[] strParamType,
  -                                  String[] strParam) {
  -        String path = new String();
  -        long lastModified;
  -        String sLastModified = null;
  -        URL url = null;
  -
  -        if(strParamType[0].equals("file")) {
  -            path = super.getFilePath(strParam[0]);
  -        } else if(strParamType[0].equals("virtual")) {
  -            path = super.getVirtualPath(strParam[0]);
  -        }
  -
  -        try {
  -            url = super.servletContext.getResource(path);
  -            lastModified = url.openConnection().getLastModified();
  -        } catch (MalformedURLException e){
  -            lastModified = 0;
  -        } catch (IOException e) {
  -            lastModified = 0;
  -        } catch (NullPointerException e) {
  -            lastModified = 0;
  -        }
  -
  -        if(lastModified==0)
  -            sLastModified = (new String(super.getError()));
  -        else
  -            sLastModified = super.timefmt(new Date(lastModified));
  +    public void execute( String cmdName, String[] argNames,
  +                         String[] argVals, SsiEnvironment ssiEnv,
  +                         ServletOutputStream out )
  +                                    throws IOException,
  +                                           SsiCommandException {
  +        FileReference ref = null;
  +
  +        String value = ssiEnv.substituteVariables( argVals[0] );
  +
  +        if (argNames[0].equals("file"))
  +            ref = ssiEnv.getFileReference( value, false );
  +        else if (argNames[0].equals("virtual"))
  +            ref = ssiEnv.getFileReference( value, true );
  +
  +        if (ref == null)
  +            throw new SsiCommandException( "Path not found:" + value );
  +
  +        String lastMod = ssiEnv.getLastModified( ref );
  +        if (lastMod == null)
  +            throw new SsiCommandException( "Error retrieving mod time." );
   
  -        return sLastModified;
  +        out.print( lastMod );
       }
   
  -    /**
  -     * Get the date of a file and format it correctly
  -     *
  -     * @param path The path to the file
  -     * @return The Date to return
  -     */
  -    protected String getDate(String path) {
  -        long lastModified;
  -        String sLastModified = null;
  -        URL url = null;
  -
  -        path = super.getVirtualPath(path);
  -
  -        try {
  -            url = super.servletContext.getResource(path);
  -            lastModified = url.openConnection().getLastModified();
  -        } catch (MalformedURLException e){
  -            lastModified = 0;
  -        } catch (IOException e) {
  -            lastModified = 0;
  -        } catch (NullPointerException e) {
  -            lastModified = 0;
  -        }
  -
  -        if(lastModified==0)
  -            sLastModified = (new String(super.getError()));
  -        else
  -            sLastModified = super.timefmt(new Date(lastModified));
  -
  -        return sLastModified;
  -    }
  -
  -    /**
  -     * Not used since this SsiCommand return a stream, use
  -     * <code>getStream()</code> instead.
  -     *
  -     * @param strParamType a value of type 'String[]'
  -     * @param strParam a value of type 'String[]'
  -     */
  -    public final void process(String[] strParamType, String[] strParam) {}
  -
  -    /**
  -     * Returns <code>true</code> this SsiCommand is always prnitable
  -     * and should therefore be accsessed through <code>getStream()</code>
  -     *
  -     * @return a value of type 'boolean'
  -     */
  -    public final boolean isPrintable() { return true; }
  -
  -    /**
  -     * Returns <code>false</code>, this SsiCommands is never buffered.
  -     *
  -     * @return a value of type 'boolean'
  -     */
  -    public final boolean isModified() { return false; }
   }
  
  
  
  1.4       +42 -64    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiFsize.java
  
  Index: SsiFsize.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiFsize.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SsiFsize.java	2001/07/22 20:25:15	1.3
  +++ SsiFsize.java	2001/10/26 19:35:23	1.4
  @@ -1,8 +1,8 @@
   /*
    * SsiFsize.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiFsize.java,v 1.3 2001/07/22 20:25:15 pier Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/07/22 20:25:15 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiFsize.java,v 1.4 2001/10/26 19:35:23 bip Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/10/26 19:35:23 $
    *
    * ====================================================================
    *
  @@ -68,82 +68,60 @@
   import java.net.URL;
   import java.net.MalformedURLException;
   import javax.servlet.ServletContext;
  +import javax.servlet.ServletOutputStream;
   
   /**
    * Return the size of a given file, subject of formatting.
    *
    * @author Bip Thelin
  - * @version $Revision: 1.3 $, $Date: 2001/07/22 20:25:15 $
  + * @author Paul Speed
  + * @version $Revision: 1.4 $, $Date: 2001/10/26 19:35:23 $
    */
  -public final class SsiFsize
  -    extends SsiMediator implements SsiCommand {
  +public final class SsiFsize implements SsiCommand {
   
       /**
  -     * Figure out the length/size of a given file.
  +     *  Runs this command using the specified parameters.
        *
  -     * @param strParamType The parameter type
  -     * @param strParam The value, only "var" accepted
  -     * @return The result
  +     *  @param cmdName  The name that was used to lookup this
  +     *                  command instance.
  +     *  @param argNames String array containing the parameter
  +     *                  names for the command.
  +     *  @param argVals  String array containing the paramater
  +     *                  values for the command.
  +     *  @param ssiEnv   The environment to use for command
  +     *                  execution.
  +     *  @param out      A convenient place for commands to
  +     *                  write their output.
        */
  -    public final String getStream(String[] strParamType,
  -                                  String[] strParam) {
  -        String length = "";
  -        String retLength = "";
  -        String path = "";
  -        URL url = null;
  -        long lLength = -1;
  -
  -        if(strParamType[0].equals("file")) {
  -            path = super.getFilePath(strParam[0]);
  -        } else if(strParamType[0].equals("virtual")) {
  -            path = super.getVirtualPath(strParam[0]);
  -        }
  +    public void execute( String cmdName, String[] argNames,
  +                         String[] argVals, SsiEnvironment ssiEnv,
  +                         ServletOutputStream out )
  +                                    throws IOException,
  +                                           SsiCommandException {
  +        FileReference ref = null;
  +
  +        String value = ssiEnv.substituteVariables( argVals[0] );
  +
  +        if (argNames[0].equals("file"))
  +            ref = ssiEnv.getFileReference( value, false );
  +        else if (argNames[0].equals("virtual"))
  +            ref = ssiEnv.getFileReference( value, true );
  +
  +        if (ref == null)
  +            throw new SsiCommandException( "Path not found:" + value );
   
  +        long fileSize;
  +
           try {
  -            url = super.servletContext.getResource(path);
  -            lLength = url.openConnection().getContentLength();
  -            length = (new Long(lLength)).toString();
  -        } catch (MalformedURLException e){
  -            length = null;
  -        } catch (IOException e) {
  -            length = null;
  -        } catch (NullPointerException e) {
  -            length = null;
  +            URL u = ref.getResource();
  +            fileSize = u.openConnection().getContentLength();
  +        } catch (Exception e) {
  +            throw new SsiCommandException( e.toString() );
           }
  -
  -        if(length == null)
  -            retLength = (new String(super.getError()));
  -        else
  -            retLength =
  -                formatSize(length,
  -                           ((SsiConfig)super.getCommand("config")).getSizefmt());
   
  -        return retLength;
  +        out.print( formatSize(String.valueOf(fileSize),
  +                              ssiEnv.getConfiguration("sizefmt")) );
       }
  -
  -    /**
  -     * Not used since this SsiCommand return a stream, use
  -     * <code>getStream()</code> instead.
  -     *
  -     * @param strParamType a value of type 'String[]'
  -     * @param strParam a value of type 'String[]'
  -     */
  -    public final void process(String[] strParamType, String[] strParam) {}
  -
  -    /**
  -     * Returns <code>true</code> this SsiCommand is always prnitable
  -     * and should therefore be accsessed through <code>getStream()</code>
  -     *
  -     * @return a value of type 'boolean'
  -     */
  -    public final boolean isPrintable() { return true; }
  -
  -    /**
  -     * Returns <code>false</code>, this SsiCommands is never buffered.
  -     *
  -     * @return a value of type 'boolean'
  -     */
  -    public final boolean isModified() { return false; }
   
       //----------------- Private methods
   
  
  
  
  1.4       +41 -68    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiInclude.java
  
  Index: SsiInclude.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiInclude.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SsiInclude.java	2001/07/22 20:25:15	1.3
  +++ SsiInclude.java	2001/10/26 19:35:23	1.4
  @@ -1,8 +1,8 @@
   /*
    * SsiInclude.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiInclude.java,v 1.3 2001/07/22 20:25:15 pier Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/07/22 20:25:15 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiInclude.java,v 1.4 2001/10/26 19:35:23 bip Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/10/26 19:35:23 $
    *
    * ====================================================================
    *
  @@ -75,76 +75,49 @@
    * <code>RequestDispatcher.include().</code>
    *
    * @author Bip Thelin
  - * @version $Revision: 1.3 $, $Date: 2001/07/22 20:25:15 $
  + * @author Paul Speed
  + * @version $Revision: 1.4 $, $Date: 2001/10/26 19:35:23 $
    */
  -public final class SsiInclude
  -    extends SsiMediator implements SsiCommand {
  +public final class SsiInclude implements SsiCommand {
   
       /**
  -     * Get the stream from the included file.
  +     *  Runs this command using the specified parameters.
        *
  -     * @param strParamType The parameter type
  -     * @param strParam The file to include
  -     * @return The result from the include
  +     *  @param cmdName  The name that was used to lookup this
  +     *                  command instance.
  +     *  @param argNames String array containing the parameter
  +     *                  names for the command.
  +     *  @param argVals  String array containing the paramater
  +     *                  values for the command.
  +     *  @param ssiEnv   The environment to use for command
  +     *                  execution.
  +     *  @param out      A convenient place for commands to
  +     *                  write their output.
        */
  -    public final String getStream(String[] strParamType,
  -                                  String[] strParam) {
  -        String retString = "";
  -        String path = "";
  -
  -        if(strParamType[0].equals("file"))
  -            path = super.getFilePath(strParam[0]);
  -        else if(strParamType[0].equals("virtual"))
  -            path = super.getVirtualPath(strParam[0]);
  -
  -        if(path != null) {
  -            try {
  -                if(super.servletContext.getResource(path) != null) {
  -                    RequestDispatcher rd =
  -                        super.servletContext.getRequestDispatcher(path);
  -                    rd.include(super.req,
  -                               new ResponseIncludeWrapper(super.res,
  -                                                          (ServletOutputStream)super.out));
  -                } else{
  -                    retString = new String(super.getError());
  -                }
  -            } catch (IOException e) {
  -                retString = new String(super.getError());
  -            } catch (ServletException e) {
  -                retString = new String(super.getError());
  -            } catch (IllegalArgumentException e) {
  -                retString = new String(super.getError());
  -            } catch (NullPointerException e) {
  -                retString = new String(super.getError());
  -            }
  -        } else {
  -            retString = new String(super.getError());
  +    public void execute( String cmdName, String[] argNames,
  +                         String[] argVals, SsiEnvironment ssiEnv,
  +                         ServletOutputStream out )
  +                                    throws IOException,
  +                                           SsiCommandException {
  +        FileReference ref = null;
  +
  +        String value = ssiEnv.substituteVariables( argVals[0] );
  +
  +        if (argNames[0].equals("file"))
  +            ref = ssiEnv.getFileReference( value, false );
  +        else if (argNames[0].equals("virtual"))
  +            ref = ssiEnv.getFileReference( value, true );
  +
  +        if (ref == null)
  +            throw new SsiCommandException( "Path not found:" + value );
  +
  +        try {
  +            RequestDispatcher rd = ref.getRequestDispatcher();
  +            rd.include( ssiEnv.getRequest(),
  +                        new ResponseIncludeWrapper( ssiEnv.getResponse(),
  +                                                    out ) );
  +        } catch (Exception e) {
  +            throw new SsiCommandException( e.toString() );
           }
  -
  -        return retString;
       }
  -
  -    /**
  -     * Not used since this SsiCommand return a stream, use
  -     * <code>getStream()</code> instead.
  -     *
  -     * @param strParamType a value of type 'String[]'
  -     * @param strParam a value of type 'String[]'
  -     */
  -    public final void process(String[] strParamType, String[] strParam) {}
  -
  -    /**
  -     * Returns <code>true</code> this SsiCommand is always prnitable
  -     * and should therefore be accsessed through <code>getStream()</code>
  -     *
  -     * @return a value of type 'boolean'
  -     */
  -    public final boolean isPrintable() { return true; }
  -
  -    /**
  -     * Returns <code>false</code>, this SsiCommands is never buffered.
  -     *
  -     * @return a value of type 'boolean'
  -     */
  -    public final boolean isModified() { return false; }
   }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/FileReference.java
  
  Index: FileReference.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/FileReference.java,v 1.1 2001/10/26 19:35:23 bip Exp $
   * $Revision: 1.1 $
   * $Date: 2001/10/26 19:35:23 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.catalina.util.ssi;
  
  import java.net.URL;
  import java.net.MalformedURLException;
  
  import javax.servlet.ServletContext;
  import javax.servlet.RequestDispatcher;
  
  
  /**
   *  Contains the path and servlet context for a file.  This
   *  information can be used to retrieve the file as a resource
   *  or to retrieve a request dispatcher, etc..
   *
   *  @version   $Revision: 1.1 $, $Date: 2001/10/26 19:35:23 $
   *  @author    Paul Speed
   */
  public class FileReference {
  
      /**
       *  The normalized path of the file.
       */
      private String path;
  
      /**
       *  The servlet context to which the file is relative.
       */
      private ServletContext context;
  
      /**
       *  Creates a new file reference object containing the
       *  specified normalized path and context.
       */
      public FileReference( String path, ServletContext context ) {
          this.path = path;
          this.context = context;
      }
  
      /**
       *  Returns the URL object for this file reference.
       */
      public URL getResource() throws MalformedURLException {
          return context.getResource(path);
      }
  
      /**
       *  Returns a RequestDispatcher suitable for processing
       *  the referenced file.
       */
      public RequestDispatcher getRequestDispatcher() {
          return context.getRequestDispatcher(path);
      }
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiCommandException.java
  
  Index: SsiCommandException.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiCommandException.java,v 1.1 2001/10/26 19:35:23 bip Exp $
   * $Revision: 1.1 $
   * $Date: 2001/10/26 19:35:23 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.catalina.util.ssi;
  
  /**
   *  Exception thrown by SsiCommands if they have problems during
   *  execution.
   *
   *  @version   $Revision: 1.1 $, $Date: 2001/10/26 19:35:23 $
   *  @author    Paul Speed
   */
  public class SsiCommandException extends Exception {
  
      public SsiCommandException( String message ) {
          super( message );
      }
  
      public SsiCommandException() {
      }
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiDispatcher.java
  
  Index: SsiDispatcher.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiDispatcher.java,v 1.1 2001/10/26 19:35:23 bip Exp $
   * $Revision: 1.1 $
   * $Date: 2001/10/26 19:35:23 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.catalina.util.ssi;
  
  import java.io.IOException;
  import java.util.Hashtable;
  
  import javax.servlet.ServletOutputStream;
  
  /**
   *  Dispatcher class used to run SSI commands.  The idea is that
   *  each SsiInokerServlet instance will have its own SsiDispatcher
   *  and can therefore configure certain context-global settings.
   *
   *  @version   $Revision: 1.1 $, $Date: 2001/10/26 19:35:23 $
   *  @author    Paul Speed
   */
  public class SsiDispatcher {
  
      /**
       *  Determines how to treate unknown command references.
       */
      private boolean ignoreUnsupportedDirective = true;
  
      /**
       *  Contains the SSI command instances.  This is shared
       *  across all dispatcher instances.
       */
      private static Hashtable ssiCommands;
  
      /**
       *  Initialize the pool of SsiCommands.
       */
      static {
          ssiCommands = new Hashtable(6);
          ssiCommands.put("config", new SsiConfig());
          ssiCommands.put("include", new SsiInclude());
          ssiCommands.put("echo", new SsiEcho());
          ssiCommands.put("fsize", new SsiFsize());
          ssiCommands.put("flastmod", new SsiFlastmod());
          ssiCommands.put("exec", new SsiExec());
          ssiCommands.put("set", new SsiSet());
      }
  
      /**
       *  Set to true to ignore unknown commands.
       */
      public void setIgnoreUnsupportedDirective(boolean flag) {
          this.ignoreUnsupportedDirective = flag;
      }
  
      /**
       * Set to true to consider the webapp as root.
      public void setIsVirtualWebappRelative(boolean flag) {
          this.isVirtualWebappRelative = flag;
      }
  
      /**
       *  Returns true if the dispatcher ignores unknown commands.
       */
      public boolean ignoreUnsupportedDirective() {
          return ignoreUnsupportedDirective;
      }
  
      /**
       *  Runs the specified command using the specified arguments.
       *
       *  @param cmdName  The name of the command to run.
       *  @param argNames String array containing the parameter
       *                  names for the command.
       *  @param argVals  String array containing the paramater
       *                  values for the command.
       *  @param ssiEnv   The environment to use for command
       *                  execution.
       *  @param out      A convenient place for commands to
       *                  write their output.
       */
      public void runCommand( String cmdName,
                              String[] argNames,
                              String[] argVals,
                              SsiEnvironment ssiEnv,
                              ServletOutputStream out )
                                      throws IOException {
          // Lookup the command
          SsiCommand cmd = (SsiCommand)ssiCommands.get(cmdName);
          if (cmd == null) {
              if (!ignoreUnsupportedDirective)
                  out.print( ssiEnv.getConfiguration("errmsg") );
              return;
          }
  
          try {
              // Run the command
              cmd.execute( cmdName, argNames, argVals, ssiEnv, out );
          } catch (SsiCommandException e) {
              // Write the error
              out.print( ssiEnv.getConfiguration("errmsg") );
          }
      }
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiEnvironment.java
  
  Index: SsiEnvironment.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiEnvironment.java,v 1.1 2001/10/26 19:35:23 bip Exp $
   * $Revision: 1.1 $
   * $Date: 2001/10/26 19:35:23 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.catalina.util.ssi;
  
  import java.io.IOException;
  import java.net.URL;
  import java.net.MalformedURLException;
  import java.util.Date;
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import java.text.ParseException;
  import java.util.Hashtable;
  import java.util.TimeZone;
  
  import javax.servlet.ServletContext;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.catalina.util.DateTool;
  
  /**
   *  Contains the execution environment for SSI commands.  Nested
   *  SsiEnvironment instances are created for nested requests.  In
   *  these cases, most environment access will defer to the root
   *  environment.  The construct is provided for the few cases where
   *  nested environment would not be shared.  In any case,
   *  createEnvironmentForRequest() takes care of these details.
   *
   *  @version   $Revision: 1.1 $, $Date: 2001/10/26 19:35:23 $
   *  @author    Paul Speed
   */
  public class SsiEnvironment {
  
      /**
       *  The key used when storing the environment as a request
       *  attribute.
       */
      public static final String ATTR_SSI_ENVIRONMENT
                                      = "tomcat.ssi.environment";
  
      /**
       *  The parent SsiEnvironment instance, or null if this is a
       *  root.
       */
      private SsiEnvironment parent;
  
      /**
       *  The server variables for this SSI environment.
       */
      private Hashtable serverVariables;
  
      /**
       *  The SSI configuration for this environment.  Includes the
       *  time format, file size format, etc.
       */
      private Hashtable ssiConfig;
  
      /**
       *  The ServletContext associated with this environment.
       */
      private ServletContext servletContext;
  
      /**
       *  The context path for this environment.
       */
      private String contextPath;
  
      /**
       *  The path of the original request that created this environment.
       */
      private String requestPath;
  
      /**
       *  The location of the file pointed to be requestPath.  This
       *  is the requestPath minus anything after the last /.
       */
      private String location;
  
      /**
       *  True if virtual paths should be resolved relative to the webapp
       *  directory.
       */
      private boolean isVirtualWebappRelative;
  
      /**
       *  The request object for the request that created this environment.
       */
      private HttpServletRequest request;
  
      /**
       *  The response object for the request that created this environment.
       */
      private HttpServletResponse response;
  
      /**
       *  Set to true if output is temporarily disabled.
       */
      private boolean disableOutput;
  
      /**
       *  Used to track the number if "if" directives that have been
       *  encountered without yet seeing an "endif".
       */
      private int conditionalCount = 0;
  
      /**
       *  Used to track the number of nested conditional branches that
       *  have been taken.
       */
      private int branchCount = 0;
  
      /**
       *  Creates a new SsiEnvironment instance for the specified request.
       *  This method will create a new or nested instance as appropriate.
       *
       *  @param context  The ServletContext from which the environment will
       *                  be initialized.
       *  @param req      The HttpServletRequest from which the environment
       *                  will be initialized.
       *  @param path     The normalized path of the request.
       */
      public static SsiEnvironment createSsiEnvironment( ServletContext context,
                                                         HttpServletRequest req,
                                                         HttpServletResponse res,
                                                         String path ) {
  
          SsiEnvironment env = null;
  
          // Try to get a parent
          env = (SsiEnvironment)req.getAttribute( ATTR_SSI_ENVIRONMENT );
  
          if (env == null) {
              // Create a new root level environment
              env = new SsiEnvironment( context, req, res, path );
  
              // Only store root environments in the request
              req.setAttribute( ATTR_SSI_ENVIRONMENT, env );
          } else {
              // Create a nested environment
              env = new SsiEnvironment( env, context, req, res, path );
          }
  
          return env;
      }
  
  
      /**
       *  Constructs and initializes a new root-level SsiEnvironment for the
       *  specified request.
       *
       *  @param req The HttpServletRequest used to initialize the environment
       *             variables.
       *  @param path The normalized path of the request.
       */
      protected SsiEnvironment( ServletContext context,
                                HttpServletRequest req,
                                HttpServletResponse res,
                                String path ) {
  
          this.serverVariables = new Hashtable(17);
          this.ssiConfig = new Hashtable(3);
          this.servletContext = context;
          this.contextPath = req.getContextPath();
          this.requestPath = path;
          this.location = getDirectoryFromPath( path );
          this.request = req;
          this.response = res;
  
          // Set the default configuration
          setConfiguration( "errmsg",
                            "[an error occurred while processing this directive]" );
          setConfiguration( "sizefmt", "abbrev" );
          setConfiguration( "timefmt", "EEE, dd MMM yyyyy HH:mm:ss z" );
  
  
          // Set the standard server variables
          setVariable( "AUTH_TYPE", req.getAuthType() );
  
          int c = req.getContentLength();
          if (c <= 0)
              setVariable( "CONTENT_LENGTH", "" );
          else
              setVariable( "CONTENT_LENGTH", String.valueOf(c) );
  
          setVariable( "CONTENT_TYPE", req.getContentType() );
          setVariable( "GATEWAY_INTERFACE", "CGI/1.1");
          setVariable( "PATH_INFO", req.getPathInfo() );
          setVariable( "PATH_TRANSLATED ", req.getPathTranslated() );
          setVariable( "QUERY_STRING", req.getQueryString() );
          setVariable( "REMOTE_ADDR", req.getRemoteAddr() );
          setVariable( "REMOTE_HOST", req.getRemoteHost() );
          setVariable( "REMOTE_IDENT", null );
          setVariable( "REMOTE_USER", req.getRemoteUser() );
          setVariable( "REQUEST_METHOD", req.getMethod() );
          setVariable( "SCRIPT_NAME", req.getServletPath() );
          setVariable( "SERVER_NAME", req.getServerName() );
          setVariable( "SERVER_PORT", String.valueOf(req.getServerPort()) );
          setVariable( "SERVER_PROTOCOL", req.getProtocol() );
          setVariable( "SERVER_SOFTWARE", servletContext.getServerInfo() );
          setVariable( "DOCUMENT_NAME", getFileFromPath(path) );
          setVariable( "DOCUMENT_URI", path );
          setVariable( "QUERY_STRING_UNESCAPED", "" );
  
          applyDate();
      }
  
      /**
       *  Constructs a new SsiEnvironment that will use the specified parent
       *  for variable access.
       *
       *  @param parent   The parent for this nested environment.
       *  @param req      The request used to initialize some local nested
       *                  properities.
       */
      protected SsiEnvironment( SsiEnvironment parent,
                                ServletContext context,
                                HttpServletRequest req,
                                HttpServletResponse res,
                                String path ) {
  
          this.parent = parent;
          this.servletContext = context;
          this.requestPath = path;
          this.location = getDirectoryFromPath( path );
          this.request = req;
          this.response = res;
      }
  
      /**
       *  Sets whether virtual paths should be resolved relative to the webapp.
       */
      public void setIsVirtualWebappRelative( boolean flag ) {
          this.isVirtualWebappRelative = flag;
      }
  
      /**
       *  Returns true if virtual paths should be resolved relative to the
       *  webapp.
       */
      public boolean isVirtualWebappRelative() {
          return isVirtualWebappRelative;
      }
  
      /**
       *  Returns true if output is currently disabled.  Certain conditional
       *  commands will change the disabled state, but it should always
       *  be a command that sets it.
       */
      public boolean isOutputDisabled() {
          return disableOutput;
      }
  
      /**
       *  Set to true to disable output.  This should only be done by
       *  SSI commands.
       */
      public void setOutputDisabled( boolean flag ) {
          this.disableOutput = flag;
      }
  
      /**
       *  Returns the request object for this environment instance.
       */
      public HttpServletRequest getRequest() {
          return request;
      }
  
      /**
       *  Returns the response object for this environment instance.
       */
      public HttpServletResponse getResponse() {
          return response;
      }
  
      /**
       *  Returns the current context path for this environment.
       */
      public String getContextPath() {
          return contextPath;
      }
  
      /**
       *  Sets the value of the specified environment variable.
       */
      public void setVariable( String key, String value ) {
          if (parent != null) {
              // Delegate
              parent.setVariable( key, value );
              return;
          }
  
          if (value == null) {
              // Remove it
              serverVariables.remove( key );
              return;
          }
  
          // Set the value
          serverVariables.put( key, value );
      }
  
      /**
       *  Returns the value for the specified environment variable.
       */
      public String getVariable( String key ) {
          if (parent != null)
              return parent.getVariable(key);
          return (String)serverVariables.get( key );
      }
  
      /**
       *  Sets the value of the specified configuration variable.
       */
      public void setConfiguration( String key, String value ) {
          if (parent != null) {
              // Delegate
              parent.setConfiguration( key, value );
              return;
          }
  
          if (value == null) {
              // Remove it
              ssiConfig.remove( key );
              return;
          }
  
          // Set the value
          ssiConfig.put( key, value );
      }
  
      /**
       *  Returns the value for the specified configuration variable.
       */
      public String getConfiguration( String key ) {
          if (parent != null)
              return parent.getConfiguration(key);
          return (String)ssiConfig.get( key );
      }
  
      /**
       *  Sets the current data and time to the appropriate environment
       *  variables.
       */
      public void applyDate() {
          setVariable( "DATE_LOCAL", formatDate(new Date()) );
          setVariable( "DATE_GMT", formatDate(new Date(), DateTool.GMT_ZONE) );
      }
  
      /**
       *  Sets the last modified variable to the last modification time
       *  of the current document.
       */
      public void applyLastModTime() {
          setVariable( "LAST_MODIFIED", getLastModified(requestPath) );
      }
  
      /**
       *  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) == '\\')
                  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 = getVariable( 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();
      }
  
      /**
       *  Format the Date using the current time format settings.
       */
      public String formatDate( Date date ) {
  
          String pattern = getConfiguration( "timefmt" );
          DateFormat dateFormat = new SimpleDateFormat( pattern,
                                                        DateTool.LOCALE_US );
          return dateFormat.format(date);
      }
  
      /**
       *  Format the Date using the current time format settings and the
       *  specified TimeZone.
       */
      public String formatDate( Date date, TimeZone zone ) {
  
          String pattern = getConfiguration( "timefmt" );
          DateFormat dateFormat = new SimpleDateFormat( pattern,
                                                        DateTool.LOCALE_US );
          dateFormat.setTimeZone(DateTool.GMT_ZONE);
          return dateFormat.format(date);
      }
  
      /**
       *  Returns a FileReference object that can be used to lookup
       *  resources and request dispatchers.
       *
       *  @param path     The path of the file relative to the current
       *                  location.
       *  @param virtual  True if the path should be treated as if it were a
       *                  "virtual" argument in the SSI include directive.
       */
      public FileReference getFileReference( String path, boolean virtual ) {
  
          if (path == null)
              return null;
  
          // Create a place for the normalized path
          String normalized = path;
  
          // Flip the backslashes
          if (normalized.indexOf('\\') >= 0)
              normalized = normalized.replace( '\\', '/' );
  
          // Only virtual allows ".."
          if (!virtual && path.indexOf( ".." ) > 0)
              return null;
  
          if (!normalized.startsWith("/")) {
              // Make the full relative path otherwise assume absolute
              normalized = location.concat( normalized );
          } else if (!virtual) {
              // Only virtual paths can be absolute
              return null;
          }
  
          // Resolve occurrences of "//" in the normalized path
          int index;
          while ((index = normalized.indexOf("//")) >= 0) {
              normalized = normalized.substring( 0, index )
                          + normalized.substring( index + 1 );
          }
  
          // Resololve occurrences of "/./" in the normalized path
          while ((index = normalized.indexOf("/./")) >= 0)  {
              normalized = normalized.substring( 0, index )
                          + normalized.substring( index + 2 );
          }
  
          // Resolve occurrences of "/../" in the normalized path
          while ((index = normalized.indexOf("/../")) >= 0) {
              if (index == 0) // Trying to go outside our context
                  return null;
  
              // Find the start of the parent dir
              int index2 = normalized.lastIndexOf( '/', index - 1 );
  
              // Take it out along with the /..
              normalized = normalized.substring( 0, index2 )
                          + normalized.substring( index + 3 );
          }
  
          // Default the file context to the current environment context.
          ServletContext context = servletContext;
  
          // Only virtual paths can be anything other than webapp relative
          // If the path should be interpretted as server root relative
          // then the appropriate path and servlet context still need to
          // be resolved.
          if (virtual && !isVirtualWebappRelative) {
  
              // case of virtual="file.txt", "./file.txt", or dir/file.txt
              if ((!path.startsWith("/")) || (path.startsWith("./"))) {
                  // handle as file in the current directory with original servletContext
                  // No special processing necessary
              } else if (path.indexOf('/', 1)==-1) {
                  // root context
                  context = servletContext.getContext("/");
              } else if (!contextPath.equals("") &&
                         (normalized !=null) && (normalized.startsWith(contextPath))) {
                  // starts with the context path of this webapp
                  // strip off the context path
                  context = servletContext.getContext(contextPath);
                  normalized = normalized.substring(contextPath.length());
              } else if (normalized != null) {
                  // find which context is the right one to handle
                  String contextName = normalized.substring(0, path.indexOf('/', 1));
                  ServletContext sc = servletContext.getContext(contextName);
                  if (sc != null) {
                      context = sc;
                      normalized = normalized.substring(contextName.length());
                  }
              }
          }
  
          // Return the resolved file reference object
          return new FileReference( normalized, context );
      }
  
  
      /**
       *  Returns the formatted last modification time of the specified path.
       */
      public String getLastModified( String path ) {
  
          // Get the file reference for the path
          FileReference ref = getFileReference( path, true );
  
          return getLastModified( ref );
      }
  
      /**
       *  Returns the formatted last modification time of the specified
       *  FileReference.
       */
      public String getLastModified( FileReference ref ) {
  
          try {
              URL u = ref.getResource();
              long lastModified = u.openConnection().getLastModified();
              return formatDate(new Date(lastModified));
          } catch (MalformedURLException e) {
              return null;
          } catch (IOException e) {
              return null;
          } catch (NullPointerException e) {
              return null;
          }
      }
  
      /**
       *  Returns just the file portion of the specified path.
       */
      private String getFileFromPath( String path ) {
  
          int split = path.lastIndexOf( '/' );
          if (split < 0)
              return path;
          return path.substring( split + 1 );
      }
  
      /**
       *  Returns just the directory portion of the specified path.
       */
      private String getDirectoryFromPath( String path ) {
  
          int split = path.lastIndexOf( '/' );
          if (split < 0)
              return path;
          return path.substring( 0, split + 1 );
      }
  
      /**
       *  Helper method to convert null values to "".
       */
      private String nullToString( String value ) {
          return (value==null)?"":value;
      }
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiSet.java
  
  Index: SsiSet.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiSet.java,v 1.1 2001/10/26 19:35:23 bip Exp $
   * $Revision: 1.1 $
   * $Date: 2001/10/26 19:35:23 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.catalina.util.ssi;
  
  import javax.servlet.ServletOutputStream;
  
  /**
   *  SSI command to set a server variable in the SsiEnvironment.
   *
   *  @version   $Revision: 1.1 $, $Date: 2001/10/26 19:35:23 $
   *  @author    Paul Speed
   */
  public final class SsiSet implements SsiCommand {
  
      /**
       *  Runs this command using the specified parameters.
       *
       *  @param cmdName  The name that was used to lookup this
       *                  command instance.
       *  @param argNames String array containing the parameter
       *                  names for the command.
       *  @param argVals  String array containing the paramater
       *                  values for the command.
       *  @param ssiEnv   The environment to use for command
       *                  execution.
       *  @param out      A convenient place for commands to
       *                  write their output.
       */
      public void execute( String cmdName, String[] argNames,
                           String[] argVals, SsiEnvironment ssiEnv,
                           ServletOutputStream out )
                                      throws SsiCommandException {
  
          String varName = null;
          String value = null;
  
          for (int i = 0; i < argNames.length; i++) {
              String name = argNames[i];
              if ("var".equals( name ))
                  varName = argVals[i];
              else if ("value".equals( name ))
                  value = argVals[i];
          }
  
          if (varName == null)
              throw new SsiCommandException( "No variable specified." );
  
          // Resolve any variable references in the value
          value = ssiEnv.substituteVariables( value );
  
          // Set the server variable value
          ssiEnv.setVariable( varName, value );
      }
  
  }
  
  
  

Mime
View raw message