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.chain.Constants;
24 import org.apache.struts.chain.commands.AbstractSelectAction;
25 import org.apache.struts.chain.contexts.ActionContext;
26 import org.apache.struts.chain.contexts.ServletActionContext;
27 import org.apache.struts.config.ModuleConfig;
28
29 import jakarta.servlet.http.HttpServletRequest;
30
31
32
33
34
35
36
37
38 public class SelectAction extends AbstractSelectAction {
39
40 protected String getPath(ActionContext context) {
41 ServletActionContext saContext = (ServletActionContext) context;
42 HttpServletRequest request = saContext.getRequest();
43 String path = null;
44 boolean extension = false;
45
46
47 path = (String) request.getAttribute(Constants.INCLUDE_PATH_INFO);
48
49 if ((path == null) || (path.length() == 0)) {
50 path = request.getPathInfo();
51 }
52
53
54 if ((path == null) || (path.length() == 0)) {
55 path =
56 (String) request.getAttribute(Constants.INCLUDE_SERVLET_PATH);
57
58 if ((path == null) || (path.length() == 0)) {
59 path = request.getServletPath();
60 }
61
62 if ((path == null) || (path.length() == 0)) {
63 throw new IllegalArgumentException(
64 "No path information in request");
65 }
66
67 extension = true;
68 }
69
70
71 ModuleConfig moduleConfig = saContext.getModuleConfig();
72 String prefix = moduleConfig.getPrefix();
73
74 if (!path.startsWith(prefix)) {
75 throw new IllegalArgumentException("Path does not start with '"
76 + prefix + "'");
77 }
78
79 path = path.substring(prefix.length());
80
81 if (extension) {
82 int slash = path.lastIndexOf("/");
83 int period = path.lastIndexOf(".");
84
85 if ((period >= 0) && (period > slash)) {
86 path = path.substring(0, period);
87 }
88 }
89
90 return (path);
91 }
92 }