| 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 public class WAIHttpServletRequest extends HttpServletRequestWrapper {
40
41 public WAIHttpServletRequest(
42 HttpServletRequest request, String contextPath, String pathInfo,
43 String queryString, Map<String, String[]> params) {
44
45 super(request);
46
47 _contextPath = contextPath;
48 _pathInfo = pathInfo;
49 _queryString = queryString;
50 _params = params;
51 }
52
53 public String getContextPath() {
54 return _contextPath;
55 }
56
57 public String getPathInfo() {
58 return super.getPathInfo();
59 }
60
61 public String getQueryString() {
62 return _queryString;
63 }
64
65 public String getRequestURI() {
66 StringBuilder sb = new StringBuilder();
67
68 sb.append(getContextPath());
69 sb.append(_pathInfo);
70
71 if (getQueryString().trim().length() > 0) {
72 sb.append(StringPool.QUESTION);
73 sb.append(getQueryString());
74 }
75
76 return sb.toString();
77 }
78
79 public StringBuffer getRequestURL() {
80 return new StringBuffer(getRequestURI());
81 }
82
83 public Map<String, String[]> getParameterMap() {
84 return _params;
85 }
86
87 public Enumeration<String> getParameterNames() {
88 return Collections.enumeration(_params.keySet());
89 }
90
91 public String getParameter(String key) {
92 String[] values = _params.get(key);
93
94 if (values == null) {
95 return null;
96 }
97
98 return values[0];
99 }
100
101 public String[] getParameterValues(String key) {
102 return _params.get(key);
103 }
104
105 private String _contextPath;
106 private String _pathInfo;
107 private String _queryString;
108 private Map<String, String[]> _params;
109
110 }