1   /**
2    * Copyright (c) 2000-2008 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.StringMaker;
26  import com.liferay.portal.kernel.util.StringPool;
27  
28  import java.util.Collections;
29  import java.util.Enumeration;
30  import java.util.Map;
31  
32  import javax.servlet.http.HttpServletRequest;
33  import javax.servlet.http.HttpServletRequestWrapper;
34  
35  /**
36   * <a href="WAIHttpServletRequest.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Jorge Ferrer
39   *
40   */
41  public class WAIHttpServletRequest extends HttpServletRequestWrapper {
42  
43      public WAIHttpServletRequest(
44          HttpServletRequest req, String contextPath, String pathInfo,
45          String queryString, Map<String, String[]> params) {
46  
47          super(req);
48  
49          _contextPath = contextPath;
50          _pathInfo = pathInfo;
51          _queryString = queryString;
52          _params = params;
53      }
54  
55      public String getContextPath() {
56          return _contextPath;
57      }
58  
59      public String getPathInfo() {
60          return super.getPathInfo();
61      }
62  
63      public String getQueryString() {
64          return _queryString;
65      }
66  
67      public String getRequestURI() {
68          StringMaker sm = new StringMaker();
69  
70          sm.append(getContextPath());
71          sm.append(_pathInfo);
72  
73          if (getQueryString().trim().length() > 0) {
74              sm.append(StringPool.QUESTION);
75              sm.append(getQueryString());
76          }
77  
78          return sm.toString();
79      }
80  
81      public StringBuffer getRequestURL() {
82          return new StringBuffer(getRequestURI());
83      }
84  
85      public Map<String, String[]> getParameterMap() {
86          return _params;
87      }
88  
89      public Enumeration<String> getParameterNames() {
90          return Collections.enumeration(_params.keySet());
91      }
92  
93      public String getParameter(String key) {
94          String[] values = _params.get(key);
95  
96          if (values == null) {
97              return null;
98          }
99  
100         return values[0];
101     }
102 
103     public String[] getParameterValues(String key) {
104         return _params.get(key);
105     }
106 
107     private String _contextPath;
108     private String _pathInfo;
109     private String _queryString;
110     private Map<String, String[]> _params;
111 
112 }