001: /*
002: * Copyright 2004-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package org.springframework.webflow.context.servlet;
017:
018: import javax.servlet.ServletContext;
019: import javax.servlet.http.HttpServletRequest;
020: import javax.servlet.http.HttpServletResponse;
021:
022: import org.springframework.core.style.ToStringCreator;
023: import org.springframework.webflow.context.ExternalContext;
024: import org.springframework.webflow.core.collection.LocalAttributeMap;
025: import org.springframework.webflow.core.collection.LocalParameterMap;
026: import org.springframework.webflow.core.collection.LocalSharedAttributeMap;
027: import org.springframework.webflow.core.collection.MutableAttributeMap;
028: import org.springframework.webflow.core.collection.ParameterMap;
029: import org.springframework.webflow.core.collection.SharedAttributeMap;
030:
031: /**
032: * Provides contextual information about an HTTP Servlet environment that has interacted with Spring Web Flow.
033: *
034: * @author Keith Donald
035: * @author Erwin Vervaet
036: */
037: public class ServletExternalContext implements ExternalContext {
038:
039: /**
040: * The context.
041: */
042: private ServletContext context;
043:
044: /**
045: * The request.
046: */
047: private HttpServletRequest request;
048:
049: /**
050: * The response.
051: */
052: private HttpServletResponse response;
053:
054: /**
055: * An accessor for the HTTP request parameter map.
056: */
057: private ParameterMap requestParameterMap;
058:
059: /**
060: * An accessor for the HTTP request attribute map.
061: */
062: private MutableAttributeMap requestMap;
063:
064: /**
065: * An accessor for the HTTP session map.
066: */
067: private SharedAttributeMap sessionMap;
068:
069: /**
070: * An accessor for the servlet context application map.
071: */
072: private SharedAttributeMap applicationMap;
073:
074: /**
075: * Create a new external context wrapping given servlet HTTP request and response and given servlet context.
076: * @param context the servlet context
077: * @param request the HTTP request
078: * @param response the HTTP response
079: */
080: public ServletExternalContext(ServletContext context,
081: HttpServletRequest request, HttpServletResponse response) {
082: this .context = context;
083: this .request = request;
084: this .response = response;
085: this .requestParameterMap = new LocalParameterMap(
086: new HttpServletRequestParameterMap(request));
087: this .requestMap = new LocalAttributeMap(
088: new HttpServletRequestMap(request));
089: this .sessionMap = new LocalSharedAttributeMap(
090: new HttpSessionMap(request));
091: this .applicationMap = new LocalSharedAttributeMap(
092: new HttpServletContextMap(context));
093: }
094:
095: public String getContextPath() {
096: return request.getContextPath();
097: }
098:
099: public String getDispatcherPath() {
100: return request.getServletPath();
101: }
102:
103: public String getRequestPathInfo() {
104: return request.getPathInfo();
105: }
106:
107: public ParameterMap getRequestParameterMap() {
108: return requestParameterMap;
109: }
110:
111: public MutableAttributeMap getRequestMap() {
112: return requestMap;
113: }
114:
115: public SharedAttributeMap getSessionMap() {
116: return sessionMap;
117: }
118:
119: public SharedAttributeMap getGlobalSessionMap() {
120: return getSessionMap();
121: }
122:
123: public SharedAttributeMap getApplicationMap() {
124: return applicationMap;
125: }
126:
127: /**
128: * Return the wrapped HTTP servlet context.
129: */
130: public ServletContext getContext() {
131: return context;
132: }
133:
134: /**
135: * Return the wrapped HTTP servlet request.
136: */
137: public HttpServletRequest getRequest() {
138: return request;
139: }
140:
141: /**
142: * Return the wrapped HTTP servlet response.
143: */
144: public HttpServletResponse getResponse() {
145: return response;
146: }
147:
148: public String toString() {
149: return new ToStringCreator(this ).append("requestParameterMap",
150: getRequestParameterMap()).toString();
151: }
152: }
|