1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.upload;
21  
22  import com.liferay.portal.kernel.upload.UploadPortletRequest;
23  import com.liferay.portal.kernel.upload.UploadServletRequest;
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="UploadPortletRequestImpl.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 UploadPortletRequestImpl
44      extends HttpServletRequestWrapper implements UploadPortletRequest {
45  
46      public UploadPortletRequestImpl(
47          UploadServletRequest uploadRequest, String namespace) {
48  
49          super(uploadRequest);
50  
51          _uploadRequest = uploadRequest;
52          _namespace = namespace;
53      }
54  
55      public void cleanUp() {
56          _uploadRequest.cleanUp();
57      }
58  
59      public String getContentType(String name) {
60          String contentType = _uploadRequest.getContentType(_namespace + name);
61  
62          if (contentType == null) {
63              contentType = _uploadRequest.getContentType(name);
64          }
65  
66          return contentType;
67      }
68  
69      public File getFile(String name) {
70          File file = _uploadRequest.getFile(_namespace + name);
71  
72          if (file == null) {
73              file = _uploadRequest.getFile(name);
74          }
75  
76          return file;
77      }
78  
79      public String getFileName(String name) {
80          String fileName = _uploadRequest.getFileName(_namespace + name);
81  
82          if (fileName == null) {
83              fileName = _uploadRequest.getFileName(name);
84          }
85  
86          return fileName;
87      }
88  
89      public String getFullFileName(String name) {
90          String fullFileName = _uploadRequest.getFullFileName(_namespace + name);
91  
92          if (fullFileName == null) {
93              fullFileName = _uploadRequest.getFullFileName(name);
94          }
95  
96          return fullFileName;
97      }
98  
99      public String getParameter(String name) {
100         String parameter = _uploadRequest.getParameter(_namespace + name);
101 
102         if (parameter == null) {
103             parameter = _uploadRequest.getParameter(name);
104         }
105 
106         return parameter;
107     }
108 
109     public Map<String, String[]> getParameterMap() {
110         Map<String, String[]> map = new HashMap<String, String[]>();
111 
112         Enumeration<String> enu = getParameterNames();
113 
114         while (enu.hasMoreElements()) {
115             String name = enu.nextElement();
116 
117             map.put(name, getParameterValues(name));
118         }
119 
120         return map;
121     }
122 
123     public Enumeration<String> getParameterNames() {
124         List<String> parameterNames = new ArrayList<String>();
125 
126         Enumeration<String> enu = _uploadRequest.getParameterNames();
127 
128         while (enu.hasMoreElements()) {
129             String name = enu.nextElement();
130 
131             if (name.startsWith(_namespace)) {
132                 parameterNames.add(
133                     name.substring(_namespace.length(), name.length()));
134             }
135             else {
136                 parameterNames.add(name);
137             }
138         }
139 
140         return Collections.enumeration(parameterNames);
141     }
142 
143     public String[] getParameterValues(String name) {
144         String[] parameterValues = _uploadRequest.getParameterValues(
145             _namespace + name);
146 
147         if (parameterValues == null) {
148             parameterValues = _uploadRequest.getParameterValues(name);
149         }
150 
151         return parameterValues;
152     }
153 
154     public boolean isFormField(String name) {
155         Boolean formField = _uploadRequest.isFormField(_namespace + name);
156 
157         if (formField == null) {
158             formField = _uploadRequest.isFormField(name);
159         }
160 
161         if (formField == null) {
162             return true;
163         }
164         else {
165             return formField.booleanValue();
166         }
167     }
168 
169     private UploadServletRequest _uploadRequest;
170     private String _namespace;
171 
172 }