FileDocCategorySizeDatePackage
UserConfig.javaAPI DocApache Tomcat 6.0.149208Fri Jul 20 04:20:34 BST 2007org.apache.catalina.startup

UserConfig

public final class UserConfig extends Object implements org.apache.catalina.LifecycleListener
Startup event listener for a Host that configures Contexts (web applications) for all defined "users" who have a web application in a directory with the specified name in their home directories. The context path of each deployed application will be set to ~xxxxx, where xxxxx is the username of the owning user for that web application
author
Craig R. McClanahan
version
$Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $

Fields Summary
private static org.apache.juli.logging.Log
log
private String
configClass
The Java class name of the Context configuration class we should use.
private String
contextClass
The Java class name of the Context implementation we should use.
private String
directoryName
The directory name to be searched for within each user home directory.
private String
homeBase
The base directory containing user home directories.
private org.apache.catalina.Host
host
The Host we are associated with.
private static final org.apache.catalina.util.StringManager
sm
The string resources for this package.
private String
userClass
The Java class name of the user database class we should use.
Constructors Summary
Methods Summary
private voiddeploy()
Deploy a web application for any user who has a web application present in a directory with a specified name within their home directory.


        if (host.getLogger().isDebugEnabled())
            host.getLogger().debug(sm.getString("userConfig.deploying"));

        // Load the user database object for this host
        UserDatabase database = null;
        try {
            Class clazz = Class.forName(userClass);
            database = (UserDatabase) clazz.newInstance();
            database.setUserConfig(this);
        } catch (Exception e) {
            host.getLogger().error(sm.getString("userConfig.database"), e);
            return;
        }

        // Deploy the web application (if any) for each defined user
        Enumeration users = database.getUsers();
        while (users.hasMoreElements()) {
            String user = (String) users.nextElement();
            String home = database.getHome(user);
            deploy(user, home);
        }

    
private voiddeploy(java.lang.String user, java.lang.String home)
Deploy a web application for the specified user if they have such an application in the defined directory within their home directory.

param
user Username owning the application to be deployed
param
home Home directory of this user


        // Does this user have a web application to be deployed?
        String contextPath = "/~" + user;
        if (host.findChild(contextPath) != null)
            return;
        File app = new File(home, directoryName);
        if (!app.exists() || !app.isDirectory())
            return;
        /*
        File dd = new File(app, "/WEB-INF/web.xml");
        if (!dd.exists() || !dd.isFile() || !dd.canRead())
            return;
        */
        host.getLogger().info(sm.getString("userConfig.deploy", user));

        // Deploy the web application for this user
        try {
            Class clazz = Class.forName(contextClass);
            Context context =
              (Context) clazz.newInstance();
            context.setPath(contextPath);
            context.setDocBase(app.toString());
            if (context instanceof Lifecycle) {
                clazz = Class.forName(configClass);
                LifecycleListener listener =
                  (LifecycleListener) clazz.newInstance();
                ((Lifecycle) context).addLifecycleListener(listener);
            }
            host.addChild(context);
        } catch (Exception e) {
            host.getLogger().error(sm.getString("userConfig.error", user), e);
        }

    
public java.lang.StringgetConfigClass()
Return the Context configuration class name.



    // ------------------------------------------------------------- Properties


               
       

        return (this.configClass);

    
public java.lang.StringgetContextClass()
Return the Context implementation class name.


        return (this.contextClass);

    
public java.lang.StringgetDirectoryName()
Return the directory name for user web applications.


        return (this.directoryName);

    
public java.lang.StringgetHomeBase()
Return the base directory containing user home directories.


        return (this.homeBase);

    
public java.lang.StringgetUserClass()
Return the user database class name for this component.


        return (this.userClass);

    
public voidlifecycleEvent(org.apache.catalina.LifecycleEvent event)
Process the START event for an associated Host.

param
event The lifecycle event that has occurred


        // Identify the host we are associated with
        try {
            host = (Host) event.getLifecycle();
        } catch (ClassCastException e) {
            log.error(sm.getString("hostConfig.cce", event.getLifecycle()), e);
            return;
        }

        // Process the event that has occurred
        if (event.getType().equals(Lifecycle.START_EVENT))
            start();
        else if (event.getType().equals(Lifecycle.STOP_EVENT))
            stop();

    
public voidsetConfigClass(java.lang.String configClass)
Set the Context configuration class name.

param
configClass The new Context configuration class name.


        this.configClass = configClass;

    
public voidsetContextClass(java.lang.String contextClass)
Set the Context implementation class name.

param
contextClass The new Context implementation class name.


        this.contextClass = contextClass;

    
public voidsetDirectoryName(java.lang.String directoryName)
Set the directory name for user web applications.

param
directoryName The new directory name


        this.directoryName = directoryName;

    
public voidsetHomeBase(java.lang.String homeBase)
Set the base directory containing user home directories.

param
homeBase The new base directory


        this.homeBase = homeBase;

    
public voidsetUserClass(java.lang.String userClass)
Set the user database class name for this component.


        this.userClass = userClass;

    
private voidstart()
Process a "start" event for this Host.


        if (host.getLogger().isDebugEnabled())
            host.getLogger().debug(sm.getString("userConfig.start"));

        deploy();

    
private voidstop()
Process a "stop" event for this Host.


        if (host.getLogger().isDebugEnabled())
            host.getLogger().debug(sm.getString("userConfig.stop"));