1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.util.bridges.wai;
16  
17  import com.liferay.portal.kernel.util.StringBundler;
18  import com.liferay.portal.kernel.util.StringPool;
19  
20  import java.util.Collections;
21  import java.util.Enumeration;
22  import java.util.Map;
23  
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.http.HttpServletRequestWrapper;
26  
27  /**
28   * <a href="WAIHttpServletRequest.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Jorge Ferrer
31   */
32  public class WAIHttpServletRequest extends HttpServletRequestWrapper {
33  
34      public WAIHttpServletRequest(
35          HttpServletRequest request, String contextPath, String pathInfo,
36          String queryString, Map<String, String[]> params) {
37  
38          super(request);
39  
40          _contextPath = contextPath;
41          _pathInfo = pathInfo;
42          _queryString = queryString;
43          _params = params;
44      }
45  
46      public String getContextPath() {
47          return _contextPath;
48      }
49  
50      public String getPathInfo() {
51          return super.getPathInfo();
52      }
53  
54      public String getQueryString() {
55          return _queryString;
56      }
57  
58      public String getRequestURI() {
59          StringBundler sb = new StringBundler(4);
60  
61          sb.append(getContextPath());
62          sb.append(_pathInfo);
63  
64          if (getQueryString().trim().length() > 0) {
65              sb.append(StringPool.QUESTION);
66              sb.append(getQueryString());
67          }
68  
69          return sb.toString();
70      }
71  
72      public StringBuffer getRequestURL() {
73          return new StringBuffer(getRequestURI());
74      }
75  
76      public Map<String, String[]> getParameterMap() {
77          return _params;
78      }
79  
80      public Enumeration<String> getParameterNames() {
81          return Collections.enumeration(_params.keySet());
82      }
83  
84      public String getParameter(String key) {
85          String[] values = _params.get(key);
86  
87          if (values == null) {
88              return null;
89          }
90  
91          return values[0];
92      }
93  
94      public String[] getParameterValues(String key) {
95          return _params.get(key);
96      }
97  
98      private String _contextPath;
99      private String _pathInfo;
100     private String _queryString;
101     private Map<String, String[]> _params;
102 
103 }