1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.portal.upload;
24  
25  import com.liferay.portal.kernel.upload.UploadPortletRequest;
26  import com.liferay.portal.kernel.upload.UploadServletRequest;
27  
28  import java.io.File;
29  
30  import java.util.ArrayList;
31  import java.util.Collections;
32  import java.util.Enumeration;
33  import java.util.HashMap;
34  import java.util.List;
35  import java.util.Map;
36  
37  import javax.servlet.http.HttpServletRequestWrapper;
38  
39  /**
40   * <a href="UploadPortletRequestImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   * @author Harry Mark
44   */
45  public class UploadPortletRequestImpl
46      extends HttpServletRequestWrapper implements UploadPortletRequest {
47  
48      public UploadPortletRequestImpl(
49          UploadServletRequest uploadRequest, String namespace) {
50  
51          super(uploadRequest);
52  
53          _uploadRequest = uploadRequest;
54          _namespace = namespace;
55      }
56  
57      public void cleanUp() {
58          _uploadRequest.cleanUp();
59      }
60  
61      public String getContentType(String name) {
62          String contentType = _uploadRequest.getContentType(_namespace + name);
63  
64          if (contentType == null) {
65              contentType = _uploadRequest.getContentType(name);
66          }
67  
68          return contentType;
69      }
70  
71      public File getFile(String name) {
72          File file = _uploadRequest.getFile(_namespace + name);
73  
74          if (file == null) {
75              file = _uploadRequest.getFile(name);
76          }
77  
78          return file;
79      }
80  
81      public String getFileName(String name) {
82          String fileName = _uploadRequest.getFileName(_namespace + name);
83  
84          if (fileName == null) {
85              fileName = _uploadRequest.getFileName(name);
86          }
87  
88          return fileName;
89      }
90  
91      public String getFullFileName(String name) {
92          String fullFileName = _uploadRequest.getFullFileName(_namespace + name);
93  
94          if (fullFileName == null) {
95              fullFileName = _uploadRequest.getFullFileName(name);
96          }
97  
98          return fullFileName;
99      }
100 
101     public String getParameter(String name) {
102         String parameter = _uploadRequest.getParameter(_namespace + name);
103 
104         if (parameter == null) {
105             parameter = _uploadRequest.getParameter(name);
106         }
107 
108         return parameter;
109     }
110 
111     public Map<String, String[]> getParameterMap() {
112         Map<String, String[]> map = new HashMap<String, String[]>();
113 
114         Enumeration<String> enu = getParameterNames();
115 
116         while (enu.hasMoreElements()) {
117             String name = enu.nextElement();
118 
119             map.put(name, getParameterValues(name));
120         }
121 
122         return map;
123     }
124 
125     public Enumeration<String> getParameterNames() {
126         List<String> parameterNames = new ArrayList<String>();
127 
128         Enumeration<String> enu = _uploadRequest.getParameterNames();
129 
130         while (enu.hasMoreElements()) {
131             String name = enu.nextElement();
132 
133             if (name.startsWith(_namespace)) {
134                 parameterNames.add(
135                     name.substring(_namespace.length(), name.length()));
136             }
137             else {
138                 parameterNames.add(name);
139             }
140         }
141 
142         return Collections.enumeration(parameterNames);
143     }
144 
145     public String[] getParameterValues(String name) {
146         String[] parameterValues = _uploadRequest.getParameterValues(
147             _namespace + name);
148 
149         if (parameterValues == null) {
150             parameterValues = _uploadRequest.getParameterValues(name);
151         }
152 
153         return parameterValues;
154     }
155 
156     public boolean isFormField(String name) {
157         Boolean formField = _uploadRequest.isFormField(_namespace + name);
158 
159         if (formField == null) {
160             formField = _uploadRequest.isFormField(name);
161         }
162 
163         if (formField == null) {
164             return true;
165         }
166         else {
167             return formField.booleanValue();
168         }
169     }
170 
171     private UploadServletRequest _uploadRequest;
172     private String _namespace;
173 
174 }