view src/kryshen/catalina/startup/UserConfig.java @ 10:086a55aa2620

PasswdUserConfig. Error logging.
author Mikhail Kryshen <mikhail@kryshen.net>
date Mon, 02 Nov 2009 23:17:40 +0300
parents ff1e55a2171f
children 3a71cbe721f9
line source
1 package kryshen.catalina.startup;
3 import java.io.File;
4 import org.apache.catalina.startup.HostConfig;
5 import org.apache.juli.logging.LogFactory;
7 /**
8 *
9 * @author Mikhail Kryshen
10 */
11 public abstract class UserConfig extends HostConfig {
13 /**
14 * The directory name to be searched for within each user home directory.
15 */
16 private String directoryName = "public_webapps";
19 protected UserConfig() {
20 log = LogFactory.getLog(UserConfig.class);
21 }
23 public String getDirectoryName() {
24 return directoryName;
25 }
27 /**
28 * Set the directory name for user web applications.
29 *
30 * @param directoryName The new directory name
31 */
32 public void setDirectoryName(String directoryName) {
33 this.directoryName = directoryName;
34 }
36 @Override
37 protected void deployApps() {
38 deployUserApps();
39 }
41 @Override
42 protected void deployApps(String name) {
43 throw new UnsupportedOperationException
44 ("deployApps(String) is not supported.");
45 }
47 protected abstract void deployUserApps();
49 protected void deployUserApps(String user, File home) {
50 File base = new File(home, directoryName);
52 if (!base.exists() || !base.isDirectory() || !base.canRead()) {
53 return;
54 }
56 // TODO: deployWARs
57 // deployWARs(appBase, appBase.list());
59 // Deploy expanded folders
60 deployDirectories(user, base, base.list());
61 }
63 /**
64 * Deploy user webapp directories.
65 */
66 protected void deployDirectories(String user, File base, String[] files) {
68 if (files == null) {
69 log.error("Error reading base directory: " + base.getPath() + ".");
70 return;
71 }
73 for (int i = 0; i < files.length; i++) {
74 if (files[i].equalsIgnoreCase("META-INF")) {
75 continue;
76 }
78 if (files[i].equalsIgnoreCase("WEB-INF")) {
79 continue;
80 }
82 File dir = new File(base, files[i]);
84 if (!dir.isDirectory() || !dir.canRead()) {
85 continue;
86 }
88 String contextPath;
90 if (files[i].equals("ROOT")) {
91 contextPath = "/~" + user;
92 } else {
93 contextPath = "/~" + user + '/' + files[i].replace('#', '/');
94 }
96 if (isServiced(contextPath)) {
97 continue;
98 }
100 deployDirectory(contextPath, dir, dir.getAbsolutePath());
101 }
102 }
103 }