|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ServletRequestWrapper.java | 0% | 0% | 0% | 0% |
|
1 | /* | |
2 | * Copyright 2004 The Apache Software Foundation | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of 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, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package javax.servlet; | |
17 | ||
18 | import java.io.BufferedReader; | |
19 | import java.io.IOException; | |
20 | import java.util.Enumeration; | |
21 | import java.util.Locale; | |
22 | import java.util.Map; | |
23 | ||
24 | ||
25 | ||
26 | /** | |
27 | * | |
28 | * Provides a convenient implementation of the ServletRequest interface that | |
29 | * can be subclassed by developers wishing to adapt the request to a Servlet. | |
30 | * This class implements the Wrapper or Decorator pattern. Methods default to | |
31 | * calling through to the wrapped request object. | |
32 | * @since v 2.3 | |
33 | * | |
34 | * | |
35 | * | |
36 | * @see javax.servlet.ServletRequest | |
37 | * | |
38 | */ | |
39 | ||
40 | public class ServletRequestWrapper implements ServletRequest { | |
41 | private ServletRequest request; | |
42 | ||
43 | /** | |
44 | * Creates a ServletRequest adaptor wrapping the given request object. | |
45 | * @throws java.lang.IllegalArgumentException if the request is null | |
46 | */ | |
47 | ||
48 | 0 | public ServletRequestWrapper(ServletRequest request) { |
49 | 0 | if (request == null) { |
50 | 0 | throw new IllegalArgumentException("Request cannot be null"); |
51 | } | |
52 | 0 | this.request = request; |
53 | } | |
54 | ||
55 | /** | |
56 | * Return the wrapped request object. | |
57 | */ | |
58 | 0 | public ServletRequest getRequest() { |
59 | 0 | return this.request; |
60 | } | |
61 | ||
62 | /** | |
63 | * Sets the request object being wrapped. | |
64 | * @throws java.lang.IllegalArgumentException if the request is null. | |
65 | */ | |
66 | ||
67 | 0 | public void setRequest(ServletRequest request) { |
68 | 0 | if (request == null) { |
69 | 0 | throw new IllegalArgumentException("Request cannot be null"); |
70 | } | |
71 | 0 | this.request = request; |
72 | } | |
73 | ||
74 | /** | |
75 | * | |
76 | * The default behavior of this method is to call getAttribute(String name) | |
77 | * on the wrapped request object. | |
78 | */ | |
79 | ||
80 | 0 | public Object getAttribute(String name) { |
81 | 0 | return this.request.getAttribute(name); |
82 | } | |
83 | ||
84 | ||
85 | ||
86 | /** | |
87 | * The default behavior of this method is to return getAttributeNames() | |
88 | * on the wrapped request object. | |
89 | */ | |
90 | ||
91 | 0 | public Enumeration getAttributeNames() { |
92 | 0 | return this.request.getAttributeNames(); |
93 | } | |
94 | ||
95 | ||
96 | ||
97 | /** | |
98 | * The default behavior of this method is to return getCharacterEncoding() | |
99 | * on the wrapped request object. | |
100 | */ | |
101 | ||
102 | 0 | public String getCharacterEncoding() { |
103 | 0 | return this.request.getCharacterEncoding(); |
104 | } | |
105 | ||
106 | /** | |
107 | * The default behavior of this method is to set the character encoding | |
108 | * on the wrapped request object. | |
109 | */ | |
110 | ||
111 | 0 | public void setCharacterEncoding(String enc) throws java.io.UnsupportedEncodingException { |
112 | 0 | this.request.setCharacterEncoding(enc); |
113 | } | |
114 | ||
115 | ||
116 | /** | |
117 | * The default behavior of this method is to return getContentLength() | |
118 | * on the wrapped request object. | |
119 | */ | |
120 | ||
121 | 0 | public int getContentLength() { |
122 | 0 | return this.request.getContentLength(); |
123 | } | |
124 | ||
125 | ||
126 | ||
127 | ||
128 | /** | |
129 | * The default behavior of this method is to return getContentType() | |
130 | * on the wrapped request object. | |
131 | */ | |
132 | 0 | public String getContentType() { |
133 | 0 | return this.request.getContentType(); |
134 | } | |
135 | ||
136 | ||
137 | ||
138 | ||
139 | /** | |
140 | * The default behavior of this method is to return getInputStream() | |
141 | * on the wrapped request object. | |
142 | */ | |
143 | ||
144 | 0 | public ServletInputStream getInputStream() throws IOException { |
145 | 0 | return this.request.getInputStream(); |
146 | } | |
147 | ||
148 | ||
149 | ||
150 | ||
151 | /** | |
152 | * The default behavior of this method is to return getParameter(String name) | |
153 | * on the wrapped request object. | |
154 | */ | |
155 | ||
156 | 0 | public String getParameter(String name) { |
157 | 0 | return this.request.getParameter(name); |
158 | } | |
159 | ||
160 | /** | |
161 | * The default behavior of this method is to return getParameterMap() | |
162 | * on the wrapped request object. | |
163 | */ | |
164 | 0 | public Map getParameterMap() { |
165 | 0 | return this.request.getParameterMap(); |
166 | } | |
167 | ||
168 | ||
169 | ||
170 | ||
171 | /** | |
172 | * The default behavior of this method is to return getParameterNames() | |
173 | * on the wrapped request object. | |
174 | */ | |
175 | ||
176 | 0 | public Enumeration getParameterNames() { |
177 | 0 | return this.request.getParameterNames(); |
178 | } | |
179 | ||
180 | ||
181 | ||
182 | ||
183 | /** | |
184 | * The default behavior of this method is to return getParameterValues(String name) | |
185 | * on the wrapped request object. | |
186 | */ | |
187 | 0 | public String[] getParameterValues(String name) { |
188 | 0 | return this.request.getParameterValues(name); |
189 | } | |
190 | ||
191 | ||
192 | ||
193 | ||
194 | /** | |
195 | * The default behavior of this method is to return getProtocol() | |
196 | * on the wrapped request object. | |
197 | */ | |
198 | ||
199 | 0 | public String getProtocol() { |
200 | 0 | return this.request.getProtocol(); |
201 | } | |
202 | ||
203 | ||
204 | ||
205 | ||
206 | /** | |
207 | * The default behavior of this method is to return getScheme() | |
208 | * on the wrapped request object. | |
209 | */ | |
210 | ||
211 | ||
212 | 0 | public String getScheme() { |
213 | 0 | return this.request.getScheme(); |
214 | } | |
215 | ||
216 | ||
217 | ||
218 | ||
219 | /** | |
220 | * The default behavior of this method is to return getServerName() | |
221 | * on the wrapped request object. | |
222 | */ | |
223 | 0 | public String getServerName() { |
224 | 0 | return this.request.getServerName(); |
225 | } | |
226 | ||
227 | ||
228 | ||
229 | ||
230 | /** | |
231 | * The default behavior of this method is to return getServerPort() | |
232 | * on the wrapped request object. | |
233 | */ | |
234 | ||
235 | 0 | public int getServerPort() { |
236 | 0 | return this.request.getServerPort(); |
237 | } | |
238 | ||
239 | ||
240 | ||
241 | /** | |
242 | * The default behavior of this method is to return getReader() | |
243 | * on the wrapped request object. | |
244 | */ | |
245 | ||
246 | 0 | public BufferedReader getReader() throws IOException { |
247 | 0 | return this.request.getReader(); |
248 | } | |
249 | ||
250 | ||
251 | ||
252 | ||
253 | /** | |
254 | * The default behavior of this method is to return getRemoteAddr() | |
255 | * on the wrapped request object. | |
256 | */ | |
257 | ||
258 | 0 | public String getRemoteAddr() { |
259 | 0 | return this.request.getRemoteAddr(); |
260 | } | |
261 | ||
262 | ||
263 | ||
264 | ||
265 | /** | |
266 | * The default behavior of this method is to return getRemoteHost() | |
267 | * on the wrapped request object. | |
268 | */ | |
269 | ||
270 | 0 | public String getRemoteHost() { |
271 | 0 | return this.request.getRemoteHost(); |
272 | } | |
273 | ||
274 | ||
275 | ||
276 | ||
277 | /** | |
278 | * The default behavior of this method is to return setAttribute(String name, Object o) | |
279 | * on the wrapped request object. | |
280 | */ | |
281 | ||
282 | 0 | public void setAttribute(String name, Object o) { |
283 | 0 | this.request.setAttribute(name, o); |
284 | } | |
285 | ||
286 | ||
287 | ||
288 | ||
289 | /** | |
290 | * The default behavior of this method is to call removeAttribute(String name) | |
291 | * on the wrapped request object. | |
292 | */ | |
293 | 0 | public void removeAttribute(String name) { |
294 | 0 | this.request.removeAttribute(name); |
295 | } | |
296 | ||
297 | ||
298 | ||
299 | ||
300 | /** | |
301 | * The default behavior of this method is to return getLocale() | |
302 | * on the wrapped request object. | |
303 | */ | |
304 | ||
305 | 0 | public Locale getLocale() { |
306 | 0 | return this.request.getLocale(); |
307 | } | |
308 | ||
309 | ||
310 | ||
311 | ||
312 | /** | |
313 | * The default behavior of this method is to return getLocales() | |
314 | * on the wrapped request object. | |
315 | */ | |
316 | ||
317 | 0 | public Enumeration getLocales() { |
318 | 0 | return this.request.getLocales(); |
319 | } | |
320 | ||
321 | ||
322 | ||
323 | ||
324 | /** | |
325 | * The default behavior of this method is to return isSecure() | |
326 | * on the wrapped request object. | |
327 | */ | |
328 | ||
329 | 0 | public boolean isSecure() { |
330 | 0 | return this.request.isSecure(); |
331 | } | |
332 | ||
333 | ||
334 | ||
335 | ||
336 | /** | |
337 | * The default behavior of this method is to return getRequestDispatcher(String path) | |
338 | * on the wrapped request object. | |
339 | */ | |
340 | ||
341 | 0 | public RequestDispatcher getRequestDispatcher(String path) { |
342 | 0 | return this.request.getRequestDispatcher(path); |
343 | } | |
344 | ||
345 | ||
346 | ||
347 | ||
348 | /** | |
349 | * The default behavior of this method is to return getRealPath(String path) | |
350 | * on the wrapped request object. | |
351 | */ | |
352 | ||
353 | 0 | public String getRealPath(String path) { |
354 | 0 | return this.request.getRealPath(path); |
355 | } | |
356 | ||
357 | /** | |
358 | * The default behavior of this method is to return | |
359 | * getRemotePort() on the wrapped request object. | |
360 | * | |
361 | * @since 2.4 | |
362 | */ | |
363 | 0 | public int getRemotePort(){ |
364 | 0 | return this.request.getRemotePort(); |
365 | } | |
366 | ||
367 | ||
368 | /** | |
369 | * The default behavior of this method is to return | |
370 | * getLocalName() on the wrapped request object. | |
371 | * | |
372 | * @since 2.4 | |
373 | */ | |
374 | 0 | public String getLocalName(){ |
375 | 0 | return this.request.getLocalName(); |
376 | } | |
377 | ||
378 | /** | |
379 | * The default behavior of this method is to return | |
380 | * getLocalAddr() on the wrapped request object. | |
381 | * | |
382 | * @since 2.4 | |
383 | */ | |
384 | 0 | public String getLocalAddr(){ |
385 | 0 | return this.request.getLocalAddr(); |
386 | } | |
387 | ||
388 | ||
389 | /** | |
390 | * The default behavior of this method is to return | |
391 | * getLocalPort() on the wrapped request object. | |
392 | * | |
393 | * @since 2.4 | |
394 | */ | |
395 | 0 | public int getLocalPort(){ |
396 | 0 | return this.request.getLocalPort(); |
397 | } | |
398 | ||
399 | } | |
400 |
|