1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts.chain.commands.servlet;
22
23 import org.apache.struts.Globals;
24 import org.apache.struts.chain.Constants;
25 import org.apache.struts.chain.commands.AbstractSelectModule;
26 import org.apache.struts.chain.contexts.ActionContext;
27 import org.apache.struts.chain.contexts.ServletActionContext;
28
29 import jakarta.servlet.http.HttpServletRequest;
30
31
32
33
34
35
36
37
38
39 public class SelectModule extends AbstractSelectModule {
40
41 protected String getPrefix(ActionContext context) {
42
43 ServletActionContext sacontext = (ServletActionContext) context;
44 HttpServletRequest request = sacontext.getRequest();
45 String uri =
46 (String) request.getAttribute(Constants.INCLUDE_SERVLET_PATH);
47
48 if (uri == null) {
49 uri = request.getServletPath();
50 }
51
52 if (uri == null) {
53 throw new IllegalArgumentException("No path information in request");
54 }
55
56
57 String prefix = "";
58 String[] prefixes =
59 (String[]) sacontext.getApplicationScope().get(Globals.MODULE_PREFIXES_KEY);
60 int lastSlash = 0;
61
62 while (prefix.equals("") && ((lastSlash = uri.lastIndexOf("/")) > 0)) {
63 uri = uri.substring(0, lastSlash);
64
65 for (int i = 0; i < prefixes.length; i++) {
66 if (uri.equals(prefixes[i])) {
67 prefix = prefixes[i];
68
69 break;
70 }
71 }
72 }
73
74 return (prefix);
75 }
76 }