view src/kryshen/catalina/startup/UserConfig.java @ 7:ca0b81d28307

Compatibility fixes.
author Mikhail Kryshen <mikhail@kryshen.net>
date Sun, 01 Nov 2009 04:25:39 +0300
parents 64c05808a046
children ff1e55a2171f
line source
1 package kryshen.catalina.startup;
3 import java.io.File;
4 import org.apache.catalina.startup.HostConfig;
6 /**
7 *
8 * @author Mikhail Kryshen
9 */
10 public class UserConfig extends HostConfig {
12 /**
13 * The directory name to be searched for within each user home directory.
14 */
15 private String directoryName = "public_webapps";
17 /**
18 * The base directory containing user home directories.
19 */
20 private String homeBase = null;
22 /**
23 * The Java class name of the user database class we should use.
24 */
25 private String userClass =
26 "org.apache.catalina.startup.PasswdUserDatabase";
28 /**
29 * Return the directory name for user web applications.
30 */
31 public String getDirectoryName() {
32 return (this.directoryName);
33 }
35 /**
36 * Set the directory name for user web applications.
37 *
38 * @param directoryName The new directory name
39 */
40 public void setDirectoryName(String directoryName) {
41 this.directoryName = directoryName;
42 }
44 /**
45 * Return the base directory containing user home directories.
46 */
47 public String getHomeBase() {
48 return (this.homeBase);
49 }
51 /**
52 * Set the base directory containing user home directories.
53 *
54 * @param homeBase The new base directory
55 */
56 public void setHomeBase(String homeBase) {
57 this.homeBase = homeBase;
58 }
60 /**
61 * Return the user database class name for this component.
62 */
63 public String getUserClass() {
64 return (this.userClass);
65 }
67 /**
68 * Set the user database class name for this component.
69 */
70 public void setUserClass(String userClass) {
71 this.userClass = userClass;
72 }
74 @Override
75 protected void deployApps() {
76 // Load the user database object for this host
77 UserDatabase database = null;
78 try {
79 Class clazz = Class.forName(userClass);
80 database = (UserDatabase) clazz.newInstance();
81 database.setUserConfig(this);
82 } catch (Exception e) {
83 host.getLogger().error(sm.getString("userConfig.database"), e);
84 return;
85 }
87 // Deploy the web application (if any) for each defined user
88 for (UserDatabase.User user : database) {
89 deployUserApps(user.getName(), user.getHome());
90 }
91 }
93 @Override
94 protected void deployApps(String name) {
95 throw new UnsupportedOperationException
96 ("deployApps(String) is not supported.");
97 }
99 protected void deployUserApps(String user, File home) {
100 File base = new File(home, directoryName);
102 if (!base.exists() || !base.isDirectory() || !base.canRead()) {
103 return;
104 }
106 // TODO: deployWARs
107 // // Deploy WARs, and loop if additional descriptors are found
108 // deployWARs(appBase, appBase.list());
110 // Deploy expanded folders
111 deployDirectories(user, base, base.list());
112 }
114 /**
115 * Deploy user webapp directories.
116 */
117 protected void deployDirectories(String user, File base, String[] files) {
119 if (files == null) {
120 return;
121 }
123 for (int i = 0; i < files.length; i++) {
124 if (files[i].equalsIgnoreCase("META-INF")) {
125 continue;
126 }
128 if (files[i].equalsIgnoreCase("WEB-INF")) {
129 continue;
130 }
132 File dir = new File(base, files[i]);
134 if (!dir.isDirectory() || !dir.canRead()) {
135 continue;
136 }
138 String contextPath;
140 if (files[i].equals("ROOT")) {
141 contextPath = "/~" + user;
142 } else {
143 contextPath = "/~" + user + '/' + files[i].replace('#', '/');
144 }
146 if (isServiced(contextPath)) {
147 continue;
148 }
150 deployDirectory(contextPath, dir, dir.getAbsolutePath());
151 }
152 }
153 }