1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.struts.chain.commands.servlet;
17
18 import org.apache.struts.Globals;
19 import org.apache.struts.chain.Constants;
20 import org.apache.struts.chain.commands.AbstractSelectModule;
21 import org.apache.struts.chain.contexts.ActionContext;
22 import org.apache.struts.chain.contexts.ServletActionContext;
23
24 import javax.servlet.http.HttpServletRequest;
25
26 /***
27 * <p>Cache the <code>ModuleConfig</code> and <code>MessageResources</code>
28 * instances for the sub-application module to be used for processing this
29 * request.</p>
30 *
31 * @version $Rev: 421119 $ $Date: 2005-06-04 10:58:46 -0400 (Sat, 04 Jun 2005)
32 * $
33 */
34 public class SelectModule extends AbstractSelectModule {
35
36 protected String getPrefix(ActionContext context) {
37
38 ServletActionContext sacontext = (ServletActionContext) context;
39 HttpServletRequest request = sacontext.getRequest();
40 String uri =
41 (String) request.getAttribute(Constants.INCLUDE_SERVLET_PATH);
42
43 if (uri == null) {
44 uri = request.getServletPath();
45 }
46
47 if (uri == null) {
48 throw new IllegalArgumentException("No path information in request");
49 }
50
51
52 String prefix = "";
53 String[] prefixes =
54 (String[]) sacontext.getApplicationScope().get(Globals.MODULE_PREFIXES_KEY);
55 int lastSlash = 0;
56
57 while (prefix.equals("") && ((lastSlash = uri.lastIndexOf("/")) > 0)) {
58 uri = uri.substring(0, lastSlash);
59
60 for (int i = 0; i < prefixes.length; i++) {
61 if (uri.equals(prefixes[i])) {
62 prefix = prefixes[i];
63
64 break;
65 }
66 }
67 }
68
69 return (prefix);
70 }
71 }