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 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 /**
24 * Returns the directory name to be searched for webapps for each user
25 * (relative to the user's home direcotry).
26 */
27 public String getDirectoryName() {
28 return directoryName;
29 }
31 /**
32 * Set the directory name to be searched for webapps for each user
33 * (relative to the user's home direcotry).
34 *
35 * @param directoryName The new directory name
36 */
37 public void setDirectoryName(String directoryName) {
38 this.directoryName = directoryName;
39 }
41 @Override
42 protected void deployApps() {
43 deployUserApps();
44 }
46 @Override
47 protected void deployApps(String name) {
48 throw new UnsupportedOperationException
49 ("deployApps(String) is not supported.");
50 }
52 /**
53 * Deploy applications for all available users.
54 */
55 protected abstract void deployUserApps();
57 /**
58 * Deploy applications (if any) for specific user.
59 *
60 * @param user Username
61 * @param home User home directory
62 */
63 protected void deployUserApps(String user, File home) {
64 File base = new File(home, directoryName);
66 if (!base.isDirectory() || !base.canRead()) {
67 return;
68 }
70 // TODO: deployWars
72 deployDirectories(user, base, base.list());
73 }
75 /**
76 * Deploy user webapp directories.
77 */
78 protected void deployDirectories(String user, File base, String[] files) {
80 if (files == null) {
81 log.warn("Error reading base directory: " + base.getPath() + ".");
82 return;
83 }
85 for (int i = 0; i < files.length; i++) {
86 if (files[i].equalsIgnoreCase("META-INF")) {
87 continue;
88 }
90 if (files[i].equalsIgnoreCase("WEB-INF")) {
91 continue;
92 }
94 File dir = new File(base, files[i]);
96 if (!dir.isDirectory() || !dir.canRead()) {
97 continue;
98 }
100 String contextPath;
102 if (files[i].equals("ROOT")) {
103 contextPath = "/~" + user;
104 } else {
105 contextPath = "/~" + user + '/' + files[i].replace('#', '/');
106 }
108 if (isServiced(contextPath)) {
109 continue;
110 }
112 deployDirectory(contextPath, dir, dir.getAbsolutePath());
113 }
114 }
115 }