KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > context > servlet > ServletExternalContext


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.servlet;
17
18 import javax.servlet.ServletContext JavaDoc;
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21
22 import org.springframework.core.style.ToStringCreator;
23 import org.springframework.webflow.context.ExternalContext;
24 import org.springframework.webflow.core.collection.LocalAttributeMap;
25 import org.springframework.webflow.core.collection.LocalParameterMap;
26 import org.springframework.webflow.core.collection.LocalSharedAttributeMap;
27 import org.springframework.webflow.core.collection.MutableAttributeMap;
28 import org.springframework.webflow.core.collection.ParameterMap;
29 import org.springframework.webflow.core.collection.SharedAttributeMap;
30
31 /**
32  * Provides contextual information about an HTTP Servlet environment that has
33  * interacted with Spring Web Flow.
34  *
35  * @author Keith Donald
36  * @author Erwin Vervaet
37  */

38 public class ServletExternalContext implements ExternalContext {
39
40     /**
41      * The context.
42      */

43     private ServletContext JavaDoc context;
44
45     /**
46      * The request.
47      */

48     private HttpServletRequest JavaDoc request;
49
50     /**
51      * The response.
52      */

53     private HttpServletResponse JavaDoc response;
54
55     /**
56      * Create a new external context wrapping given servlet HTTP request and
57      * response and given servlet context.
58      * @param context the servlet context
59      * @param request the HTTP request
60      * @param response the HTTP response
61      */

62     public ServletExternalContext(ServletContext JavaDoc context, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
63         this.context = context;
64         this.request = request;
65         this.response = response;
66     }
67
68     public String JavaDoc getContextPath() {
69         return request.getContextPath();
70     }
71
72     public String JavaDoc getDispatcherPath() {
73         return request.getServletPath();
74     }
75
76     public String JavaDoc getRequestPathInfo() {
77         return request.getPathInfo();
78     }
79
80     public ParameterMap getRequestParameterMap() {
81         return new LocalParameterMap(new HttpServletRequestParameterMap(request));
82     }
83
84     public MutableAttributeMap getRequestMap() {
85         return new LocalAttributeMap(new HttpServletRequestMap(request));
86     }
87
88     public SharedAttributeMap getSessionMap() {
89         return new LocalSharedAttributeMap(new HttpSessionMap(request));
90     }
91
92     public SharedAttributeMap getGlobalSessionMap() {
93         return getSessionMap();
94     }
95     
96     public SharedAttributeMap getApplicationMap() {
97         return new LocalSharedAttributeMap(new HttpServletContextMap(context));
98     }
99
100     /**
101      * Return the wrapped HTTP servlet context.
102      */

103     public ServletContext JavaDoc getContext() {
104         return context;
105     }
106
107     /**
108      * Return the wrapped HTTP servlet request.
109      */

110     public HttpServletRequest JavaDoc getRequest() {
111         return request;
112     }
113
114     /**
115      * Return the wrapped HTTP servlet response.
116      */

117     public HttpServletResponse JavaDoc getResponse() {
118         return response;
119     }
120
121     public String JavaDoc toString() {
122         return new ToStringCreator(this).append("requestParameterMap", getRequestParameterMap()).toString();
123     }
124 }
Popular Tags