1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.chain.contexts;
19
20 import org.apache.commons.chain.web.WebContext;
21 import org.apache.struts.Globals;
22 import org.apache.struts.config.ModuleConfig;
23
24 import java.util.Map;
25
26 /***
27 * <p> Provide a Subclass of ActionContextBase which is understood to be
28 * wrapping an instance of <code>org.apache.commons.chain.web.WebContext</code>.
29 * </p>
30 */
31 public class WebActionContext extends ActionContextBase {
32 /***
33 * Instantiate this composite by wrapping an instance of WebContext.
34 *
35 * @param context The WebContext to wrap
36 */
37 public WebActionContext(WebContext context) {
38 super(context);
39 }
40
41 /***
42 * Provide the wrapped WebContext for this composite.
43 *
44 * @return The wrapped WebContext
45 */
46 protected WebContext webContext() {
47 return (WebContext) this.getBaseContext();
48 }
49
50 public void release() {
51 super.release();
52 }
53
54
55
56
57
58 /***
59 * <p> Return an immutable Map that maps header names to the first (or
60 * only) header value (as a String). </p>
61 *
62 * @return A immutable Map of web request header names
63 */
64 public Map getHeader() {
65 return webContext().getHeader();
66 }
67
68 /***
69 * <p> Return an immutable Map that maps header names to the set of all
70 * values specified in the request (as a String array). Header names must
71 * be matched in a case-insensitive manner. </p>
72 *
73 * @return An immutable Map of web request header values
74 */
75 public Map getHeaderValues() {
76 return webContext().getHeaderValues();
77 }
78
79 /***
80 * <p> Return an immutable Map that maps context application
81 * initialization parameters to their values. </p>
82 *
83 * @return An immutable Map of web context initialization parameters
84 */
85 public Map getInitParam() {
86 return webContext().getInitParam();
87 }
88
89 /***
90 * <p> Return a map whose keys are <code>String</code> request parameter
91 * names and whose values are <code>String</code> values. </p> <p> For
92 * parameters which were submitted with more than one value, only one
93 * value will be returned, as if one called
94 * <code>ServletRequest.getParameter(String)</code>
95 * </p>
96 *
97 * @return A map of web request parameters
98 */
99 public Map getParam() {
100 return webContext().getParam();
101 }
102
103 /***
104 * <p> Return a map whose keys are <code>String</code> request parameter
105 * names and whose values are <code>String[]</code> values. </p>
106 *
107 * @return A map of web request parameter values (as an array)
108 */
109 public Map getParamValues() {
110 return webContext().getParamValues();
111 }
112
113 public Map getApplicationScope() {
114 return webContext().getApplicationScope();
115 }
116
117 public Map getRequestScope() {
118 return webContext().getRequestScope();
119 }
120
121 public Map getParameterMap() {
122 return getParamValues();
123 }
124
125 public Map getSessionScope() {
126 return webContext().getSessionScope();
127 }
128
129
130
131
132
133 public void setModuleConfig(ModuleConfig moduleConfig) {
134 super.setModuleConfig(moduleConfig);
135 this.getRequestScope().put(Globals.MODULE_KEY, moduleConfig);
136 }
137
138 /***
139 * @see org.apache.struts.chain.contexts.ActionContext#getModuleConfig()
140 */
141 public ModuleConfig getModuleConfig() {
142 ModuleConfig mc = super.getModuleConfig();
143
144 if (mc == null) {
145 mc = (ModuleConfig) this.getRequestScope().get(Globals.MODULE_KEY);
146 }
147
148 return mc;
149 }
150
151
152
153
154
155 public void setCancelled(Boolean cancelled) {
156 super.setCancelled(cancelled);
157
158
159
160
161 if ((cancelled != null) && cancelled.booleanValue()) {
162 this.getRequestScope().put(Globals.CANCEL_KEY, cancelled);
163 } else {
164 this.getRequestScope().remove(Globals.CANCEL_KEY);
165 }
166 }
167
168 public Boolean getCancelled() {
169 Boolean cancelled = super.getCancelled();
170
171 if (cancelled == null) {
172 cancelled =
173 (Boolean) this.getRequestScope().get(Globals.CANCEL_KEY);
174 }
175
176 return cancelled;
177 }
178 }