1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.chain.commands;
19
20 import org.apache.struts.chain.contexts.ActionContext;
21 import org.apache.struts.config.ActionConfig;
22 import org.apache.struts.config.ModuleConfig;
23
24 /***
25 * <p>Cache the <code>ActionConfig</code> instance for the action to be used
26 * for processing this request.</p>
27 *
28 * @version $Rev: 421119 $ $Date: 2005-11-05 21:44:59 -0500 (Sat, 05 Nov 2005)
29 * $
30 */
31 public abstract class AbstractSelectAction extends ActionCommandBase {
32
33
34 /***
35 * <p>Cache the <code>ActionConfig</code> instance for the action to be
36 * used for processing this request.</p>
37 *
38 * @param actionCtx The <code>Context</code> for the current request
39 * @return <code>false</code> so that processing continues
40 * @throws InvalidPathException if no valid action can be identified for
41 * this request
42 * @throws Exception if thrown by the Action class
43 */
44 public boolean execute(ActionContext actionCtx)
45 throws Exception {
46
47 String path = getPath(actionCtx);
48
49
50 ModuleConfig moduleConfig = actionCtx.getModuleConfig();
51 ActionConfig actionConfig = moduleConfig.findActionConfig(path);
52
53 if (actionConfig == null) {
54
55
56 ActionConfig[] configs = moduleConfig.findActionConfigs();
57
58 for (int i = 0; i < configs.length; i++) {
59 if (configs[i].getUnknown()) {
60 actionConfig = configs[i];
61
62 break;
63 }
64 }
65 }
66
67 if (actionConfig == null) {
68 throw new InvalidPathException("No action config found for the specified url.",
69 path);
70 }
71
72 actionCtx.setActionConfig(actionConfig);
73
74 return (false);
75 }
76
77
78
79 /***
80 * <p>Return the path to be used to select the <code>ActionConfig</code>
81 * for this request.</p>
82 *
83 * @param context The <code>Context</code> for this request
84 * @return Path to be used to select the ActionConfig
85 */
86 protected abstract String getPath(ActionContext context);
87 }