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.chain.Constants;
19 import org.apache.struts.chain.commands.AbstractSelectAction;
20 import org.apache.struts.chain.contexts.ActionContext;
21 import org.apache.struts.chain.contexts.ServletActionContext;
22 import org.apache.struts.config.ModuleConfig;
23
24 import javax.servlet.http.HttpServletRequest;
25
26 /***
27 * <p>Cache the <code>ActionConfig</code> instance for the action to be used
28 * for processing this request.</p>
29 *
30 * @version $Rev: 421119 $ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
31 * $
32 */
33 public class SelectAction extends AbstractSelectAction {
34
35 protected String getPath(ActionContext context) {
36 ServletActionContext saContext = (ServletActionContext) context;
37 HttpServletRequest request = saContext.getRequest();
38 String path = null;
39 boolean extension = false;
40
41
42 path = (String) request.getAttribute(Constants.INCLUDE_PATH_INFO);
43
44 if (path == null) {
45 path = request.getPathInfo();
46 }
47
48
49 if (path == null) {
50 path =
51 (String) request.getAttribute(Constants.INCLUDE_SERVLET_PATH);
52
53 if (path == null) {
54 path = request.getServletPath();
55 }
56
57 if (path == null) {
58 throw new IllegalArgumentException(
59 "No path information in request");
60 }
61
62 extension = true;
63 }
64
65
66 ModuleConfig moduleConfig = saContext.getModuleConfig();
67 String prefix = moduleConfig.getPrefix();
68
69 if (!path.startsWith(prefix)) {
70 throw new IllegalArgumentException("Path does not start with '"
71 + prefix + "'");
72 }
73
74 path = path.substring(prefix.length());
75
76 if (extension) {
77 int slash = path.lastIndexOf("/");
78 int period = path.lastIndexOf(".");
79
80 if ((period >= 0) && (period > slash)) {
81 path = path.substring(0, period);
82 }
83 }
84
85 return (path);
86 }
87 }