KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > context > portlet > PortletExternalContext


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package org.springframework.webflow.context.portlet;
17
18 import java.util.Map JavaDoc;
19
20 import javax.portlet.PortletContext;
21 import javax.portlet.PortletRequest;
22 import javax.portlet.PortletResponse;
23 import javax.portlet.PortletSession;
24
25 import org.springframework.core.style.ToStringCreator;
26 import org.springframework.webflow.context.ExternalContext;
27 import org.springframework.webflow.core.collection.LocalAttributeMap;
28 import org.springframework.webflow.core.collection.LocalParameterMap;
29 import org.springframework.webflow.core.collection.LocalSharedAttributeMap;
30 import org.springframework.webflow.core.collection.MutableAttributeMap;
31 import org.springframework.webflow.core.collection.ParameterMap;
32 import org.springframework.webflow.core.collection.SharedAttributeMap;
33
34 /**
35  * Provides contextual information about a JSR-168 Portlet environment that has
36  * called into Spring Web Flow.
37  *
38  * @author Keith Donald
39  */

40 public class PortletExternalContext implements ExternalContext {
41
42     /**
43      * The context.
44      */

45     private PortletContext context;
46
47     /**
48      * The request.
49      */

50     private PortletRequest request;
51
52     /**
53      * The response.
54      */

55     private PortletResponse response;
56
57     /**
58      * Create an external context wrapping given Portlet context, request and response.
59      * @param context the Portlet context
60      * @param request the Portlet request
61      * @param response the Portlet response
62      */

63     public PortletExternalContext(PortletContext context, PortletRequest request, PortletResponse response) {
64         this.context = context;
65         this.request = request;
66         this.response = response;
67     }
68
69     public String JavaDoc getContextPath() {
70         return request.getContextPath();
71     }
72
73     public String JavaDoc getDispatcherPath() {
74         return null;
75     }
76
77     public String JavaDoc getRequestPathInfo() {
78         return null;
79     }
80
81     public ParameterMap getRequestParameterMap() {
82         return new LocalParameterMap(new PortletRequestParameterMap(request));
83     }
84
85     public MutableAttributeMap getRequestMap() {
86         return new LocalAttributeMap(new PortletRequestMap(request));
87     }
88     
89     public SharedAttributeMap getSessionMap() {
90         return new LocalSharedAttributeMap(new PortletSessionMap(request, PortletSession.PORTLET_SCOPE));
91     }
92
93     public SharedAttributeMap getGlobalSessionMap() {
94         return new LocalSharedAttributeMap(new PortletSessionMap(request, PortletSession.APPLICATION_SCOPE));
95     }
96
97     public SharedAttributeMap getApplicationMap() {
98         return new LocalSharedAttributeMap(new PortletContextMap(context));
99     }
100
101     /**
102      * Returns the {@link PortletRequest#USER_INFO} map as a mutable attribute map.
103      * @return the Portlet user info
104      */

105     public MutableAttributeMap getUserInfoMap() {
106         Map JavaDoc userInfo = (Map JavaDoc)request.getAttribute(PortletRequest.USER_INFO);
107         if (userInfo != null) {
108             return new LocalAttributeMap(userInfo);
109         } else {
110             return null;
111         }
112     }
113
114     /**
115      * Returns the wrapped Portlet context.
116      */

117     public PortletContext getContext() {
118         return context;
119     }
120
121     /**
122      * Returns the wrapped Portlet request.
123      */

124     public PortletRequest getRequest() {
125         return request;
126     }
127
128     /**
129      * Returns the wrapped Portlet response.
130      */

131     public PortletResponse getResponse() {
132         return response;
133     }
134
135     public String JavaDoc toString() {
136         return new ToStringCreator(this).append("requestParameterMap", getRequestParameterMap()).toString();
137     }
138 }
Popular Tags