You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/01/08 23:55:46 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/core Constants.java Context.java ContextManager.java

costin      00/01/08 14:55:45

  Modified:    src/share/org/apache/tomcat/core Constants.java Context.java
                        ContextManager.java
  Added:       src/share/org/apache/tomcat/context
                        DefaultContextSetter.java WarInterceptor.java
                        WebXmlInterceptor.java WorkDirInterceptor.java
  Log:
  Moved logic from Context into ContextInterceptors ( no interface yet,
  still hardcoded until initialization cleanup).
  
  Context interceptors are grouped in tomcat.context ( if you have a better name
  please move them !).
  
  Still a lot of work to clean the interceptors, or start from zero with new
  ones, but Context is much better now.
  
  Since Context has a lot of properties ( as required by Specs ), it is better
  if Context will have little logic inside, but delegate to specialized
  classes.
  
  Also, the new methods added to Context will simplify an admin interface.
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultContextSetter.java
  
  Index: DefaultContextSetter.java
  ===================================================================
  /*
   * ====================================================================
   *
   * 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.tomcat.context;
  
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.core.Constants;
  import org.apache.tomcat.util.*;
  import org.apache.tomcat.deployment.*;
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import javax.servlet.http.*;
  
  
  /**
   * Interceptor that sets a number of default properties in context.
   *
   * @author costin@dnt.ro
   */
  public class DefaultContextSetter {
  
      public DefaultContextSetter() {
      }
  	
      public int handleContextInit(Context ctx) {
  	setEngineHeader( ctx );
  	if( ctx.getRequestSecurityProvider() == null ) 
  	    ctx.setRequestSecurityProvider(DefaultRequestSecurityProvider.
  					   getInstance());
  	
  	if( ctx.getWorkDir() == null)
  	    ctx.setWorkDir( new File(System.getProperty("user.dir", ".") +
  				     System.getProperty("file.separator") + Constants.WORK_DIR),
  			    ctx.isWorkDirPersistent() );
  
  	
  	if( ctx.getSessionManager() == null ) 
  	    ctx.setSessionManager( org.apache.tomcat.session.ServerSessionManager.getManager());
  
  
  	//Was:        for (int i = 0; i < Constants.Context.CLASS_PATHS.length; i++) {
  
  	// The names are defined by the spec, and if that change - a lot will
  	// also have too change - there is no advantage in keeping them in Constants,
  	ctx.addClassPath("WEB-INF/classes");
  	ctx.addLibPath("WEB-INF/lib");
  	return 0;
      }
  
  	
      // -------------------- implementation
      private void setEngineHeader(Context ctx) {
          String engineHeader=ctx.getEngineHeader();
  
  	if( engineHeader==null) {
  	    /*
  	     * Whoever modifies this needs to check this modification is
  	     * ok with the code in com.jsp.runtime.ServletEngine or talk
  	     * to akv before you check it in. 
  	     */
  	    // Default value for engine header
  	    // no longer use core.properties - the configuration comes from
  	    // server.xml or web.xml - no more properties.
  	    StringBuffer sb=new StringBuffer();
  	    sb.append(Constants.TOMCAT_NAME).append("/").append(Constants.TOMCAT_VERSION);
  	    sb.append(" (").append(Constants.JSP_NAME).append(" ").append(Constants.JSP_VERSION);
  	    sb.append("; ").append(Constants.SERVLET_NAME).append(" ");
  	    sb.append(Constants.SERVLET_MAJOR).append(".").append(Constants.SERVLET_MINOR);
  	    sb.append( "; Java " );
  	    sb.append(System.getProperty("java.version")).append("; ");
  	    sb.append(System.getProperty("os.name") + " ");
  	    sb.append(System.getProperty("os.version") + " ");
  	    sb.append(System.getProperty("os.arch") + "; java.vendor=");
  	    sb.append(System.getProperty("java.vendor")).append(")");
  	    engineHeader=sb.toString();
  	}
  	ctx.setEngineHeader( engineHeader );
      }
  }
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/context/WarInterceptor.java
  
  Index: WarInterceptor.java
  ===================================================================
  /*
   * ====================================================================
   *
   * 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.tomcat.context;
  
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.core.Constants;
  import org.apache.tomcat.util.*;
  import org.apache.tomcat.deployment.*;
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import javax.servlet.http.*;
  
  
  /**
   * Interceptor that sets a number of default properties in context.
   *
   * @author costin@dnt.ro
   */
  public class WarInterceptor {
  
      public WarInterceptor() {
      }
  	
      public int handleContextInit(Context ctx) {
  	if (ctx.getDocumentBase().getProtocol().equalsIgnoreCase("war")) {
  	    if (ctx.isWARExpanded()) {
  	        File warDir = new File(ctx.getWorkDir(),
  				       Constants.Context.WARExpandDir);
  		ctx.setWARDir( warDir );
  		
  		if (! warDir.exists()) {
  		    warDir.mkdirs();
  
  		    try {
  		        WARUtil.expand(warDir, ctx.getDocumentBase());
  		    } catch (MalformedURLException mue) {
  		    } catch (IOException ioe) {
  		    }
  
  		    try {
                          URL servletBase = URLUtil.resolve(warDir.toString());
  			ctx.setServletBase( servletBase );
  		    } catch (Exception e) {
  		    }
  		}
  	    }
  	}
  	return 0;
      }
  }
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/context/WebXmlInterceptor.java
  
  Index: WebXmlInterceptor.java
  ===================================================================
  /*
   * ====================================================================
   *
   * 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.tomcat.context;
  
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.core.Constants;
  import org.apache.tomcat.util.*;
  import org.apache.tomcat.deployment.*;
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import javax.servlet.http.*;
  
  
  /**
   * Will configure the context using the default web.xml
   *
   * @author costin@dnt.ro
   */
  public class WebXmlInterceptor {
      private static StringManager sm =StringManager.getManager("org.apache.tomcat.core");
      
      public WebXmlInterceptor() {
      }
  	
      public int handleContextInit(Context ctx) {
  	// process base configuration
  	try {
  	    Class webApplicationDescriptor = Class.forName(
  	        "org.apache.tomcat.deployment.WebApplicationDescriptor");
  	    InputStream is =
  	        webApplicationDescriptor.getResourceAsStream(
  	            org.apache.tomcat.deployment.Constants.ConfigFile);
  	    String msg = sm.getString("context.getConfig.msg", "default");
  
      	    System.out.println(msg);
  
  	    processWebApp(ctx, is, true);
  	} catch (Exception e) {
  	    String msg = sm.getString("context.getConfig.e", "default");
  	    System.out.println(msg);
  	}
  
  	// process webApp configuration
  
  	String s = ctx.getDocumentBase().toString();
  	if (ctx.getDocumentBase().getProtocol().equalsIgnoreCase("war")) {
  	    if (s.endsWith("/")) {
  	        s = s.substring(0, s.length() - 1);
  	    }
  
  	    s += "!/";
  	}
  
  	URL webURL = null;
  	try {
  	    webURL = new URL(s + Constants.Context.ConfigFile);
  
  	    InputStream is = webURL.openConnection().getInputStream();
  	    String msg = sm.getString("context.getConfig.msg",
  				      webURL.toString());
  
  	    System.out.println(msg);
  	    
  	    processWebApp(ctx, is, false);
  	} catch (Exception e) {
  	    String msg = sm.getString("context.getConfig.e",
  	        (webURL != null) ? webURL.toString() : "not available");
  
              // go silent on this one
  	    // System.out.println(msg);
  	}
  	return 0;
      }
  
  
      private void processWebApp(Context ctx, InputStream is, boolean internal) {
          if (is != null) {
  	    try {
  	        WebApplicationDescriptor webDescriptor =
  		    (new WebApplicationReader()).getDescriptor(is,
  		        new WebDescriptorFactoryImpl(),
  			ctx.isWARValidated());
  
  		ctx.setDescription( webDescriptor.getDescription());
  		ctx.setDistributable( webDescriptor.isDistributable());
  
  		Enumeration contextParameters=webDescriptor.getContextParameters();
  		while (contextParameters.hasMoreElements()) {
  		    ContextParameter contextParameter =
  			(ContextParameter)contextParameters.nextElement();
  		    ctx.setInitParameter(contextParameter.getName(),
  					 contextParameter.getValue());
  		}
  		ctx.setSessionTimeOut( webDescriptor.getSessionTimeout());
  
  		processServlets(ctx, webDescriptor.getWebComponentDescriptors());
  		processMimeMaps(ctx, webDescriptor.getMimeMappings());
  		processWelcomeFiles(ctx, webDescriptor.getWelcomeFiles(),
  				    internal);
  		processErrorPages(ctx, webDescriptor.getErrorPageDescriptors());
  	    } catch (Throwable e) {
                  String msg = "config parse: " + e.getMessage();
  
                  System.out.println(msg);
  	    }
  	}
      }
  
      private void processServlets(Context ctx, Enumeration servlets) {
          // XXX
          // oh my ... this has suddenly turned rather ugly
          // perhaps the reader should do this normalization work
  
          while (servlets.hasMoreElements()) {
  	    WebComponentDescriptor webComponentDescriptor =
  	        (WebComponentDescriptor)servlets.nextElement();
  	    String name = webComponentDescriptor.getCanonicalName();
  	    String description = webComponentDescriptor.getDescription();
  	    String resourceName = null;
  	    boolean removeResource = false;
  
  	    if (webComponentDescriptor instanceof ServletDescriptor) {
  		resourceName =
  		    ((ServletDescriptor)webComponentDescriptor).getClassName();
  
  		if ( ctx.containsServletByName(name)) {
  		    String msg = sm.getString("context.dd.dropServlet",
  					      name + "(" + resourceName + ")" );
  		    
  		    System.out.println(msg);
  		    
  		    removeResource = true;
  		    ctx.removeServletByName(name);
  		}
  
  		ctx.addServlet(name, resourceName, description);
  	    } else if (webComponentDescriptor instanceof JspDescriptor) {
  		resourceName =
  		    ((JspDescriptor)webComponentDescriptor).getJspFileName();
  
  		if (! resourceName.startsWith("/")) {
  		    resourceName = "/" + resourceName;
  		}
  
  		if (ctx.containsJSP(resourceName)) {
  		    String msg = sm.getString("context.dd.dropServlet",
  					      resourceName);
  
  		    System.out.println(msg);
  		    
  		    removeResource = true;
  		    ctx.removeJSP(resourceName);
  		}
  
  		ctx.addJSP(name, resourceName, description);
  	    }
  
  
  	    // XXX ugly, but outside of context - the whole thing will be
  	    // rewriten, so don't worry
  	    
  	    // if the resource was already defined, override with the new definition
  	    // XXX I have very little ideea about what it does !
  	    if (removeResource) {
  
  	        Enumeration levels = ctx.getInitLevles();
  
  		while (levels.hasMoreElements()) {
  		    Integer level = (Integer)levels.nextElement();
  		    Enumeration servletsOnLevel=ctx.getLoadableServlets( level );
  		    
  		    Vector buf = new Vector();
  		    while (servletsOnLevel.hasMoreElements()) {
  		        String servletName = (String)servletsOnLevel.nextElement();
  
  			if (ctx.containsServletByName(servletName)) {
  			    buf.addElement(servletName);
  			}
  		    }
  		    ctx.setLoadableServlets(level, buf);
  		}
  	    }
  	    
  	    int loadOnStartUp = webComponentDescriptor.getLoadOnStartUp();
  
              if (loadOnStartUp > Integer.MIN_VALUE) {
  	        Integer key = new Integer(loadOnStartUp);
  		ctx.addLoadableServlet( key, name );
  		
  	    }
  
  	    Enumeration enum =
  	        webComponentDescriptor.getInitializationParameters();
  	    Hashtable initializationParameters = new Hashtable();
  
  	    while (enum.hasMoreElements()) {
  	        InitializationParameter initializationParameter =
  		    (InitializationParameter)enum.nextElement();
  
  		initializationParameters.put(
  		    initializationParameter.getName(),
  		    initializationParameter.getValue());
  	    }
  
  	    ctx.setServletInitParams( webComponentDescriptor.getCanonicalName(),
  				 initializationParameters);
  
  	    enum = webComponentDescriptor.getUrlPatterns();
  
  	    while (enum.hasMoreElements()) {
  	        String mapping = (String)enum.nextElement();
  
  		if (! mapping.startsWith("*.") &&
  		    ! mapping.startsWith("/")) {
  		    mapping = "/" + mapping;
  		}
  
  		if (! ctx.containsServlet(mapping) &&
  		    ! ctx.containsJSP(mapping)) {
  		    if (ctx.containsMapping(mapping)) {
  		        String msg = sm.getString("context.dd.dropMapping",
  			    mapping);
  
  			System.out.println(msg);
  
  			ctx.removeMapping(mapping);
  		    }
  
                      ctx.addMapping(name, mapping);
  		} else {
  		    String msg = sm.getString("context.dd.ignoreMapping",
  		        mapping);
  
  		    System.out.println(msg);
  		}
  	    }
  	}
      }
  
      private void processMimeMaps(Context ctx, Enumeration mimeMaps) {
          while (mimeMaps.hasMoreElements()) {
  	    MimeMapping mimeMapping = (MimeMapping)mimeMaps.nextElement();
  
  	    ctx.addContentType(	mimeMapping.getExtension(),
  				mimeMapping.getMimeType());
  	}
      }
  
      private void processWelcomeFiles(Context ctx, Enumeration welcomeFiles,
          boolean internal) {
          if (! internal && welcomeFiles.hasMoreElements()) {
              ctx.removeWelcomeFiles();
          }
  
  	while (welcomeFiles.hasMoreElements()) {
  	    ctx.addWelcomeFile((String)welcomeFiles.nextElement());
  	}
      }
  
      private void processErrorPages(Context ctx, Enumeration errorPages) {
          while (errorPages.hasMoreElements()) {
  	    ErrorPageDescriptor errorPageDescriptor =
  	        (ErrorPageDescriptor)errorPages.nextElement();
  	    String key = null;
  
  	    if (errorPageDescriptor.getErrorCode() > -1) {
  	        key = String.valueOf(errorPageDescriptor.getErrorCode());
  	    } else {
  	        key = errorPageDescriptor.getExceptionType();
  	    }
  
  	    ctx.addErrorPage(key, errorPageDescriptor.getLocation());
  	}
      }
  
      
  }
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/context/WorkDirInterceptor.java
  
  Index: WorkDirInterceptor.java
  ===================================================================
  /*
   * ====================================================================
   *
   * 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.tomcat.context;
  
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.core.Constants;
  import org.apache.tomcat.util.*;
  import org.apache.tomcat.deployment.*;
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import javax.servlet.http.*;
  
  
  /**
   * Handles work dir setup/removal
   *
   * @author costin@dnt.ro
   */
  public class WorkDirInterceptor {
  
      public WorkDirInterceptor() {
      }
  	
      public int handleContextInit(Context ctx) {
  	// never null !! ( it is set by default to ./work ! )
  	//log	System.out.println("Preparing work dir " + ctx.getWorkDir() );
  
  	if (! ctx.isWorkDirPersistent()) {
  	    clearDir(ctx.getWorkDir() );
          }
  
  	if (! ctx.getWorkDir().exists()) {
  	    //log  System.out.println("Creating work dir " + ctx.getWorkDir() );
  	    ctx.getWorkDir().mkdirs();
  	}
  
  	ctx.setAttribute(Constants.ATTRIB_WORKDIR1, ctx.getWorkDir());
  	ctx.setAttribute(Constants.ATTRIB_WORKDIR , ctx.getWorkDir());
  	return 0;
      }
  
      public int handleContextShutdown( Context ctx ) {
  	
  	if (! ctx.isWorkDirPersistent()) {
              clearDir(ctx.getWorkDir());
  	}
  	return 0;
      }
  
      private void clearDir(File dir) {
          String[] files = dir.list();
  
          if (files != null) {
  	    for (int i = 0; i < files.length; i++) {
  	        File f = new File(dir, files[i]);
  
  	        if (f.isDirectory()) {
  		    clearDir(f);
  	        }
  
  	        try {
  	            f.delete();
  	        } catch (Exception e) {
  	        }
  	    }
  
  	    try {
  	        dir.delete();
  	    } catch (Exception e) {
  	    }
          }
      }
  
  
  	
  }
  
  
  
  1.9       +7 -19     jakarta-tomcat/src/share/org/apache/tomcat/core/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Constants.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Constants.java	2000/01/08 15:34:28	1.8
  +++ Constants.java	2000/01/08 22:55:45	1.9
  @@ -76,16 +76,19 @@
       public static final int SERVLET_MAJOR = 2;
       public static final int SERVLET_MINOR = 2;
   
  +
  +    public static final String ATTRIB_WORKDIR1 = "sun.servlet.workdir";
  +    public static final String ATTRIB_WORKDIR = "javax.servlet.context.tempdir";
  +
  +
       public static final String Package = "org.apache.tomcat.core";
       public static final int RequestURIMatchRecursion = 5;
  -    public static final String WorkDir = "work";
  +    public static final String WORK_DIR = "work";
   
       public static class Context {
           public static final String WebInfDir = "WEB-INF";
           public static final String WARInfDir = "META-INF";
           public static final String ConfigFile = WebInfDir + "/web.xml";
  -        public static final String ServletDir = WebInfDir + "/classes";
  -        public static final String LibDir = WebInfDir + "/lib";
           public static final String WARExpandDir = "docBase";
   
           public static final String[] MASKED_DIR = {
  @@ -93,20 +96,6 @@
               WARInfDir
           };
   
  -        public static String[] CLASS_PATHS = {
  -            ServletDir
  -        };
  -
  -        public static String[] LIB_PATHS = {
  -            LibDir
  -        };
  -
  -        public static class Attribute {
  -	    public static class WorkDir {
  -	        public static final String Name = "sun.servlet.workdir";
  -	    }
  -	}
  -
           public static class Default {
   	    public static final String Name = "default";
   	    public static final String Path = "";
  @@ -158,9 +147,8 @@
           }
       }
   
  +
       public static class Attribute {
  -        public static final String WorkDirectory =
  -            "javax.servlet.context.tempdir";
           public static final String RequestURI =
               "javax.servlet.include.request_uri";
           public static final String ServletPath =
  
  
  
  1.19      +131 -424  jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java
  
  Index: Context.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Context.java	2000/01/08 15:52:20	1.18
  +++ Context.java	2000/01/08 22:55:45	1.19
  @@ -61,85 +61,102 @@
   package org.apache.tomcat.core;
   
   import org.apache.tomcat.server.*;
  +import org.apache.tomcat.context.*;
   import org.apache.tomcat.util.*;
  -import org.apache.tomcat.deployment.*;
   import java.io.*;
   import java.net.*;
   import java.util.*;
   import javax.servlet.http.*;
   
  +//
  +// WARNING: Some of the APIs in this class are used by J2EE. 
  +// Please talk to harishp@eng.sun.com before making any changes.
  +//
  +
   /**
  + * Context represent a Web Application as specified by Servlet Specs.
  + * The implementation is a repository for all the properties
  + * defined in web.xml and tomcat specific properties, with all the
  + * functionality delegated to interceptors.
    * 
    * @author James Duncan Davidson [duncan@eng.sun.com]
    * @author James Todd [gonzo@eng.sun.com]
    * @author Jason Hunter [jch@eng.sun.com]
    * @author Harish Prabandham
  + * @author costin@dnt.ro
    */
  +public class Context {
  +    private static StringManager sm =StringManager.getManager("org.apache.tomcat.core");
   
  -//
  -// WARNING: Some of the APIs in this class are used by J2EE. 
  -// Please talk to harishp@eng.sun.com before making any changes.
  -//
  +    // -------------------- internal properties
  +    // context "id"
  +    private String path = "";
  +    private URL docBase;
   
  -public class Context {
  -    
  -    private StringManager sm =
  -        StringManager.getManager(Constants.Package);
  +    // internal state / related objects
       private boolean initialized = false;
       private ContextManager server;
  -    private String description = null;
  -    private boolean isDistributable = false;
  -    private String engineHeader = null;
  -    //private Hashtable sessions = new Hashtable();
  -    // XXX XXX XXX hardcoded ! 
  -    private SessionManager sessionManager;
       private ServletContextFacade contextFacade;
  -    private Hashtable initializationParameters = new Hashtable();
  +    private SessionManager sessionManager;
  +    private ServletWrapper defaultServlet = null;
  +
  +    // 
       private Hashtable attributes = new Hashtable();
  -    private MimeMap mimeTypes = new MimeMap();
  -    private int sessionTimeOut = -1;
  -    private Vector welcomeFiles = new Vector();
  -    private Hashtable errorPages = new Hashtable();
  -    private Hashtable loadableServlets = new Hashtable();
  -    private URL docBase;
  -    private String path = "";
  -    //private String sessionCookieName;
  -    private boolean isInvokerEnabled = false;
  -    private File workDir =
  -        new File(System.getProperty("user.dir", ".") +
  -            System.getProperty("file.separator") + Constants.WorkDir);
  +
  +    // work dir
  +    private File workDir;
       private boolean isWorkDirPersistent = false;
  +
  +    // tomcat specific properties
  +    private String engineHeader = null;
  +    private URL servletBase = null;
  +    private boolean isInvokerEnabled = false;
  +
  +    // for serving WARs directly 
       private File warDir = null;
       private boolean isWARExpanded = false;
       private boolean isWARValidated = false;
  -    private Vector initInterceptors = new Vector();
  -    private Vector serviceInterceptors = new Vector();
  -    private Vector destroyInterceptors = new Vector();
  -    private RequestSecurityProvider rsProvider =
  -        DefaultRequestSecurityProvider.getInstance();
  -
  -    private Hashtable servlets = new Hashtable();
  -    private Hashtable prefixMappedServlets = new Hashtable();
  -    private Hashtable extensionMappedServlets = new Hashtable();
  -    private Hashtable pathMappedServlets = new Hashtable();
  -    private ServletWrapper defaultServlet = null;
  -    private URL servletBase = null;
   
  -    
       // Class Loading 
       private String classPath = ""; // classpath used by the classloader.
       private Vector classPaths = new Vector();
       private Vector libPaths = new Vector();
       private ServletClassLoader servletLoader;
       private ClassLoader classLoader = null;
  -
       
  +    // Interceptors
  +    private Vector initInterceptors = new Vector();
  +    private Vector serviceInterceptors = new Vector();
  +    private Vector destroyInterceptors = new Vector();
  +    private RequestSecurityProvider rsProvider;
  +    
  +    // Servlets loaded by this context( String->ServletWrapper )
  +    private Hashtable servlets = new Hashtable();
  +
  +    // -------------------- from web.xml
  +    private Hashtable initializationParameters = new Hashtable();
  +    private Vector welcomeFiles = new Vector();
  +    private Hashtable errorPages = new Hashtable();
  +    private String description = null;
  +    private boolean isDistributable = false;
  +    private MimeMap mimeTypes = new MimeMap();
  +    private int sessionTimeOut = -1;
  +
  +    // Maps specified in web.xml ( String->ServletWrapper )
  +    private Hashtable prefixMappedServlets = new Hashtable();
  +    private Hashtable extensionMappedServlets = new Hashtable();
  +    private Hashtable pathMappedServlets = new Hashtable();
  +    // servlets loaded on startup( String->ServletWrapper )
  +    private Hashtable loadableServlets = new Hashtable();
  +
  +    // -------------------- Accessors --------------------
       public Context() {
       }
   	
  -    public Context(ContextManager server, String path) {
  +    public Context(ContextManager server, String path, URL docBase) {
           this.server = server;
   	this.path = path;
  +	setDocumentBase( docBase );
           contextFacade = new ServletContextFacade(server, this);
       }
   
  @@ -199,11 +216,17 @@
       }
   
       public RequestSecurityProvider getRequestSecurityProvider() {
  +	if ( rsProvider==null)
  +	    rsProvider=DefaultRequestSecurityProvider.getInstance();
  +	
   	return this.rsProvider;
       }
   
       public File getWorkDir() {
  -        return this.workDir;
  +	if( workDir==null)
  +	    workDir=new File(System.getProperty("user.dir", ".") +
  +			     System.getProperty("file.separator") + Constants.WORK_DIR);
  +	return workDir;
       }
   
       public void setWorkDir(String workDir, boolean isWorkDirPersistent) {
  @@ -218,19 +241,11 @@
       }
   
       public void setWorkDir(File workDir, boolean isWorkDirPersistent) {
  -        this.isWorkDirPersistent = isWorkDirPersistent;
  -
  -	if (workDir == null) {
  -	    workDir = this.workDir;
  -	}
  -
  -	if (! isWorkDirPersistent) {
  -	    clearDir(workDir);
  -        }
  -
   	this.workDir = workDir;
  +        this.isWorkDirPersistent = isWorkDirPersistent;
  +	// assert workDir!=null - or no reason to set it
   
  -	setAttribute(Constants.Attribute.WorkDirectory, this.workDir);
  +	// workDir will be cleaned at init() and shutdown()
       }
   
       public boolean isWorkDirPersistent() {
  @@ -241,6 +256,10 @@
           return this.warDir;
       }
   
  +    public void setWARDir( File f ) {
  +	warDir=f;
  +    }
  +
       public boolean isWARExpanded() {
           return this.isWARExpanded;
       }
  @@ -340,127 +359,32 @@
        */
       
       public synchronized void init() {
  -	// check to see if we've already been init'd
  -
   	if (this.initialized) {
   	    String msg = sm.getString("context.init.alreadyinit");
  -
   	    throw new IllegalStateException(msg);
   	}
  -
   	this.initialized = true;
  -	
  -	if (this.docBase == null) {
  -	    //String msg = sm.getString("context.init.nodocbase");
  -	    //throw new IllegalStateException(msg);
  -
  -	    // XXX
  -	    // for now we are going to pretend it doens't matter
  -	}
   
  -	// set up work dir attribute
  -
  -	if (this.workDir != null) {
  -	    setAttribute(Constants.Context.Attribute.WorkDir.Name,
  -	        this.workDir);
  -
  -	    if (! this.workDir.exists()) {
  -	        this.workDir.mkdirs();
  -	    }
  -	}
  -
  -	// expand WAR
  +	// Set defaults if not already there
  +	new DefaultContextSetter().handleContextInit( this );
  +	
  +	// set up work dir ( attribute + creation )
  +	new WorkDirInterceptor().handleContextInit( this );
   
  +	// XXX who uses servletBase ???
   	URL servletBase = this.docBase;
  -
  -	if (docBase.getProtocol().equalsIgnoreCase("war")) {
  -	    if (isWARExpanded()) {
  -	        this.warDir = new File(getWorkDir(),
  -		    Constants.Context.WARExpandDir);
  -
  -		if (! this.warDir.exists()) {
  -		    this.warDir.mkdirs();
  -
  -		    try {
  -		        WARUtil.expand(this.warDir, getDocumentBase());
  -		    } catch (MalformedURLException mue) {
  -		    } catch (IOException ioe) {
  -		    }
  -
  -		    try {
  -                        servletBase = URLUtil.resolve(this.warDir.toString());
  -		    } catch (Exception e) {
  -		    }
  -		}
  -	    }
  -	}
  -
           this.setServletBase(servletBase);
  -
  -        for (int i = 0; i < Constants.Context.CLASS_PATHS.length; i++) {
  -            this.addClassPath(Constants.Context.CLASS_PATHS[i]);
  -	}
  -
  -        for (int i = 0; i < Constants.Context.LIB_PATHS.length; i++) {
  -            this.addLibPath(Constants.Context.LIB_PATHS[i]);
  -	}
  -
  -	// process base configuration
  -
  -	try {
  -	    Class webApplicationDescriptor = Class.forName(
  -	        "org.apache.tomcat.deployment.WebApplicationDescriptor");
  -	    InputStream is =
  -	        webApplicationDescriptor.getResourceAsStream(
  -	            org.apache.tomcat.deployment.Constants.ConfigFile);
  -	    String msg = sm.getString("context.getConfig.msg", "default");
  -
  -    	    System.out.println(msg);
  -
  -	    processWebApp(is, true);
  -	} catch (Exception e) {
  -	    String msg = sm.getString("context.getConfig.e", "default");
  -
  -	    System.out.println(msg);
  -	}
  -
  -	// process webApp configuration
  -
  -	String s = docBase.toString();
  -
  -	if (docBase.getProtocol().equalsIgnoreCase("war")) {
  -	    if (s.endsWith("/")) {
  -	        s = s.substring(0, s.length() - 1);
  -	    }
  -
  -	    s += "!/";
  -	}
  -
  -	URL webURL = null;
  -
  -	try {
  -	    webURL = new URL(s + Constants.Context.ConfigFile);
   
  -	    InputStream is = webURL.openConnection().getInputStream();
  -	    String msg = sm.getString("context.getConfig.msg",
  -	        webURL.toString());
  -
  -	    System.out.println(msg);
  -
  -	    processWebApp(is);
  -	} catch (Exception e) {
  -	    String msg = sm.getString("context.getConfig.e",
  -	        (webURL != null) ? webURL.toString() : "not available");
  -
  -            // go silent on this one
  -	    // System.out.println(msg);
  -	}
  +	// expand WAR
  +	new WarInterceptor().handleContextInit( this );
   
  +	// Read context's web.xml
  +	new WebXmlInterceptor().handleContextInit( this );
  +	
   	if (! this.isInvokerEnabled) {
   	    // Put in a special "no invoker" that handles
   	    // /servlet requests and explains why no servlet
   	    // is being invoked
  -
   	    this.addServlet(Constants.Servlet.NoInvoker.Name,
   	        Constants.Servlet.NoInvoker.Class);
   	    this.addMapping(Constants.Servlet.NoInvoker.Name,
  @@ -468,7 +392,6 @@
   	}
   
   	// load-on-startup
  -
           if (! loadableServlets.isEmpty()) {
   	    loadServlets();
           }
  @@ -500,22 +423,33 @@
   	// shut down any sessions
   
   	getSessionManager().removeSessions(this);
  -
  -	if (! isWorkDirPersistent) {
  -            clearDir(workDir);
  -	}
   
  +	new WorkDirInterceptor().handleContextShutdown(this);
  +	
   	System.out.println("Context: " + this + " down");
       }
       
       public Enumeration getWelcomeFiles() {
   	return welcomeFiles.elements();
       }
  +
  +    public void removeWelcomeFiles() {
  +	if( ! this.welcomeFiles.isEmpty() )
  +	    this.welcomeFiles.removeAllElements();
  +    }
  +
  +    public void addWelcomeFile( String s) {
  +	welcomeFiles.addElement( s );
  +    }
       
       public String getInitParameter(String name) {
           return (String)initializationParameters.get(name);
       }
   
  +    public void setInitParameter( String name, String value ) {
  +	initializationParameters.put(name, value );
  +    }
  +    
       public Enumeration getInitParameterNames() {
           return initializationParameters.keys();
       }
  @@ -591,10 +525,18 @@
           return mimeTypes;
       }
   
  +    public void addContentType( String ext, String type) {
  +	mimeTypes.addContentType( ext, type );
  +    }
  +
       public String getErrorPage(int errorCode) {
           return getErrorPage(String.valueOf(errorCode));
       }
   
  +    public void addErrorPage( String errorType, String value ) {
  +	this.errorPages.put( errorPages, value );
  +    }
  +
       public String getErrorPage(String errorCode) {
           return (String)errorPages.get(errorCode);
       }
  @@ -603,265 +545,30 @@
           return contextFacade;
       }
   
  -    private Properties getProperties(String propertyFileName) {
  -        Properties props = new Properties();
  -
  -        try {
  -	    props.load(this.getClass().getResourceAsStream(propertyFileName));
  -	} catch (IOException ioe) {
  -	}
  -
  -	return props;
  -    }
  -
  -    private void clearDir(File dir) {
  -        String[] files = dir.list();
  -
  -        if (files != null) {
  -	    for (int i = 0; i < files.length; i++) {
  -	        File f = new File(dir, files[i]);
  -
  -	        if (f.isDirectory()) {
  -		    clearDir(f);
  -	        }
  -
  -	        try {
  -	            f.delete();
  -	        } catch (Exception e) {
  -	        }
  -	    }
  -
  -	    try {
  -	        dir.delete();
  -	    } catch (Exception e) {
  -	    }
  -        }
  -    }
  -
  -    private void processWebApp(InputStream is) {
  -        processWebApp(is, false);
  -    }
  -
  -    private void processWebApp(InputStream is, boolean internal) {
  -        if (is != null) {
  -	    try {
  -	        WebApplicationDescriptor webDescriptor =
  -		    (new WebApplicationReader()).getDescriptor(is,
  -		        new WebDescriptorFactoryImpl(),
  -			isWARValidated());
  -
  -		processDescription(webDescriptor.getDescription());
  -		processDistributable(webDescriptor.isDistributable());
  -		processInitializationParameters(
  -		    webDescriptor.getContextParameters());
  -		processSessionTimeOut(webDescriptor.getSessionTimeout());
  -		processServlets(webDescriptor.getWebComponentDescriptors());
  -		processMimeMaps(webDescriptor.getMimeMappings());
  -		processWelcomeFiles(webDescriptor.getWelcomeFiles(),
  -                    internal);
  -		processErrorPages(webDescriptor.getErrorPageDescriptors());
  -	    } catch (Throwable e) {
  -                String msg = "config parse: " + e.getMessage();
  -
  -                System.out.println(msg);
  -	    }
  -	}
  -    }
  -
  -    private void processDescription(String description) {
  -        this.description = description;
  -    }
   
  -    private void processDistributable(boolean isDistributable) {
  -        this.isDistributable = isDistributable;
  +    public Enumeration getInitLevles() {
  +	return loadableServlets.keys();
       }
   
  -    private void processInitializationParameters(
  -	Enumeration contextParameters) {
  -        while (contextParameters.hasMoreElements()) {
  -	    ContextParameter contextParameter =
  -	        (ContextParameter)contextParameters.nextElement();
  -	    initializationParameters.put(contextParameter.getName(),
  -	        contextParameter.getValue());
  -	}
  +    public Enumeration getLoadableServlets( Integer level ) {
  +	return ((Vector)loadableServlets.get( level )).elements();
       }
   
  -    private void processSessionTimeOut(int sessionTimeOut) {
  -        this.sessionTimeOut = sessionTimeOut;
  +    public void setLoadableServlets( Integer level, Vector servlets ) {
  +	loadableServlets.put( level, servlets );
       }
  -
  -    private void processServlets(Enumeration servlets) {
  -        // XXX
  -        // oh my ... this has suddenly turned rather ugly
  -        // perhaps the reader should do this normalization work
  -
  -        while (servlets.hasMoreElements()) {
  -	    WebComponentDescriptor webComponentDescriptor =
  -	        (WebComponentDescriptor)servlets.nextElement();
  -	    String name = webComponentDescriptor.getCanonicalName();
  -	    String description = webComponentDescriptor.getDescription();
  -	    String resourceName = null;
  -	    boolean removeResource = false;
  -
  -	    if (webComponentDescriptor instanceof ServletDescriptor) {
  -		resourceName =
  -		    ((ServletDescriptor)webComponentDescriptor).getClassName();
  -
  -		if (containsServletByName(name)) {
  -		    String msg = sm.getString("context.dd.dropServlet",
  -		        name + "(" + resourceName + ")" );
  -
  -		    System.out.println(msg);
  -		    
  -		    removeResource = true;
  -		    removeServletByName(name);
  -		}
   
  -		addServlet(name, resourceName, description);
  -	    } else if (webComponentDescriptor instanceof JspDescriptor) {
  -		resourceName =
  -		    ((JspDescriptor)webComponentDescriptor).getJspFileName();
  -
  -		if (! resourceName.startsWith("/")) {
  -		    resourceName = "/" + resourceName;
  -		}
  -
  -		if (containsJSP(resourceName)) {
  -		    String msg = sm.getString("context.dd.dropServlet",
  -		        resourceName);
  -
  -		    System.out.println(msg);
  -
  -		    removeResource = true;
  -		    removeJSP(resourceName);
  -		}
  -
  -		addJSP(name, resourceName, description);
  -	    }
  -
  -	    if (removeResource) {
  -	        Enumeration enum = loadableServlets.keys();
  -
  -		while (enum.hasMoreElements()) {
  -		    Integer key = (Integer)enum.nextElement();
  -		    Vector v = (Vector)loadableServlets.get(key);
  -
  -		    Enumeration e = v.elements();
  -		    Vector buf = new Vector();
  -
  -		    while (e.hasMoreElements()) {
  -		        String servletName = (String)e.nextElement();
  -
  -			if (containsServletByName(servletName)) {
  -			    buf.addElement(servletName);
  -			}
  -		    }
  -
  -		    loadableServlets.put(key, buf);
  -		}
  -	    }
  -
  -	    int loadOnStartUp = webComponentDescriptor.getLoadOnStartUp();
  -
  -            if (loadOnStartUp > Integer.MIN_VALUE) {
  -	        Integer key = new Integer(loadOnStartUp);
  -		Vector v = (Vector)((loadableServlets.containsKey(key)) ?
  -		    loadableServlets.get(key) : new Vector());
  -
  -		v.addElement(name);
  -		loadableServlets.put(key, v);
  -	    }
  -
  -	    Enumeration enum =
  -	        webComponentDescriptor.getInitializationParameters();
  -	    Hashtable initializationParameters = new Hashtable();
  -
  -	    while (enum.hasMoreElements()) {
  -	        InitializationParameter initializationParameter =
  -		    (InitializationParameter)enum.nextElement();
  -
  -		initializationParameters.put(
  -		    initializationParameter.getName(),
  -		    initializationParameter.getValue());
  -	    }
  -
  -	    setServletInitParams(webComponentDescriptor.getCanonicalName(),
  -				 initializationParameters);
  -
  -	    enum = webComponentDescriptor.getUrlPatterns();
  -
  -	    while (enum.hasMoreElements()) {
  -	        String mapping = (String)enum.nextElement();
  -
  -		if (! mapping.startsWith("*.") &&
  -		    ! mapping.startsWith("/")) {
  -		    mapping = "/" + mapping;
  -		}
  -
  -		if (! containsServlet(mapping) &&
  -		    ! containsJSP(mapping)) {
  -		    if (containsMapping(mapping)) {
  -		        String msg = sm.getString("context.dd.dropMapping",
  -			    mapping);
  -
  -			System.out.println(msg);
  -
  -			removeMapping(mapping);
  -		    }
  -
  -                    addMapping(name, mapping);
  -		} else {
  -		    String msg = sm.getString("context.dd.ignoreMapping",
  -		        mapping);
  -
  -		    System.out.println(msg);
  -		}
  -	    }
  -	}
  -    }
  -
  -    private void processMimeMaps(Enumeration mimeMaps) {
  -        while (mimeMaps.hasMoreElements()) {
  -	    MimeMapping mimeMapping = (MimeMapping)mimeMaps.nextElement();
  -
  -	    this.mimeTypes.addContentType(
  -	        mimeMapping.getExtension(), mimeMapping.getMimeType());
  -	}
  -    }
  -
  -    private void processWelcomeFiles(Enumeration welcomeFiles) {
  -        processWelcomeFiles(welcomeFiles, false);
  -    }
  -
  -    private void processWelcomeFiles(Enumeration welcomeFiles,
  -        boolean internal) {
  -        if (! internal &&
  -            ! this.welcomeFiles.isEmpty() &&
  -            welcomeFiles.hasMoreElements()) {
  -            this.welcomeFiles.removeAllElements();
  -        }
  -
  -	while (welcomeFiles.hasMoreElements()) {
  -	    this.welcomeFiles.addElement(welcomeFiles.nextElement());
  -	}
  -    }
  -
  -    private void processErrorPages(Enumeration errorPages) {
  -        while (errorPages.hasMoreElements()) {
  -	    ErrorPageDescriptor errorPageDescriptor =
  -	        (ErrorPageDescriptor)errorPages.nextElement();
  -	    String key = null;
  -
  -	    if (errorPageDescriptor.getErrorCode() > -1) {
  -	        key = String.valueOf(errorPageDescriptor.getErrorCode());
  -	    } else {
  -	        key = errorPageDescriptor.getExceptionType();
  -	    }
  -
  -	    this.errorPages.put(key, errorPageDescriptor.getLocation());
  -	}
  +    public void addLoadableServlet( Integer level,String name ) {
  +	Vector v;
  +	if( loadableServlets.get(level) != null ) 
  +	    v=(Vector)loadableServlets.get(level);
  +	else
  +	    v=new Vector();
  +	
  +	v.addElement(name);
  +	loadableServlets.put(level, v);
       }
  -
  +    
       private void loadServlets() {
   	Vector orderedKeys = new Vector();
   	Enumeration e = loadableServlets.keys();
  @@ -974,7 +681,7 @@
   
       /** True if we have a servlet with className.
        */
  -    boolean containsServlet(String className) {
  +    public boolean containsServlet(String className) {
           ServletWrapper[] sw = getServlets(className);
   
           return (sw != null &&
  @@ -983,7 +690,7 @@
   
       /** Check if we have a servlet with the specified name
        */
  -    boolean containsServletByName(String name) {
  +    public boolean containsServletByName(String name) {
   	return (servlets.containsKey(name));
       }
   
  @@ -995,21 +702,21 @@
   
       /** Remove the servlet with a specific name
        */
  -    void removeServletByName(String servletName) {
  +    public void removeServletByName(String servletName) {
   	ServletWrapper wrapper=(ServletWrapper)servlets.get(servletName);
   	if( wrapper != null ) {
   	    removeServlet( wrapper );
   	}
       }
   
  -    boolean containsJSP(String path) {
  +    public boolean containsJSP(String path) {
           ServletWrapper[] sw = getServletsByPath(path);
   
           return (sw != null &&
   	    sw.length > 0);
       }
   
  -    void removeJSP(String path) {
  +    public void removeJSP(String path) {
   	Enumeration enum = servlets.keys();
   
   	while (enum.hasMoreElements()) {
  @@ -1094,7 +801,7 @@
   	return extensionMappedServlets;
       }
       
  -    boolean containsMapping(String mapping) {
  +    public boolean containsMapping(String mapping) {
           mapping = mapping.trim();
   
           return (prefixMappedServlets.containsKey(mapping) ||
  @@ -1102,7 +809,7 @@
   	    pathMappedServlets.containsKey(mapping));
       }
   
  -    void removeMapping(String mapping) {
  +    public void removeMapping(String mapping) {
           mapping = mapping.trim();
   
   	prefixMappedServlets.remove(mapping);
  
  
  
  1.6       +8 -7      jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java
  
  Index: ContextManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ContextManager.java	2000/01/07 19:14:11	1.5
  +++ ContextManager.java	2000/01/08 22:55:45	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v 1.5 2000/01/07 19:14:11 costin Exp $
  - * $Revision: 1.5 $
  - * $Date: 2000/01/07 19:14:11 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v 1.6 2000/01/08 22:55:45 costin Exp $
  + * $Revision: 1.6 $
  + * $Date: 2000/01/08 22:55:45 $
    *
    * ====================================================================
    *
  @@ -284,11 +284,12 @@
   	    throw new IllegalStateException(msg);
   	}
   
  -	Context context = new Context(this, path);
  -
  -	if (docBase != null) {
  -	    context.setDocumentBase(docBase);
  +	if (docBase == null) {
  +	    throw new RuntimeException("XXX SHOULD NEVER HAPPEN");
   	}
  +
  +	Context context = new Context(this, path, docBase);
  +
   
   	// check to see if defaultContext