01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import java.io.UnsupportedEncodingException;
18: import java.util.List;
19: import java.util.Locale;
20:
21: import javax.servlet.http.HttpServletRequest;
22: import javax.servlet.http.HttpSession;
23:
24: import org.apache.tapestry.ioc.internal.util.InternalUtils;
25: import org.apache.tapestry.services.Request;
26: import org.apache.tapestry.services.Session;
27:
28: /**
29: * Basic implementation of {@link org.apache.tapestry.services.Request} that wraps around an
30: * {@link javax.servlet.http.HttpServletRequest}.
31: */
32: public class RequestImpl implements Request {
33: private final HttpServletRequest _request;
34:
35: public RequestImpl(HttpServletRequest request) {
36: _request = request;
37: }
38:
39: public List<String> getParameterNames() {
40: return InternalUtils.toList(_request.getParameterNames());
41: }
42:
43: public List<String> getHeaderNames() {
44: return InternalUtils.toList(_request.getHeaderNames());
45: }
46:
47: public String getParameter(String name) {
48: return _request.getParameter(name);
49: }
50:
51: public String[] getParameters(String name) {
52: return _request.getParameterValues(name);
53: }
54:
55: public String getHeader(String name) {
56: return _request.getHeader(name);
57: }
58:
59: public String getPath() {
60: return _request.getServletPath();
61: }
62:
63: public String getContextPath() {
64: return _request.getContextPath();
65: }
66:
67: public Session getSession(boolean create) {
68: HttpSession session = _request.getSession(create);
69:
70: return session == null ? null : new SessionImpl(session);
71: }
72:
73: public Locale getLocale() {
74: return _request.getLocale();
75: }
76:
77: public long getDateHeader(String name) {
78: return _request.getDateHeader(name);
79: }
80:
81: public void setEncoding(String requestEncoding) {
82: try {
83: _request.setCharacterEncoding(requestEncoding);
84: } catch (UnsupportedEncodingException ex) {
85: throw new RuntimeException(ex);
86: }
87: }
88:
89: }
|