changeset 3:3ab011b6e6e8

Cleaner refactored version.
author Mikhail Kryshen <mikhail@kryshen.net>
date Fri, 30 Oct 2009 05:12:58 +0300
parents d11df03af52a
children 6ef7cbf5c8d6
files nbproject/build-impl.xml nbproject/genfiles.properties nbproject/project.properties src/kryshen/catalina/startup/HomesUserDatabase.java src/kryshen/catalina/startup/UserConfig.java src/kryshen/catalina/startup/UserConfig2.java src/kryshen/catalina/startup/UserDatabase.java
diffstat 7 files changed, 271 insertions(+), 224 deletions(-) [+]
line diff
     1.1 --- a/nbproject/build-impl.xml	Fri Oct 30 03:54:56 2009 +0300
     1.2 +++ b/nbproject/build-impl.xml	Fri Oct 30 05:12:58 2009 +0300
     1.3 @@ -20,6 +20,13 @@
     1.4  
     1.5          -->
     1.6  <project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="tomcat-userconfig-impl">
     1.7 +    <fail message="Please build using Ant 1.7.1 or higher.">
     1.8 +        <condition>
     1.9 +            <not>
    1.10 +                <antversion atleast="1.7.1"/>
    1.11 +            </not>
    1.12 +        </condition>
    1.13 +    </fail>
    1.14      <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
    1.15      <!-- 
    1.16                  ======================
    1.17 @@ -152,10 +159,18 @@
    1.18              <attribute default="${includes}" name="includes"/>
    1.19              <attribute default="${excludes}" name="excludes"/>
    1.20              <attribute default="${javac.debug}" name="debug"/>
    1.21 -            <attribute default="/does/not/exist" name="sourcepath"/>
    1.22 +            <attribute default="${empty.dir}" name="sourcepath"/>
    1.23 +            <attribute default="${empty.dir}" name="gensrcdir"/>
    1.24              <element name="customize" optional="true"/>
    1.25              <sequential>
    1.26 +                <property location="${build.dir}/empty" name="empty.dir"/>
    1.27 +                <mkdir dir="${empty.dir}"/>
    1.28                  <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}">
    1.29 +                    <src>
    1.30 +                        <dirset dir="@{gensrcdir}" erroronmissingdir="false">
    1.31 +                            <include name="*"/>
    1.32 +                        </dirset>
    1.33 +                    </src>
    1.34                      <classpath>
    1.35                          <path path="@{classpath}"/>
    1.36                      </classpath>
    1.37 @@ -271,6 +286,8 @@
    1.38                  <java classname="@{classname}" dir="${work.dir}" fork="true">
    1.39                      <jvmarg line="${debug-args-line}"/>
    1.40                      <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
    1.41 +                    <jvmarg value="-Dfile.encoding=${source.encoding}"/>
    1.42 +                    <redirector errorencoding="${source.encoding}" inputencoding="${source.encoding}" outputencoding="${source.encoding}"/>
    1.43                      <jvmarg line="${run.jvmargs}"/>
    1.44                      <classpath>
    1.45                          <path path="@{classpath}"/>
    1.46 @@ -287,12 +304,15 @@
    1.47      <target name="-init-macrodef-java">
    1.48          <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
    1.49              <attribute default="${main.class}" name="classname"/>
    1.50 +            <attribute default="${run.classpath}" name="classpath"/>
    1.51              <element name="customize" optional="true"/>
    1.52              <sequential>
    1.53                  <java classname="@{classname}" dir="${work.dir}" fork="true">
    1.54 +                    <jvmarg value="-Dfile.encoding=${source.encoding}"/>
    1.55 +                    <redirector errorencoding="${source.encoding}" inputencoding="${source.encoding}" outputencoding="${source.encoding}"/>
    1.56                      <jvmarg line="${run.jvmargs}"/>
    1.57                      <classpath>
    1.58 -                        <path path="${run.classpath}"/>
    1.59 +                        <path path="@{classpath}"/>
    1.60                      </classpath>
    1.61                      <syspropertyset>
    1.62                          <propertyref prefix="run-sys-prop."/>
    1.63 @@ -332,10 +352,15 @@
    1.64          <!-- You can override this target in the ../build.xml file. -->
    1.65      </target>
    1.66      <target if="do.depend.true" name="-compile-depend">
    1.67 -        <j2seproject3:depend/>
    1.68 +        <pathconvert property="build.generated.subdirs">
    1.69 +            <dirset dir="${build.generated.sources.dir}" erroronmissingdir="false">
    1.70 +                <include name="*"/>
    1.71 +            </dirset>
    1.72 +        </pathconvert>
    1.73 +        <j2seproject3:depend srcdir="${src.dir}:${build.generated.subdirs}"/>
    1.74      </target>
    1.75      <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-compile-depend" if="have.sources" name="-do-compile">
    1.76 -        <j2seproject3:javac/>
    1.77 +        <j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
    1.78          <copy todir="${build.classes.dir}">
    1.79              <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
    1.80          </copy>
    1.81 @@ -352,7 +377,7 @@
    1.82      <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
    1.83          <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
    1.84          <j2seproject3:force-recompile/>
    1.85 -        <j2seproject3:javac excludes="" includes="${javac.includes}" sourcepath="${src.dir}"/>
    1.86 +        <j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.dir}"/>
    1.87      </target>
    1.88      <target name="-post-compile-single">
    1.89          <!-- Empty placeholder for easier customization. -->
    1.90 @@ -418,11 +443,29 @@
    1.91          <property location="${dist.jar}" name="dist.jar.resolved"/>
    1.92          <echo>java -jar "${dist.jar.resolved}"</echo>
    1.93      </target>
    1.94 +    <target depends="init,compile,-pre-pre-jar,-pre-jar" if="libs.CopyLibs.classpath" name="-do-jar-with-libraries-without-manifest" unless="manifest.available+main.class">
    1.95 +        <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
    1.96 +        <pathconvert property="run.classpath.without.build.classes.dir">
    1.97 +            <path path="${run.classpath}"/>
    1.98 +            <map from="${build.classes.dir.resolved}" to=""/>
    1.99 +        </pathconvert>
   1.100 +        <pathconvert pathsep=" " property="jar.classpath">
   1.101 +            <path path="${run.classpath.without.build.classes.dir}"/>
   1.102 +            <chainedmapper>
   1.103 +                <flattenmapper/>
   1.104 +                <globmapper from="*" to="lib/*"/>
   1.105 +            </chainedmapper>
   1.106 +        </pathconvert>
   1.107 +        <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
   1.108 +        <copylibs compress="${jar.compress}" jarfile="${dist.jar}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
   1.109 +            <fileset dir="${build.classes.dir}"/>
   1.110 +        </copylibs>
   1.111 +    </target>
   1.112      <target name="-post-jar">
   1.113          <!-- Empty placeholder for easier customization. -->
   1.114          <!-- You can override this target in the ../build.xml file. -->
   1.115      </target>
   1.116 -    <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
   1.117 +    <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-do-jar-with-libraries-without-manifest,-post-jar" description="Build JAR." name="jar"/>
   1.118      <!--
   1.119                  =================
   1.120                  EXECUTION SECTION
   1.121 @@ -442,6 +485,10 @@
   1.122          <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
   1.123          <j2seproject1:java classname="${run.class}"/>
   1.124      </target>
   1.125 +    <target depends="init,-do-not-recompile,compile-test-single" name="run-test-with-main">
   1.126 +        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
   1.127 +        <j2seproject1:java classname="${run.class}" classpath="${run.test.classpath}"/>
   1.128 +    </target>
   1.129      <!--
   1.130                  =================
   1.131                  DEBUGGING SECTION
   1.132 @@ -450,6 +497,9 @@
   1.133      <target depends="init" if="netbeans.home" name="-debug-start-debugger">
   1.134          <j2seproject1:nbjpdastart name="${debug.class}"/>
   1.135      </target>
   1.136 +    <target depends="init" if="netbeans.home" name="-debug-start-debugger-main-test">
   1.137 +        <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${debug.class}"/>
   1.138 +    </target>
   1.139      <target depends="init,compile" name="-debug-start-debuggee">
   1.140          <j2seproject3:debug>
   1.141              <customize>
   1.142 @@ -467,6 +517,11 @@
   1.143          <j2seproject3:debug classname="${debug.class}"/>
   1.144      </target>
   1.145      <target depends="init,-do-not-recompile,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/>
   1.146 +    <target depends="init,compile-test-single" if="netbeans.home" name="-debug-start-debuggee-main-test">
   1.147 +        <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
   1.148 +        <j2seproject3:debug classname="${debug.class}" classpath="${debug.test.classpath}"/>
   1.149 +    </target>
   1.150 +    <target depends="init,-do-not-recompile,compile-test-single,-debug-start-debugger-main-test,-debug-start-debuggee-main-test" if="netbeans.home" name="debug-test-with-main"/>
   1.151      <target depends="init" name="-pre-debug-fix">
   1.152          <fail unless="fix.includes">Must set fix.includes</fail>
   1.153          <property name="javac.includes" value="${fix.includes}.java"/>
   1.154 @@ -489,6 +544,9 @@
   1.155              <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
   1.156                  <filename name="**/*.java"/>
   1.157              </fileset>
   1.158 +            <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
   1.159 +                <include name="**/*.java"/>
   1.160 +            </fileset>
   1.161          </javadoc>
   1.162      </target>
   1.163      <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview">
   1.164 @@ -550,7 +608,7 @@
   1.165          <j2seproject3:junit testincludes="**/*Test.java"/>
   1.166      </target>
   1.167      <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
   1.168 -        <fail if="tests.failed">Some tests failed; see details above.</fail>
   1.169 +        <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
   1.170      </target>
   1.171      <target depends="init" if="have.tests" name="test-report"/>
   1.172      <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/>
   1.173 @@ -563,7 +621,7 @@
   1.174          <j2seproject3:junit excludes="" includes="${test.includes}"/>
   1.175      </target>
   1.176      <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
   1.177 -        <fail if="tests.failed">Some tests failed; see details above.</fail>
   1.178 +        <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
   1.179      </target>
   1.180      <target depends="init,-do-not-recompile,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
   1.181      <!--
     2.1 --- a/nbproject/genfiles.properties	Fri Oct 30 03:54:56 2009 +0300
     2.2 +++ b/nbproject/genfiles.properties	Fri Oct 30 05:12:58 2009 +0300
     2.3 @@ -1,8 +1,8 @@
     2.4  build.xml.data.CRC32=8168bf3c
     2.5  build.xml.script.CRC32=d8558c95
     2.6 -build.xml.stylesheet.CRC32=958a1d3e
     2.7 +build.xml.stylesheet.CRC32=958a1d3e@1.26.2.45
     2.8  # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
     2.9  # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
    2.10  nbproject/build-impl.xml.data.CRC32=8168bf3c
    2.11 -nbproject/build-impl.xml.script.CRC32=22b92b6d
    2.12 -nbproject/build-impl.xml.stylesheet.CRC32=65b8de21
    2.13 +nbproject/build-impl.xml.script.CRC32=92172d17
    2.14 +nbproject/build-impl.xml.stylesheet.CRC32=5c621a33@1.26.2.45
     3.1 --- a/nbproject/project.properties	Fri Oct 30 03:54:56 2009 +0300
     3.2 +++ b/nbproject/project.properties	Fri Oct 30 05:12:58 2009 +0300
     3.3 @@ -8,6 +8,7 @@
     3.4  # This directory is removed when the project is cleaned:
     3.5  build.dir=build
     3.6  build.generated.dir=${build.dir}/generated
     3.7 +build.generated.sources.dir=${build.dir}/generated-sources
     3.8  # Only compile against the classpath explicitly listed here:
     3.9  build.sysclasspath=ignore
    3.10  build.test.classes.dir=${build.dir}/test/classes
    3.11 @@ -71,6 +72,6 @@
    3.12      ${javac.test.classpath}:\
    3.13      ${build.test.classes.dir}
    3.14  source.encoding=UTF-8
    3.15 -source.reference.catalina.jar=../../../misc/build/apache-tomcat-6.0.20-src/java
    3.16 +source.reference.catalina.jar=${var.tomcat-src}/!/apache-tomcat-6.0.20-src/java/
    3.17  src.dir=src
    3.18  test.src.dir=test
     4.1 --- a/src/kryshen/catalina/startup/HomesUserDatabase.java	Fri Oct 30 03:54:56 2009 +0300
     4.2 +++ b/src/kryshen/catalina/startup/HomesUserDatabase.java	Fri Oct 30 05:12:58 2009 +0300
     4.3 @@ -20,10 +20,9 @@
     4.4  
     4.5  
     4.6  import java.io.File;
     4.7 -import java.util.Hashtable;
     4.8 -import java.util.Enumeration;
     4.9 -import org.apache.catalina.startup.*;
    4.10 -
    4.11 +import java.util.Collections;
    4.12 +import java.util.HashMap;
    4.13 +import java.util.Map;
    4.14  
    4.15  /**
    4.16   * Concrete implementation of the <strong>UserDatabase</code> interface
    4.17 @@ -31,33 +30,17 @@
    4.18   * to our constructor to be "home" directories for those users.
    4.19   *
    4.20   * @author Craig R. McClanahan
    4.21 - * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (Tue, 24 Oct 2006) $
    4.22 + * @author Mikhail Kryshen
    4.23   */
    4.24  
    4.25 -public final class HomesUserDatabase
    4.26 -    implements UserDatabase {
    4.27 -
    4.28 -
    4.29 -    // --------------------------------------------------------- Constructors
    4.30 -
    4.31 -
    4.32 -    /**
    4.33 -     * Initialize a new instance of this user database component.
    4.34 -     */
    4.35 -    public HomesUserDatabase() {
    4.36 -
    4.37 -        super();
    4.38 -
    4.39 -    }
    4.40 -
    4.41 +public final class HomesUserDatabase implements UserDatabase {
    4.42  
    4.43      // --------------------------------------------------- Instance Variables
    4.44  
    4.45 -
    4.46      /**
    4.47       * The set of home directories for all defined users, keyed by username.
    4.48       */
    4.49 -    private Hashtable homes = new Hashtable();
    4.50 +    private Map<String, File> homes = new HashMap<String, File>();
    4.51  
    4.52  
    4.53      /**
    4.54 @@ -73,9 +56,7 @@
    4.55       * Return the UserConfig listener with which we are associated.
    4.56       */
    4.57      public UserConfig getUserConfig() {
    4.58 -
    4.59          return (this.userConfig);
    4.60 -
    4.61      }
    4.62  
    4.63  
    4.64 @@ -85,7 +66,6 @@
    4.65       * @param userConfig The new UserConfig listener
    4.66       */
    4.67      public void setUserConfig(UserConfig userConfig) {
    4.68 -
    4.69          this.userConfig = userConfig;
    4.70          init();
    4.71  
    4.72 @@ -100,23 +80,10 @@
    4.73       *
    4.74       * @param user User for which a home directory should be retrieved
    4.75       */
    4.76 -    public String getHome(String user) {
    4.77 -
    4.78 -        return ((String) homes.get(user));
    4.79 -
    4.80 +    public File getHome(String user) {
    4.81 +        return (homes.get(user));
    4.82      }
    4.83  
    4.84 -
    4.85 -    /**
    4.86 -     * Return an enumeration of the usernames defined on this server.
    4.87 -     */
    4.88 -    public Enumeration getUsers() {
    4.89 -
    4.90 -        return (homes.keys());
    4.91 -
    4.92 -    }
    4.93 -
    4.94 -
    4.95      // ------------------------------------------------------ Private Methods
    4.96  
    4.97  
    4.98 @@ -124,22 +91,27 @@
    4.99       * Initialize our set of users and home directories.
   4.100       */
   4.101      private void init() {
   4.102 -
   4.103          String homeBase = userConfig.getHomeBase();
   4.104          File homeBaseDir = new File(homeBase);
   4.105 -        if (!homeBaseDir.exists() || !homeBaseDir.isDirectory())
   4.106 +
   4.107 +        if (!homeBaseDir.exists() || !homeBaseDir.isDirectory()) {
   4.108              return;
   4.109 +        }
   4.110 +        
   4.111          String homeBaseFiles[] = homeBaseDir.list();
   4.112  
   4.113          for (int i = 0; i < homeBaseFiles.length; i++) {
   4.114              File homeDir = new File(homeBaseDir, homeBaseFiles[i]);
   4.115 -            if (!homeDir.isDirectory() || !homeDir.canExecute())
   4.116 +
   4.117 +            if (!homeDir.isDirectory() || !homeDir.canExecute()) {
   4.118                  continue;
   4.119 -            homes.put(homeBaseFiles[i], homeDir.toString());
   4.120 +            }
   4.121 +
   4.122 +            homes.put(homeBaseFiles[i], homeDir);
   4.123          }
   4.124 -
   4.125 -
   4.126      }
   4.127  
   4.128 -
   4.129 +    public Map<String, File> getUserHomes() {
   4.130 +        return Collections.unmodifiableMap(homes);
   4.131 +    }
   4.132  }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/kryshen/catalina/startup/UserConfig.java	Fri Oct 30 05:12:58 2009 +0300
     5.3 @@ -0,0 +1,152 @@
     5.4 +package kryshen.catalina.startup;
     5.5 +
     5.6 +import java.io.File;
     5.7 +import java.util.Map;
     5.8 +import org.apache.catalina.startup.HostConfig;
     5.9 +
    5.10 +/**
    5.11 + *
    5.12 + * @author Mikhail Kryshen
    5.13 + */
    5.14 +public class UserConfig extends HostConfig {
    5.15 +
    5.16 +    /**
    5.17 +     * The directory name to be searched for within each user home directory.
    5.18 +     */
    5.19 +    private String directoryName = "public_webapps";
    5.20 +
    5.21 +    /**
    5.22 +     * The base directory containing user home directories.
    5.23 +     */
    5.24 +    private String homeBase = null;
    5.25 +
    5.26 +    /**
    5.27 +     * The Java class name of the user database class we should use.
    5.28 +     */
    5.29 +    private String userClass =
    5.30 +            "org.apache.catalina.startup.PasswdUserDatabase";
    5.31 +
    5.32 +    /**
    5.33 +     * Return the directory name for user web applications.
    5.34 +     */
    5.35 +    public String getDirectoryName() {
    5.36 +        return (this.directoryName);
    5.37 +    }
    5.38 +
    5.39 +    /**
    5.40 +     * Set the directory name for user web applications.
    5.41 +     *
    5.42 +     * @param directoryName The new directory name
    5.43 +     */
    5.44 +    public void setDirectoryName(String directoryName) {
    5.45 +        this.directoryName = directoryName;
    5.46 +    }
    5.47 +
    5.48 +    /**
    5.49 +     * Return the base directory containing user home directories.
    5.50 +     */
    5.51 +    public String getHomeBase() {
    5.52 +        return (this.homeBase);
    5.53 +    }
    5.54 +
    5.55 +    /**
    5.56 +     * Set the base directory containing user home directories.
    5.57 +     *
    5.58 +     * @param homeBase The new base directory
    5.59 +     */
    5.60 +    public void setHomeBase(String homeBase) {
    5.61 +        this.homeBase = homeBase;
    5.62 +    }
    5.63 +
    5.64 +    /** 
    5.65 +     * Return the user database class name for this component. 
    5.66 +     */
    5.67 +    public String getUserClass() {
    5.68 +        return (this.userClass);
    5.69 +    }
    5.70 +
    5.71 +    /** 
    5.72 +     * Set the user database class name for this component. 
    5.73 +     */
    5.74 +    public void setUserClass(String userClass) {
    5.75 +        this.userClass = userClass;
    5.76 +    }
    5.77 +
    5.78 +    @Override
    5.79 +    protected void deployApps() {       
    5.80 +        // Load the user database object for this host
    5.81 +        UserDatabase database = null;
    5.82 +        try {
    5.83 +            Class clazz = Class.forName(userClass);
    5.84 +            database = (UserDatabase) clazz.newInstance();
    5.85 +            database.setUserConfig(this);
    5.86 +        } catch (Exception e) {
    5.87 +            host.getLogger().error(sm.getString("userConfig.database"), e);
    5.88 +            return;
    5.89 +        }
    5.90 +
    5.91 +        // Deploy the web application (if any) for each defined user
    5.92 +        Map<String, File> userHomes = database.getUserHomes();
    5.93 +        for (Map.Entry<String, File> entry :userHomes.entrySet()) {
    5.94 +            deployUserApps(entry.getKey(), entry.getValue());
    5.95 +        }
    5.96 +    }
    5.97 +
    5.98 +    @Override
    5.99 +    protected void deployApps(String name) {
   5.100 +        throw new UnsupportedOperationException
   5.101 +                ("deployApps(String) is not supported.");
   5.102 +    }
   5.103 +
   5.104 +    protected void deployUserApps(String user, File home) {
   5.105 +        File base = new File(home, directoryName);
   5.106 +
   5.107 +        if (!base.exists() || !base.isDirectory()) {
   5.108 +            return;
   5.109 +        }
   5.110 +
   5.111 +// TODO: deployWARs
   5.112 +//        // Deploy WARs, and loop if additional descriptors are found
   5.113 +//        deployWARs(appBase, appBase.list());
   5.114 +
   5.115 +        // Deploy expanded folders
   5.116 +        deployDirectories(user, base, base.list());
   5.117 +    }
   5.118 +
   5.119 +    /**
   5.120 +     * Deploy user webapp directories.
   5.121 +     */
   5.122 +    protected void deployDirectories(String user, File base, String[] files) {
   5.123 +
   5.124 +        if (files == null) {
   5.125 +            return;
   5.126 +        }
   5.127 +
   5.128 +        for (int i = 0; i < files.length; i++) {
   5.129 +            if (files[i].equalsIgnoreCase("META-INF")) {
   5.130 +                continue;
   5.131 +            }
   5.132 +
   5.133 +            if (files[i].equalsIgnoreCase("WEB-INF")) {
   5.134 +                continue;
   5.135 +            }
   5.136 +
   5.137 +            File dir = new File(base, files[i]);
   5.138 +            if (dir.isDirectory()) {
   5.139 +                String contextPath;
   5.140 +                
   5.141 +                if (files[i].equals("ROOT")) {
   5.142 +                    contextPath = "/~" + user;
   5.143 +                } else {
   5.144 +                    contextPath = "/~" + user + '/' + files[i].replace('#', '/');
   5.145 +                }
   5.146 +
   5.147 +                if (isServiced(contextPath)) {
   5.148 +                    continue;
   5.149 +                }
   5.150 +
   5.151 +                deployDirectory(contextPath, dir, dir.getAbsolutePath());
   5.152 +            }
   5.153 +        }
   5.154 +    }
   5.155 +}
     6.1 --- a/src/kryshen/catalina/startup/UserConfig2.java	Fri Oct 30 03:54:56 2009 +0300
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,164 +0,0 @@
     6.4 -package kryshen.catalina.startup;
     6.5 -
     6.6 -import java.io.File;
     6.7 -import java.util.Enumeration;
     6.8 -import org.apache.catalina.startup.UserDatabase;
     6.9 -import org.apache.catalina.startup.HostConfig;
    6.10 -import org.apache.catalina.startup.UserConfig;
    6.11 -
    6.12 -/**
    6.13 - *
    6.14 - * @author Mikhail Kryshen
    6.15 - */
    6.16 -public class UserConfig2 extends HostConfig {
    6.17 -
    6.18 -    /**
    6.19 -     * The directory name to be searched for within each user home directory.
    6.20 -     */
    6.21 -    private String directoryName = "public_webapps";
    6.22 -
    6.23 -    /**
    6.24 -     * The base directory containing user home directories.
    6.25 -     */
    6.26 -    private String homeBase = null;
    6.27 -
    6.28 -    /**
    6.29 -     * The Java class name of the user database class we should use.
    6.30 -     */
    6.31 -    private String userClass =
    6.32 -            "org.apache.catalina.startup.PasswdUserDatabase";
    6.33 -
    6.34 -    /**
    6.35 -     * UserConfig instance is required by UserDatabase.
    6.36 -     */
    6.37 -    private UserConfig userConfig = new UserConfig();
    6.38 -
    6.39 -    /**
    6.40 -     * Return the directory name for user web applications.
    6.41 -     */
    6.42 -    public String getDirectoryName() {
    6.43 -        return (this.directoryName);
    6.44 -    }
    6.45 -
    6.46 -    /**
    6.47 -     * Set the directory name for user web applications.
    6.48 -     *
    6.49 -     * @param directoryName The new directory name
    6.50 -     */
    6.51 -    public void setDirectoryName(String directoryName) {
    6.52 -        this.directoryName = directoryName;
    6.53 -        userConfig.setDirectoryName(directoryName);
    6.54 -    }
    6.55 -
    6.56 -    /**
    6.57 -     * Return the base directory containing user home directories.
    6.58 -     */
    6.59 -    public String getHomeBase() {
    6.60 -        return (this.homeBase);
    6.61 -    }
    6.62 -
    6.63 -    /**
    6.64 -     * Set the base directory containing user home directories.
    6.65 -     *
    6.66 -     * @param homeBase The new base directory
    6.67 -     */
    6.68 -    public void setHomeBase(String homeBase) {
    6.69 -        this.homeBase = homeBase;
    6.70 -        userConfig.setHomeBase(homeBase);
    6.71 -    }
    6.72 -
    6.73 -    /** 
    6.74 -     * Return the user database class name for this component. 
    6.75 -     */
    6.76 -    public String getUserClass() {
    6.77 -        return (this.userClass);
    6.78 -    }
    6.79 -
    6.80 -    /** 
    6.81 -     * Set the user database class name for this component. 
    6.82 -     */
    6.83 -    public void setUserClass(String userClass) {
    6.84 -        this.userClass = userClass;
    6.85 -        userConfig.setUserClass(userClass);
    6.86 -    }
    6.87 -
    6.88 -    @Override
    6.89 -    protected void deployApps() {       
    6.90 -        // Load the user database object for this host
    6.91 -        UserDatabase database = null;
    6.92 -        try {
    6.93 -            Class clazz = Class.forName(userClass);
    6.94 -            database = (UserDatabase) clazz.newInstance();
    6.95 -            database.setUserConfig(userConfig);
    6.96 -        } catch (Exception e) {
    6.97 -            host.getLogger().error(sm.getString("userConfig.database"), e);
    6.98 -            return;
    6.99 -        }
   6.100 -
   6.101 -        // Deploy the web application (if any) for each defined user
   6.102 -        Enumeration users = database.getUsers();
   6.103 -        while (users.hasMoreElements()) {
   6.104 -            String user = (String) users.nextElement();
   6.105 -            String home = database.getHome(user);
   6.106 -            deployUserApps(user, home);
   6.107 -        }
   6.108 -    }
   6.109 -
   6.110 -    @Override
   6.111 -    protected void deployApps(String name) {
   6.112 -        throw new UnsupportedOperationException
   6.113 -                ("deployApps(String) is not supported.");
   6.114 -    }
   6.115 -
   6.116 -    protected void deployUserApps(String user, String home) {
   6.117 -        File base = new File(home, directoryName);
   6.118 -
   6.119 -        if (!base.exists() || !base.isDirectory()) {
   6.120 -            return;
   6.121 -        }
   6.122 -
   6.123 -// TODO: deployWARs
   6.124 -//        // Deploy WARs, and loop if additional descriptors are found
   6.125 -//        deployWARs(appBase, appBase.list());
   6.126 -
   6.127 -        // Deploy expanded folders
   6.128 -        deployDirectories(user, base, base.list());
   6.129 -    }
   6.130 -
   6.131 -    /**
   6.132 -     * Deploy user webapp directories.
   6.133 -     */
   6.134 -    protected void deployDirectories(String user, File base, String[] files) {
   6.135 -
   6.136 -        if (files == null) {
   6.137 -            return;
   6.138 -        }
   6.139 -
   6.140 -        for (int i = 0; i < files.length; i++) {
   6.141 -            if (files[i].equalsIgnoreCase("META-INF")) {
   6.142 -                continue;
   6.143 -            }
   6.144 -
   6.145 -            if (files[i].equalsIgnoreCase("WEB-INF")) {
   6.146 -                continue;
   6.147 -            }
   6.148 -
   6.149 -            File dir = new File(base, files[i]);
   6.150 -            if (dir.isDirectory()) {
   6.151 -                String contextPath;
   6.152 -                
   6.153 -                if (files[i].equals("ROOT")) {
   6.154 -                    contextPath = "/~" + user;
   6.155 -                } else {
   6.156 -                    contextPath = "/~" + user + '/' + files[i].replace('#', '/');
   6.157 -                }
   6.158 -
   6.159 -                if (isServiced(contextPath)) {
   6.160 -                    continue;
   6.161 -                }
   6.162 -
   6.163 -                deployDirectory(contextPath, dir, dir.getAbsolutePath());
   6.164 -            }
   6.165 -        }
   6.166 -    }
   6.167 -}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/kryshen/catalina/startup/UserDatabase.java	Fri Oct 30 05:12:58 2009 +0300
     7.3 @@ -0,0 +1,28 @@
     7.4 +package kryshen.catalina.startup;
     7.5 +
     7.6 +import java.io.File;
     7.7 +import java.util.Map;
     7.8 +
     7.9 +/**
    7.10 + *
    7.11 + * @author Mikhail Kryshen
    7.12 + */
    7.13 +public interface UserDatabase {
    7.14 +
    7.15 +    /**
    7.16 +     * Return the UserConfig listener with which we are associated.
    7.17 +     */
    7.18 +    public UserConfig getUserConfig();
    7.19 +
    7.20 +    /**
    7.21 +     * Set the UserConfig listener with which we are associated.
    7.22 +     *
    7.23 +     * @param userConfig The new UserConfig listener
    7.24 +     */
    7.25 +    public void setUserConfig(UserConfig userConfig);
    7.26 +
    7.27 +    /**
    7.28 +     * Return mapping between usernames and homes.
    7.29 +     */
    7.30 +     Map<String, File> getUserHomes();
    7.31 +}