amyroh      01/04/03 15:45:33

  Modified:    catalina/src/share/org/apache/catalina/util/ssi
                        SsiMediator.java
  Log:
  Fixed virtual behavior to follow NCSA rules with a webapp-relative option.
  
  Revision  Changes    Path
  1.3       +48 -9     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiMediator.java
  
  Index: SsiMediator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiMediator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SsiMediator.java  2001/04/02 21:14:29     1.2
  +++ SsiMediator.java  2001/04/03 22:45:33     1.3
  @@ -1,8 +1,8 @@
   /*
    * SsiMediator.java
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiMediator.java,v
 1.2 2001/04/02 21:14:29 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/04/02 21:14:29 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiMediator.java,v
 1.3 2001/04/03 22:45:33 amyroh Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/04/03 22:45:33 $
    *
    * ====================================================================
    *
  @@ -85,7 +85,8 @@
   
   /**
    * @author Bip Thelin
  - * @version $Revision: 1.2 $, $Date: 2001/04/02 21:14:29 $
  + * @author Amy Roh
  + * @version $Revision: 1.3 $, $Date: 2001/04/03 22:45:33 $
    *
    */
   public class SsiMediator {
  @@ -106,12 +107,18 @@
   
       protected static ServletContext servletContext = null;
   
  +    protected static ServletContext origServletContext = null;
  +
  +    protected static String contextPath = null;
  +
       protected static String relpath = "/";
   
       protected static String path = new String();
   
       protected static int debug = 0;
   
  +    protected static boolean isVirtualWebappRelative = false;
  +
       public SsiMediator() {}
   
       static {
  @@ -129,9 +136,10 @@
                       OutputStream out,
                       ServletContext servletContext,
                       int debug,
  -                    String path) {
  +                    String path,
  +               boolean isVirtualWebappRelative) {
        this.debug = debug;
  -     flush(req, res, out, servletContext, path);
  +     flush(req, res, out, servletContext, path, isVirtualWebappRelative);
       }
   
       public final SsiCommand getCommand(String cmd) {
  @@ -142,13 +150,17 @@
                      HttpServletResponse res,
                      OutputStream out,
                      ServletContext servletContext,
  -                   String path) {
  +                   String path,
  +              boolean isVirtualWebappRelative) {
        this.req = req;
        this.res = res;
        this.out = out;
        this.servletContext = servletContext;
  +    this.origServletContext = servletContext;
  +    this.contextPath = req.getContextPath();
        this.path = path;
        this.relpath = path.substring(0, path.lastIndexOf("/")+1);
  +    this.isVirtualWebappRelative = isVirtualWebappRelative;
        int c=0;
   
        serverVariables.put("AUTH_TYPE",
  @@ -295,6 +307,32 @@
                normalized.substring(index + 3);
        }
   
  +    if (!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
  +            servletContext = origServletContext;
  +        }else if (path.indexOf("/", 1)==-1) {
  +            //root context
  +            servletContext = servletContext.getContext("/");
  +        } else if (!contextPath.equals("")) {
  +            //starts with the context path of this webapp
  +            if ((normalized !=null) && (normalized.startsWith(contextPath))) {
  +                // strip off the context path
  +                servletContext = servletContext.getContext(contextPath);
  +                normalized = normalized.substring(contextPath.length());
  +            }
  +        } else if (normalized != null){
  +            // find which context is the right one to handle 
  +            String context = normalized.substring(0, path.indexOf("/", 1));
  +            ServletContext sc = servletContext.getContext(context);
  +            if (sc!=null) {
  +                servletContext = sc;
  +                normalized = normalized.substring(context.length());
  +            }
  +        }
  +    }
  +
        return (normalized);
       }
   
  @@ -325,6 +363,8 @@
            *     normalized = RequestUtil.URLDecode(normalized, "UTF8");
            */
   
  +         servletContext = origServletContext;
  +
           if (normalized == null)
               return (null);
   
  @@ -341,8 +381,7 @@
                normalized.substring(index + 1);
        }
   
  -     // If it starts with a "/" or contains "../" we
  -     // return <code>null</code>.
  +     // If it starts with a "/" or contains "../" we return <code>null</code>.
        if (normalized.startsWith("/") || normalized.indexOf("../") >= 0)
            return (null);
   
  
  
  

Reply via email to