001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.util.servlet;
022:
023: import java.io.File;
024:
025: import java.util.ArrayList;
026: import java.util.Collections;
027: import java.util.Enumeration;
028: import java.util.HashMap;
029: import java.util.List;
030: import java.util.Map;
031:
032: import javax.servlet.http.HttpServletRequestWrapper;
033:
034: /**
035: * <a href="UploadPortletRequest.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Brian Wing Shun Chan
038: * @author Harry Mark
039: *
040: */
041: public class UploadPortletRequest extends HttpServletRequestWrapper {
042:
043: public UploadPortletRequest(UploadServletRequest req,
044: String namespace) {
045: super (req);
046:
047: _req = req;
048: _namespace = namespace;
049: }
050:
051: public String getContentType(String name) {
052: String contentType = _req.getContentType(_namespace + name);
053:
054: if (contentType == null) {
055: contentType = _req.getContentType(name);
056: }
057:
058: return contentType;
059: }
060:
061: public File getFile(String name) {
062: File file = _req.getFile(_namespace + name);
063:
064: if (file == null) {
065: file = _req.getFile(name);
066: }
067:
068: return file;
069: }
070:
071: public String getFileName(String name) {
072: String fileName = _req.getFileName(_namespace + name);
073:
074: if (fileName == null) {
075: fileName = _req.getFileName(name);
076: }
077:
078: return fileName;
079: }
080:
081: public String getFullFileName(String name) {
082: String fullFileName = _req.getFullFileName(_namespace + name);
083:
084: if (fullFileName == null) {
085: fullFileName = _req.getFullFileName(name);
086: }
087:
088: return fullFileName;
089: }
090:
091: public String getParameter(String name) {
092: String parameter = _req.getParameter(_namespace + name);
093:
094: if (parameter == null) {
095: parameter = _req.getParameter(name);
096: }
097:
098: return parameter;
099: }
100:
101: public Map getParameterMap() {
102: Map map = new HashMap();
103:
104: Enumeration enu = getParameterNames();
105:
106: while (enu.hasMoreElements()) {
107: String name = (String) enu.nextElement();
108:
109: map.put(name, getParameterValues(name));
110: }
111:
112: return map;
113: }
114:
115: public Enumeration getParameterNames() {
116: List parameterNames = new ArrayList();
117:
118: Enumeration enu = _req.getParameterNames();
119:
120: while (enu.hasMoreElements()) {
121: String name = (String) enu.nextElement();
122:
123: if (name.startsWith(_namespace)) {
124: parameterNames.add(name.substring(_namespace.length(),
125: name.length()));
126: } else {
127: parameterNames.add(name);
128: }
129: }
130:
131: return Collections.enumeration(parameterNames);
132: }
133:
134: public String[] getParameterValues(String name) {
135: String[] parameterValues = _req.getParameterValues(_namespace
136: + name);
137:
138: if (parameterValues == null) {
139: parameterValues = _req.getParameterValues(name);
140: }
141:
142: return parameterValues;
143: }
144:
145: public boolean isFormField(String name) {
146: Boolean formField = _req.isFormField(_namespace + name);
147:
148: if (formField == null) {
149: formField = _req.isFormField(name);
150: }
151:
152: if (formField == null) {
153: return true;
154: } else {
155: return formField.booleanValue();
156: }
157: }
158:
159: public void cleanUp() {
160: _req.cleanUp();
161: }
162:
163: private UploadServletRequest _req;
164: private String _namespace;
165:
166: }
|