1   /**
2    * Copyright (c) 2000-2007 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.servlet;
24  
25  import java.io.File;
26  
27  import java.util.ArrayList;
28  import java.util.Collections;
29  import java.util.Enumeration;
30  import java.util.HashMap;
31  import java.util.List;
32  import java.util.Map;
33  
34  import javax.servlet.http.HttpServletRequestWrapper;
35  
36  /**
37   * <a href="UploadPortletRequest.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   * @author Harry Mark
41   *
42   */
43  public class UploadPortletRequest extends HttpServletRequestWrapper {
44  
45      public UploadPortletRequest(UploadServletRequest req, String namespace) {
46          super(req);
47  
48          _req = req;
49          _namespace = namespace;
50      }
51  
52      public String getContentType(String name) {
53          String contentType = _req.getContentType(_namespace + name);
54  
55          if (contentType == null) {
56              contentType = _req.getContentType(name);
57          }
58  
59          return contentType;
60      }
61  
62      public File getFile(String name) {
63          File file = _req.getFile(_namespace + name);
64  
65          if (file == null) {
66              file = _req.getFile(name);
67          }
68  
69          return file;
70      }
71  
72      public String getFileName(String name) {
73          String fileName = _req.getFileName(_namespace + name);
74  
75          if (fileName == null) {
76              fileName = _req.getFileName(name);
77          }
78  
79          return fileName;
80      }
81  
82      public String getFullFileName(String name) {
83          String fullFileName = _req.getFullFileName(_namespace + name);
84  
85          if (fullFileName == null) {
86              fullFileName = _req.getFullFileName(name);
87          }
88  
89          return fullFileName;
90      }
91  
92      public String getParameter(String name) {
93          String parameter = _req.getParameter(_namespace + name);
94  
95          if (parameter == null) {
96              parameter = _req.getParameter(name);
97          }
98  
99          return parameter;
100     }
101 
102     public Map getParameterMap() {
103         Map map = new HashMap();
104 
105         Enumeration enu = getParameterNames();
106 
107         while (enu.hasMoreElements()) {
108             String name = (String)enu.nextElement();
109 
110             map.put(name, getParameterValues(name));
111         }
112 
113         return map;
114     }
115 
116     public Enumeration getParameterNames() {
117         List parameterNames = new ArrayList();
118 
119         Enumeration enu = _req.getParameterNames();
120 
121         while (enu.hasMoreElements()) {
122             String name = (String)enu.nextElement();
123 
124             if (name.startsWith(_namespace)) {
125                 parameterNames.add(
126                     name.substring(_namespace.length(), name.length()));
127             }
128             else {
129                 parameterNames.add(name);
130             }
131         }
132 
133         return Collections.enumeration(parameterNames);
134     }
135 
136     public String[] getParameterValues(String name) {
137         String[] parameterValues = _req.getParameterValues(_namespace + name);
138 
139         if (parameterValues == null) {
140             parameterValues = _req.getParameterValues(name);
141         }
142 
143         return parameterValues;
144     }
145 
146     public boolean isFormField(String name) {
147         Boolean formField = _req.isFormField(_namespace + name);
148 
149         if (formField == null) {
150             formField = _req.isFormField(name);
151         }
152 
153         if (formField == null) {
154             return true;
155         }
156         else {
157             return formField.booleanValue();
158         }
159     }
160 
161     public void cleanUp() {
162         _req.cleanUp();
163     }
164 
165     private UploadServletRequest _req;
166     private String _namespace;
167 
168 }