001: /*
002: * $Id: WebActionContext.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts.chain.contexts;
022:
023: import org.apache.commons.chain.web.WebContext;
024: import org.apache.struts.Globals;
025: import org.apache.struts.config.ModuleConfig;
026:
027: import java.util.Map;
028:
029: /**
030: * <p> Provide a Subclass of ActionContextBase which is understood to be
031: * wrapping an instance of <code>org.apache.commons.chain.web.WebContext</code>.
032: * </p>
033: */
034: public class WebActionContext extends ActionContextBase {
035: /**
036: * Instantiate this composite by wrapping an instance of WebContext.
037: *
038: * @param context The WebContext to wrap
039: */
040: public WebActionContext(WebContext context) {
041: super (context);
042: }
043:
044: /**
045: * Provide the wrapped WebContext for this composite.
046: *
047: * @return The wrapped WebContext
048: */
049: protected WebContext webContext() {
050: return (WebContext) this .getBaseContext();
051: }
052:
053: public void release() {
054: super .release();
055: }
056:
057: // -------------------------------
058: // WebContext property wrappers
059: // -------------------------------
060:
061: /**
062: * <p> Return an immutable Map that maps header names to the first (or
063: * only) header value (as a String). </p>
064: *
065: * @return A immutable Map of web request header names
066: */
067: public Map getHeader() {
068: return webContext().getHeader();
069: }
070:
071: /**
072: * <p> Return an immutable Map that maps header names to the set of all
073: * values specified in the request (as a String array). Header names must
074: * be matched in a case-insensitive manner. </p>
075: *
076: * @return An immutable Map of web request header values
077: */
078: public Map getHeaderValues() {
079: return webContext().getHeaderValues();
080: }
081:
082: /**
083: * <p> Return an immutable Map that maps context application
084: * initialization parameters to their values. </p>
085: *
086: * @return An immutable Map of web context initialization parameters
087: */
088: public Map getInitParam() {
089: return webContext().getInitParam();
090: }
091:
092: /**
093: * <p> Return a map whose keys are <code>String</code> request parameter
094: * names and whose values are <code>String</code> values. </p> <p> For
095: * parameters which were submitted with more than one value, only one
096: * value will be returned, as if one called
097: * <code>ServletRequest.getParameter(String)</code>
098: * </p>
099: *
100: * @return A map of web request parameters
101: */
102: public Map getParam() {
103: return webContext().getParam();
104: }
105:
106: /**
107: * <p> Return a map whose keys are <code>String</code> request parameter
108: * names and whose values are <code>String[]</code> values. </p>
109: *
110: * @return A map of web request parameter values (as an array)
111: */
112: public Map getParamValues() {
113: return webContext().getParamValues();
114: }
115:
116: public Map getApplicationScope() {
117: return webContext().getApplicationScope();
118: }
119:
120: public Map getRequestScope() {
121: return webContext().getRequestScope();
122: }
123:
124: public Map getParameterMap() {
125: return getParamValues();
126: }
127:
128: public Map getSessionScope() {
129: return webContext().getSessionScope();
130: }
131:
132: // ISSUE: AbstractSelectModule set the precedent of doing this at the
133: // "web context" level instead of the ServletWebContext level.
134: // Consider whether that's how we want to do it universally for other
135: // manipulations of the RequestScope or not...
136: public void setModuleConfig(ModuleConfig moduleConfig) {
137: super .setModuleConfig(moduleConfig);
138: this .getRequestScope().put(Globals.MODULE_KEY, moduleConfig);
139: }
140:
141: /**
142: * @see org.apache.struts.chain.contexts.ActionContext#getModuleConfig()
143: */
144: public ModuleConfig getModuleConfig() {
145: ModuleConfig mc = super .getModuleConfig();
146:
147: if (mc == null) {
148: mc = (ModuleConfig) this .getRequestScope().get(
149: Globals.MODULE_KEY);
150: }
151:
152: return mc;
153: }
154:
155: // ISSUE: AbstractSelectModule set the precedent of doing this at the
156: // "web context" level instead of the ServletWebContext level. Consider
157: // whether that's how we want to do it universally for other manipulations
158: // of the RequestScope or not...
159: public void setCancelled(Boolean cancelled) {
160: super .setCancelled(cancelled);
161:
162: // historic semantics of "isCancelled" are to consider any non-null
163: // value in the request under Globals.CANCEL_KEY as "yes, this was
164: // cancelled."
165: if ((cancelled != null) && cancelled.booleanValue()) {
166: this .getRequestScope().put(Globals.CANCEL_KEY, cancelled);
167: } else {
168: this .getRequestScope().remove(Globals.CANCEL_KEY);
169: }
170: }
171:
172: public Boolean getCancelled() {
173: Boolean cancelled = super .getCancelled();
174:
175: if (cancelled == null) {
176: cancelled = (Boolean) this.getRequestScope().get(
177: Globals.CANCEL_KEY);
178: }
179:
180: return cancelled;
181: }
182: }
|