| WAIHttpServletRequest.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.liferay.util.bridges.wai;
24
25 import com.liferay.portal.kernel.util.StringPool;
26
27 import java.util.Collections;
28 import java.util.Enumeration;
29 import java.util.Map;
30
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletRequestWrapper;
33
34 /**
35 * <a href="WAIHttpServletRequest.java.html"><b><i>View Source</i></b></a>
36 *
37 * @author Jorge Ferrer
38 *
39 */
40 public class WAIHttpServletRequest extends HttpServletRequestWrapper {
41
42 public WAIHttpServletRequest(
43 HttpServletRequest request, String contextPath, String pathInfo,
44 String queryString, Map<String, String[]> params) {
45
46 super(request);
47
48 _contextPath = contextPath;
49 _pathInfo = pathInfo;
50 _queryString = queryString;
51 _params = params;
52 }
53
54 public String getContextPath() {
55 return _contextPath;
56 }
57
58 public String getPathInfo() {
59 return super.getPathInfo();
60 }
61
62 public String getQueryString() {
63 return _queryString;
64 }
65
66 public String getRequestURI() {
67 StringBuilder sb = new StringBuilder();
68
69 sb.append(getContextPath());
70 sb.append(_pathInfo);
71
72 if (getQueryString().trim().length() > 0) {
73 sb.append(StringPool.QUESTION);
74 sb.append(getQueryString());
75 }
76
77 return sb.toString();
78 }
79
80 public StringBuffer getRequestURL() {
81 return new StringBuffer(getRequestURI());
82 }
83
84 public Map<String, String[]> getParameterMap() {
85 return _params;
86 }
87
88 public Enumeration<String> getParameterNames() {
89 return Collections.enumeration(_params.keySet());
90 }
91
92 public String getParameter(String key) {
93 String[] values = _params.get(key);
94
95 if (values == null) {
96 return null;
97 }
98
99 return values[0];
100 }
101
102 public String[] getParameterValues(String key) {
103 return _params.get(key);
104 }
105
106 private String _contextPath;
107 private String _pathInfo;
108 private String _queryString;
109 private Map<String, String[]> _params;
110
111 }