You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bi...@apache.org on 2002/06/23 05:32:31 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/modules/generators StaticInterceptor.java

billbarker    2002/06/22 20:32:31

  Modified:    src/share/org/apache/tomcat/modules/generators
                        StaticInterceptor.java
  Log:
  Experimental support for 2.3 style mapped-welcome files.
  
  This of off be default, and probably uses too many recorces if you have more than a few welcome-files.  What it enables is JspC compilations and declarations like:
  
  <servlet-mapping>
    <servlet-name>WelcomeServlet</servlet-name>
    <url-pattern>/foobar/</url-pattern>
  </servlet-mapping>
  
  For now, should be considered experimental only.  However, I'd be interested to hear how much overhead it adds if anyone wants to test.
  
  Revision  Changes    Path
  1.25      +50 -6     jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/StaticInterceptor.java
  
  Index: StaticInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/StaticInterceptor.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- StaticInterceptor.java	8 May 2002 02:27:04 -0000	1.24
  +++ StaticInterceptor.java	23 Jun 2002 03:32:31 -0000	1.25
  @@ -80,6 +80,7 @@
       String charset=null;
       private boolean extraSafety=false;
       private boolean useInternal=false;
  +    private boolean strict23Welcome=false;
   
       public StaticInterceptor() {
       }
  @@ -106,6 +107,14 @@
   	useInternal = internal;
       }
   
  +    /** Support the 2.3 behavior of allowing mapped servlets as welcome files.
  +     * @param support <code>true</code> Allow mapped servlets.
  +     *                <code>false</code> Allow only files.
  +     */
  +    public void setStrict23Welcome(boolean support) {
  +	strict23Welcome = support;
  +    }
  +
       public void setUseAcceptLanguage(boolean use) {
           useAcceptLanguage=use;
       }
  @@ -206,7 +215,13 @@
   	    return 0;
   	}
   	// Directory, check if we have a welcome file
  -	String welcomeFile = getWelcomeFile(ctx, file);
  +	
  +	String welcomeFile = null;
  +	if( strict23Welcome ) {
  +	    welcomeFile = getStrictWelcomeFile(ctx, file, pathInfo);
  +	} else {
  +	    welcomeFile = getWelcomeFile(ctx, file);
  +	}
   	if( debug > 0 )
   	    log( "DefaultServlet: welcome file: "  + welcomeFile);
   	
  @@ -234,6 +249,7 @@
           BaseInterceptor ri[];
   	String requestURI=req.requestURI().toString();
   	String redirectURI=concatPath(requestURI,welcomeFile);
  +	Context ctx = req.getContext();
   	req.requestURI().setString(redirectURI);
   	req.unparsedURI().recycle();
   	req.servletPath().recycle();
  @@ -247,7 +263,11 @@
   	   we need to contextMap again to catch extention-mapped servlets.
   	*/
   	int status = 0;
  -	ri=cm.getContainer().getInterceptors(Container.H_contextMap);
  +	if(ctx == null) {
  +	    ri=cm.getContainer().getInterceptors(Container.H_contextMap);
  +	} else {
  +	    ri = ctx.getContainer().getInterceptors(Container.H_contextMap);
  +	}
   	
   	for( int i=0; i< ri.length; i++ ) {
   	    status=ri[i].contextMap( req );
  @@ -319,19 +339,43 @@
   	}
       }
   
  +    private String getStrictWelcomeFile(Context context, File dir, String pathInfo) {
  +        String wf[]= context.getWelcomeFiles();
  +        BaseInterceptor ri[] = context.getContainer().
  +	                          getInterceptors(Container.H_contextMap);
  +	for(int i=0; i < wf.length; i++) {
  +	    if(getOneWelcomeFile(dir, wf[i])) {
  +		return wf[i];
  +	    }
  +	    String wfURI = concatPath(pathInfo, wf[i]);
  +	    Request req = cm.createRequest(context, wfURI);
  +	    int status = 0;
  +	
  +	    for( int j=0; j< ri.length; j++ ) {
  +		status=ri[j].contextMap( req );
  +		if( status!=0 ) break;
  +	    }
  +	    if(status == 0 && req.servletPath() != null && !req.servletPath().equals("")) {
  +		return req.servletPath().toString().substring(pathInfo.length());
  +	    }
  +	}
  +	    
  +	return null;
  +    }
       private String getWelcomeFile(Context context, File dir) {
           String wf[]= context.getWelcomeFiles();
   
   	for( int i=0; i<wf.length; i++ ) {
  -	    File f = new File(dir, wf[i]);
  -	    if (f.exists()) {
  +	    if (getOneWelcomeFile(dir, wf[i])) {
   		return wf[i];
   	    }
   	}
   	return null;
       }
  -
  -
  +    private boolean getOneWelcomeFile(File dir, String wf) {
  +	File f = new File(dir, wf);
  +	return f.exists();
  +    }
   }
   
   // -------------------- Handlers --------------------
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>