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.portlet;
017:
018: import java.util.Map;
019:
020: import javax.portlet.PortletContext;
021: import javax.portlet.PortletRequest;
022: import javax.portlet.PortletResponse;
023: import javax.portlet.PortletSession;
024:
025: import org.springframework.core.style.ToStringCreator;
026: import org.springframework.webflow.context.ExternalContext;
027: import org.springframework.webflow.core.collection.LocalAttributeMap;
028: import org.springframework.webflow.core.collection.LocalParameterMap;
029: import org.springframework.webflow.core.collection.LocalSharedAttributeMap;
030: import org.springframework.webflow.core.collection.MutableAttributeMap;
031: import org.springframework.webflow.core.collection.ParameterMap;
032: import org.springframework.webflow.core.collection.SharedAttributeMap;
033:
034: /**
035: * Provides contextual information about a JSR-168 Portlet environment that has
036: * called into Spring Web Flow.
037: *
038: * @author Keith Donald
039: */
040: public class PortletExternalContext implements ExternalContext {
041:
042: /**
043: * The context.
044: */
045: private PortletContext context;
046:
047: /**
048: * The request.
049: */
050: private PortletRequest request;
051:
052: /**
053: * The response.
054: */
055: private PortletResponse response;
056:
057: /**
058: * An accessor for the portlet request parameter map.
059: */
060: private ParameterMap requestParameterMap;
061:
062: /**
063: * An accessor for the portlet request attribute map.
064: */
065: private MutableAttributeMap requestMap;
066:
067: /**
068: * An accessor for the local portlet session map.
069: */
070: private SharedAttributeMap sessionMap;
071:
072: /**
073: * An accessor for the global portlet session map.
074: */
075: private SharedAttributeMap globalSessionMap;
076:
077: /**
078: * An accessor for the portlet context application map.
079: */
080: private SharedAttributeMap applicationMap;
081:
082: /**
083: * An accessor for the portlet user info map.
084: */
085: private MutableAttributeMap userInfoMap;
086:
087: /**
088: * Create an external context wrapping given Portlet context, request and response.
089: * @param context the Portlet context
090: * @param request the Portlet request
091: * @param response the Portlet response
092: */
093: public PortletExternalContext(PortletContext context,
094: PortletRequest request, PortletResponse response) {
095: this .context = context;
096: this .request = request;
097: this .response = response;
098: this .requestParameterMap = new LocalParameterMap(
099: new PortletRequestParameterMap(request));
100: this .requestMap = new LocalAttributeMap(new PortletRequestMap(
101: request));
102: this .sessionMap = new LocalSharedAttributeMap(
103: new PortletSessionMap(request,
104: PortletSession.PORTLET_SCOPE));
105: this .globalSessionMap = new LocalSharedAttributeMap(
106: new PortletSessionMap(request,
107: PortletSession.APPLICATION_SCOPE));
108: this .applicationMap = new LocalSharedAttributeMap(
109: new PortletContextMap(context));
110: Map userInfo = (Map) request
111: .getAttribute(PortletRequest.USER_INFO);
112: this .userInfoMap = userInfo != null ? new LocalAttributeMap(
113: userInfo) : null;
114: }
115:
116: public String getContextPath() {
117: return request.getContextPath();
118: }
119:
120: public String getDispatcherPath() {
121: // returns null in a portlet environment
122: return null;
123: }
124:
125: public String getRequestPathInfo() {
126: // returns null in a portlet environment
127: return null;
128: }
129:
130: public ParameterMap getRequestParameterMap() {
131: return requestParameterMap;
132: }
133:
134: public MutableAttributeMap getRequestMap() {
135: return requestMap;
136: }
137:
138: public SharedAttributeMap getSessionMap() {
139: return sessionMap;
140: }
141:
142: public SharedAttributeMap getGlobalSessionMap() {
143: return globalSessionMap;
144: }
145:
146: public SharedAttributeMap getApplicationMap() {
147: return applicationMap;
148: }
149:
150: /**
151: * Returns the {@link PortletRequest#USER_INFO} map as a mutable attribute map.
152: * @return the Portlet user info
153: */
154: public MutableAttributeMap getUserInfoMap() {
155: return userInfoMap;
156: }
157:
158: /**
159: * Returns the wrapped Portlet context.
160: */
161: public PortletContext getContext() {
162: return context;
163: }
164:
165: /**
166: * Returns the wrapped Portlet request.
167: */
168: public PortletRequest getRequest() {
169: return request;
170: }
171:
172: /**
173: * Returns the wrapped Portlet response.
174: */
175: public PortletResponse getResponse() {
176: return response;
177: }
178:
179: public String toString() {
180: return new ToStringCreator(this ).append("requestParameterMap",
181: getRequestParameterMap()).toString();
182: }
183: }
|