Mercurial > hg > tomcat-userconfig
view src/kryshen/catalina/startup/UserConfig.java @ 11:3a71cbe721f9
Fixed PasswdUserConfig. Better error logging.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Mon, 02 Nov 2009 23:47:14 +0300 |
parents | 086a55aa2620 |
children | 2f82b0faeb89 |
line wrap: on
line source
package kryshen.catalina.startup; import java.io.File; import org.apache.catalina.startup.HostConfig; import org.apache.juli.logging.LogFactory; /** * * @author Mikhail Kryshen */ public abstract class UserConfig extends HostConfig { /** * The directory name to be searched for within each user home directory. */ private String directoryName = "public_webapps"; protected UserConfig() { log = LogFactory.getLog(UserConfig.class); } /** * Returns the directory name to be searched for webapps for each user * (relative to the user's home direcotry). */ public String getDirectoryName() { return directoryName; } /** * Set the directory name to be searched for webapps for each user * (relative to the user's home direcotry). * * @param directoryName The new directory name */ public void setDirectoryName(String directoryName) { this.directoryName = directoryName; } @Override protected void deployApps() { deployUserApps(); } @Override protected void deployApps(String name) { throw new UnsupportedOperationException ("deployApps(String) is not supported."); } /** * Deploy applications for all available users. */ protected abstract void deployUserApps(); /** * Deploy applications (if any) for specific user. * * @param user Username * @param home User home directory */ protected void deployUserApps(String user, File home) { File base = new File(home, directoryName); if (!base.isDirectory() || !base.canRead()) { return; } // TODO: deployWars deployDirectories(user, base, base.list()); } /** * Deploy user webapp directories. */ protected void deployDirectories(String user, File base, String[] files) { if (files == null) { log.warn("Error reading base directory: " + base.getPath() + "."); return; } for (int i = 0; i < files.length; i++) { if (files[i].equalsIgnoreCase("META-INF")) { continue; } if (files[i].equalsIgnoreCase("WEB-INF")) { continue; } File dir = new File(base, files[i]); if (!dir.isDirectory() || !dir.canRead()) { continue; } String contextPath; if (files[i].equals("ROOT")) { contextPath = "/~" + user; } else { contextPath = "/~" + user + '/' + files[i].replace('#', '/'); } if (isServiced(contextPath)) { continue; } deployDirectory(contextPath, dir, dir.getAbsolutePath()); } } }