arieh       01/03/16 15:42:00

  Modified:    src/share/org/apache/tomcat/request Tag: tomcat_32
                        StaticInterceptor.java
  Log:
  Add support for docbase localization lookup.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.7.2.9   +65 -23    
jakarta-tomcat/src/share/org/apache/tomcat/request/Attic/StaticInterceptor.java
  
  Index: StaticInterceptor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/Attic/StaticInterceptor.java,v
  retrieving revision 1.7.2.8
  retrieving revision 1.7.2.9
  diff -u -r1.7.2.8 -r1.7.2.9
  --- StaticInterceptor.java    2001/03/13 22:03:19     1.7.2.8
  +++ StaticInterceptor.java    2001/03/16 23:41:57     1.7.2.9
  @@ -186,7 +186,12 @@
        if (localization == FILE_LOC)
            absPath = ctx.getRealPath (pathInfo,
                                       RequestUtil.getLocale(req),
  -                                    Locale.getDefault());
  +                                    Locale.getDefault(), "file");
  +     else if (localization == DOCB_LOC)
  +         absPath = ctx.getRealPath (pathInfo,
  +                                    RequestUtil.getLocale(req),
  +                                    Locale.getDefault(), "docbase");
  +
        else
            absPath = ctx.getRealPath( pathInfo );
   
  @@ -213,8 +218,10 @@
   
        // Directory, check if we have a welcome file
        String welcomeFile = null;
  -     if (localization == FILE_LOC)
  -         welcomeFile = getWelcomeFile(ctx, file,
  +
  +     //
  +     if (localization == FILE_LOC || localization == DOCB_LOC)
  +         welcomeFile = getWelcomeFile(ctx, pathInfo,
                                         RequestUtil.getLocale(req),
                                         Locale.getDefault());
        else
  @@ -275,31 +282,69 @@
        return null;
       }
   
  -    private String getWelcomeFile(Context context, File dir,
  +    private String getWelcomeFile(Context context, String path,
                                  Locale loc, Locale fbloc) {
        Enumeration enum = context.getWelcomeFiles();
   
  +     String docBase = context.getAbsolutePath();
  +     StringBuffer sb = new StringBuffer(docBase);
  +
        while (enum.hasMoreElements()) {
            String fileName = (String)enum.nextElement();
   
  -         int  ftype = fileName.lastIndexOf ('.');
  -         String fbasen = (ftype != -1)
  -                             ? fileName.substring (0, ftype)
  -                             : fileName;
  -
  -         String fPath = dir.getAbsolutePath()
  -                      + File.separatorChar
  -                      + fileName;
  -
  -         String retPath = FileUtil.getLocalizedResource (fPath,
  -                                                         loc,
  -                                                         fbloc);
  -         if ((new File(retPath)).exists())
  +         String retPath = null;
  +         
  +         if (localization == FILE_LOC)
            {
  -             int pathPos = retPath.lastIndexOf (fbasen);
  -             return retPath.substring (pathPos);
  +             //  preserve the basename of the path, so that the
  +             //  localized version can be identified following
  +             //  the lookup
  +             //
  +             int  ftype = fileName.lastIndexOf ('.');
  +             String fbasen = (ftype != -1) 
  +                                 ? fileName.substring (0, ftype)
  +                                 : fileName;
  +
  +             String fp = concatPath(docBase, fileName);
  +
  +             retPath = FileUtil.getLocalizedResource (
  +                                                      fp,
  +                                                      loc,
  +                                                      fbloc);
  +             if (new File(retPath).exists())
  +             {
  +                 int pathPos = retPath.lastIndexOf (fbasen);
  +                 return retPath.substring (pathPos);
  +             }
            }
  +         else        // localize according to DOCBASE
  +         {
  +             //  make sure there is a File.separator between the
  +             //  passed path and the welcome file
  +             //
  +             if (null != path)
  +             {
  +                 sb = new StringBuffer(path);
  +                 if (! path.endsWith(File.separator))
  +                     sb.append(File.separatorChar);
  +             }
  +             else
  +                 sb = new StringBuffer();
  +
  +             sb.append (fileName);
  +
  +             retPath = FileUtil.getDocBaseLocalizedResource (
  +                                                     docBase,
  +                                                     sb.toString(),
  +                                                     loc,
  +                                                     fbloc);
  +             if ((new File(retPath)).exists())
  +             {
  +                 return retPath.substring(docBase.length());
  +             }
  +         }
        }
  +
        return null;
       }
   }
  @@ -332,10 +377,7 @@
            subReq=req.getChild();
   
        Context ctx=subReq.getContext();
  -   // If this file is being included, use javax.servlet.include.servlet_path.
  -   String pathInfo = 
(String)subReq.getAttribute("javax.servlet.include.servlet_path");
  -   if(pathInfo == null)
  -      pathInfo=subReq.getServletPath();
  +     String pathInfo=subReq.getServletPath();
        String absPath = (String)subReq.getNote( realFileNote );
        if( absPath==null ) 
            absPath=ctx.getRealPath( pathInfo );
  
  
  

Reply via email to