*/
public static final String RELOAD_EVENT = "reload";
+ /**
+ * Container event for adding a welcome file.
+ */
+ public static final String ADD_WELCOME_FILE_EVENT = "addWelcomeFile";
+
+ /**
+ * Container event for removing a wrapper.
+ */
+ public static final String REMOVE_WELCOME_FILE_EVENT = "removeWelcomeFile";
+
+ /**
+ * Container event for clearing welcome files.
+ */
+ public static final String CLEAR_WELCOME_FILES_EVENT = "clearWelcomeFiles";
// ------------------------------------------------------------- Properties
public interface Wrapper extends Container {
+ /**
+ * Container event for adding a wrapper.
+ */
+ public static final String ADD_MAPPING_EVENT = "addMapping";
+
+ /**
+ * Container event for removing a wrapper.
+ */
+ public static final String REMOVE_MAPPING_EVENT = "removeMapping";
// ------------------------------------------------------------- Properties
event.getData().toString());
} else if (event.getType() == Host.REMOVE_ALIAS_EVENT) {
mapper.removeHostAlias(event.getData().toString());
+ } else if (event.getType() == Wrapper.ADD_MAPPING_EVENT) {
+ Wrapper wrapper = (Wrapper) event.getSource();
+
+ String contextName = wrapper.getParent().getName();
+ if ("/".equals(contextName)) {
+ contextName = "";
+ }
+ String hostName = wrapper.getParent().getParent().getName();
+
+ String mapping = (String) event.getData();
+ boolean jspWildCard = ("jsp".equals(wrapper.getName())
+ && mapping.endsWith("/*"));
+ mapper.addWrapper(hostName, contextName, mapping, wrapper,
+ jspWildCard);
+ } else if (event.getType() == Wrapper.REMOVE_MAPPING_EVENT) {
+ Wrapper wrapper = (Wrapper) event.getSource();
+
+ String contextName = wrapper.getParent().getName();
+ if ("/".equals(contextName)) {
+ contextName = "";
+ }
+ String hostName = wrapper.getParent().getParent().getName();
+
+ String mapping = (String) event.getData();
+
+ mapper.removeWrapper(hostName, contextName, mapping);
+ } else if (event.getType() == Context.ADD_WELCOME_FILE_EVENT) {
+ Context context = (Context) event.getSource();
+
+ String hostName = context.getParent().getName();
+
+ String contextName = context.getName();
+ if ("/".equals(contextName)) {
+ contextName = "";
+ }
+
+ String welcomeFile = (String) event.getData();
+
+ mapper.addWelcomeFile(hostName, contextName, welcomeFile);
+ } else if (event.getType() == Context.REMOVE_WELCOME_FILE_EVENT) {
+ Context context = (Context) event.getSource();
+
+ String hostName = context.getParent().getName();
+
+ String contextName = context.getName();
+ if ("/".equals(contextName)) {
+ contextName = "";
+ }
+
+ String welcomeFile = (String) event.getData();
+
+ mapper.removeWelcomeFile(hostName, contextName, welcomeFile);
+ } else if (event.getType() == Context.CLEAR_WELCOME_FILES_EVENT) {
+ Context context = (Context) event.getSource();
+
+ String hostName = context.getParent().getName();
+
+ String contextName = context.getName();
+ if ("/".equals(contextName)) {
+ contextName = "";
+ }
+
+ mapper.clearWelcomeFiles(hostName, contextName);
}
}
String[] aliases = host.findAliases();
mapper.addHost(host.getName(), aliases, host.getObjectName());
+
+ host.addContainerListener(this);
+
if(log.isDebugEnabled()) {
log.debug(sm.getString
("mapperListener.registerHost", host.getName(), domain));
*/
private void unregisterHost(Host host) {
+ host.removeContainerListener(this);
+
String hostname = host.getName();
mapper.removeHost(hostname);
*/
private void unregisterWrapper(Wrapper wrapper) {
+ wrapper.removeContainerListener(this);
+
String contextName = wrapper.getParent().getName();
if ("/".equals(contextName)) {
contextName = "";
mapper.addContext(hostName, contextName, context, welcomeFiles,
resources);
+ context.addContainerListener(this);
+
if(log.isDebugEnabled()) {
log.debug(sm.getString
("mapperListener.registerContext", contextName));
if (context.getPaused()){
return;
}
+
+ context.removeContainerListener(this);
String contextName = context.getName();
if ("/".equals(contextName)) {
jspWildCard);
}
+ // Also want to watch for any changes to the mappings for this wrapper
+ wrapper.addContainerListener(this);
+
if(log.isDebugEnabled()) {
log.debug(sm.getString("mapperListener.registerWrapper",
wrapperName, contextName));
@Override
public void lifecycleEvent(LifecycleEvent event) {
- if (event.getType() == Lifecycle.AFTER_START_EVENT) {
+ if (event.getType() == Lifecycle.BEFORE_START_EVENT) {
Object obj = event.getSource();
if (obj instanceof Wrapper) {
registerWrapper((Wrapper) obj);
// Welcome files from the application deployment descriptor
// completely replace those from the default conf/web.xml file
if (replaceWelcomeFiles) {
+ fireContainerEvent(CLEAR_WELCOME_FILES_EVENT, null);
welcomeFiles = new String[0];
setReplaceWelcomeFiles(false);
}
welcomeFiles = results;
}
postWelcomeFiles();
- fireContainerEvent("addWelcomeFile", name);
+ fireContainerEvent(ADD_WELCOME_FILE_EVENT, name);
}
// Inform interested listeners
postWelcomeFiles();
- fireContainerEvent("removeWelcomeFile", name);
+ fireContainerEvent(REMOVE_WELCOME_FILE_EVENT, name);
}
synchronized (mappings) {
mappings.add(mapping);
}
- fireContainerEvent("addMapping", mapping);
+ fireContainerEvent(ADD_MAPPING_EVENT, mapping);
}
synchronized (mappings) {
mappings.remove(mapping);
}
- fireContainerEvent("removeMapping", mapping);
+ fireContainerEvent(REMOVE_MAPPING_EVENT, mapping);
}
}
-
+ /**
+ * Add a welcome file to the given context.
+ *
+ * @param hostName
+ * @param contextPath
+ * @param welcomeFile
+ */
+ public void addWelcomeFile(String hostName, String contextPath,
+ String welcomeFile) {
+ Host[] hosts = this.hosts;
+ int pos = find(hosts, hostName);
+ if (pos < 0) {
+ return;
+ }
+ Host host = hosts[pos];
+ if (host.name.equals(hostName)) {
+ Context[] contexts = host.contextList.contexts;
+ int pos2 = find(contexts, contextPath);
+ if( pos2<0 ) {
+ log.error("No context found: " + contextPath );
+ return;
+ }
+ Context context = contexts[pos2];
+ if (context.name.equals(contextPath)) {
+ int len = context.welcomeResources.length + 1;
+ String[] newWelcomeResources = new String[len];
+ System.arraycopy(context.welcomeResources, 0,
+ newWelcomeResources, 0, len - 1);
+ newWelcomeResources[len - 1] = welcomeFile;
+ context.welcomeResources = newWelcomeResources;
+ }
+ }
+ }
+
+
+ /**
+ * Remove a welcome file from the given context.
+ *
+ * @param hostName
+ * @param contextPath
+ * @param welcomeFile
+ */
+ public void removeWelcomeFile(String hostName, String contextPath,
+ String welcomeFile) {
+ Host[] hosts = this.hosts;
+ int pos = find(hosts, hostName);
+ if (pos < 0) {
+ return;
+ }
+ Host host = hosts[pos];
+ if (host.name.equals(hostName)) {
+ Context[] contexts = host.contextList.contexts;
+ int pos2 = find(contexts, contextPath);
+ if( pos2<0 ) {
+ log.error("No context found: " + contextPath );
+ return;
+ }
+ Context context = contexts[pos2];
+ if (context.name.equals(contextPath)) {
+ int match = -1;
+ for (int i = 0; i < context.welcomeResources.length; i++) {
+ if (welcomeFile.equals(context.welcomeResources[i])) {
+ match = i;
+ break;
+ }
+ }
+ if (match > -1) {
+ int len = context.welcomeResources.length - 1;
+ String[] newWelcomeResources = new String[len];
+ System.arraycopy(context.welcomeResources, 0,
+ newWelcomeResources, 0, match);
+ if (match < len) {
+ System.arraycopy(context.welcomeResources, match + 1,
+ newWelcomeResources, match, len - match);
+ }
+ context.welcomeResources = newWelcomeResources;
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Clear the welcome files for the given context.
+ *
+ * @param hostName
+ * @param contextPath
+ */
+ public void clearWelcomeFiles(String hostName, String contextPath) {
+ Host[] hosts = this.hosts;
+ int pos = find(hosts, hostName);
+ if (pos < 0) {
+ return;
+ }
+ Host host = hosts[pos];
+ if (host.name.equals(hostName)) {
+ Context[] contexts = host.contextList.contexts;
+ int pos2 = find(contexts, contextPath);
+ if( pos2<0 ) {
+ log.error("No context found: " + contextPath );
+ return;
+ }
+ Context context = contexts[pos2];
+ if (context.name.equals(contextPath)) {
+ context.welcomeResources = new String[0];
+ }
+ }
+ }
+
+
/**
* Map the specified host name and URI, mutating the given mapping data.
*