This project has retired. For details please refer to its
Attic page.
JspRequest xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.tiles.request.jsp;
22
23 import java.io.IOException;
24 import java.io.PrintWriter;
25 import java.io.Writer;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.List;
29 import java.util.Map;
30
31 import javax.servlet.ServletException;
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34 import javax.servlet.jsp.PageContext;
35
36 import org.apache.tiles.request.AbstractViewRequest;
37 import org.apache.tiles.request.ApplicationContext;
38 import org.apache.tiles.request.DispatchRequest;
39 import org.apache.tiles.request.collection.ScopeMap;
40 import org.apache.tiles.request.jsp.extractor.ScopeExtractor;
41 import org.apache.tiles.request.jsp.extractor.SessionScopeExtractor;
42 import org.apache.tiles.request.servlet.ServletRequest;
43 import org.apache.tiles.request.servlet.ServletUtil;
44
45
46
47
48
49
50
51 public class JspRequest extends AbstractViewRequest {
52
53
54
55
56 private static final List<String> SCOPES
57 = Collections.unmodifiableList(Arrays.asList("page", REQUEST_SCOPE, "session", APPLICATION_SCOPE));
58
59
60
61
62 private PageContext pageContext;
63
64
65
66
67
68 private Map<String, Object> pageScope = null;
69
70
71
72
73
74 private Map<String, Object> requestScope = null;
75
76
77
78
79
80 private Map<String, Object> sessionScope = null;
81
82
83
84
85
86 private Map<String, Object> applicationScope = null;
87
88
89
90
91
92
93
94
95 public static JspRequest createServletJspRequest(ApplicationContext applicationContext, PageContext pageContext) {
96 return new JspRequest(new ServletRequest(
97 applicationContext, (HttpServletRequest) pageContext
98 .getRequest(), (HttpServletResponse) pageContext
99 .getResponse()), pageContext);
100 }
101
102
103
104
105
106
107
108 public JspRequest(DispatchRequest enclosedRequest,
109 PageContext pageContext) {
110 super(enclosedRequest);
111 this.pageContext = pageContext;
112 }
113
114 @Override
115 public List<String> getAvailableScopes() {
116 return SCOPES;
117 }
118
119
120 @Override
121 protected void doInclude(String path) throws IOException {
122 try {
123 pageContext.include(path, false);
124 } catch (ServletException e) {
125 throw ServletUtil.wrapServletException(e, "JSPException including path '"
126 + path + "'.");
127 }
128 }
129
130
131 @Override
132 public PrintWriter getPrintWriter() {
133 return new JspPrintWriterAdapter(pageContext.getOut());
134 }
135
136
137 @Override
138 public Writer getWriter() {
139 return pageContext.getOut();
140 }
141
142
143
144
145
146
147 public Map<String, Object> getPageScope() {
148 if ((pageScope == null) && (pageContext != null)) {
149 pageScope = new ScopeMap(new ScopeExtractor(pageContext,
150 PageContext.PAGE_SCOPE));
151 }
152 return (pageScope);
153 }
154
155
156
157
158
159
160 public Map<String, Object> getRequestScope() {
161 if ((requestScope == null) && (pageContext != null)) {
162 requestScope = new ScopeMap(new ScopeExtractor(pageContext,
163 PageContext.REQUEST_SCOPE));
164 }
165 return (requestScope);
166 }
167
168
169
170
171
172
173 public Map<String, Object> getSessionScope() {
174 if ((sessionScope == null) && (pageContext != null)) {
175 sessionScope = new ScopeMap(new SessionScopeExtractor(pageContext));
176 }
177 return (sessionScope);
178 }
179
180
181
182
183
184
185 public Map<String, Object> getApplicationScope() {
186 if ((applicationScope == null) && (pageContext != null)) {
187 applicationScope = new ScopeMap(new ScopeExtractor(pageContext,
188 PageContext.APPLICATION_SCOPE));
189 }
190 return (applicationScope);
191 }
192
193
194
195
196
197
198 public PageContext getPageContext() {
199 return pageContext;
200 }
201
202 @Override
203 public Map<String, Object> getContext(String scope) {
204 if("page".equals(scope)){
205 return getPageScope();
206 }else if(REQUEST_SCOPE.equals(scope)){
207 return getRequestScope();
208 }else if("session".equals(scope)){
209 return getSessionScope();
210 }else if(APPLICATION_SCOPE.equals(scope)){
211 return getApplicationScope();
212 }
213 throw new IllegalArgumentException(scope + " does not exist. Call getAvailableScopes() first to check.");
214 }
215 }