/*
- * Copyright (C) 2001, 2002 The Mir-coders group
+ * Copyright (C) 2001, 2002 The Mir-coders group
*
* This file is part of Mir.
*
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with the com.oreilly.servlet library, any library
- * licensed under the Apache Software License, The Sun (tm) Java Advanced
- * Imaging library (JAI), The Sun JIMI library (or with modified versions of
- * the above that use the same license as the above), and distribute linked
- * combinations including the two. You must obey the GNU General Public
- * License in all respects for all of the code used other than the above
- * mentioned libraries. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If you do
- * not wish to do so, delete this exception statement from your version.
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
*/
-
package mir.util;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.commons.fileupload.FileItem;
-import org.apache.commons.fileupload.FileUpload;
import mir.log.LoggerWrapper;
+import org.apache.commons.fileupload.DiskFileUpload;
+import org.apache.commons.fileupload.FileItem;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.*;
public class HTTPParsedRequest {
static final String MULTIPART_FORMDATA_CONTENTTYPE = "multipart/form-data";
private int maxUploadSize;
private String tempDir;
- private Map stringValues;
- private Map listValues;
+ private Map parameterStringValues;
+ private Map parameterListValues;
private List files;
- private LoggerWrapper logger;
+ private LoggerWrapper logger = new LoggerWrapper("Utility.HTTPParsedRequest");
public HTTPParsedRequest(HttpServletRequest aRequest, String anEncoding, int aMaxUploadSize, String aTempDir) throws UtilExc, UtilFailure {
- logger = new LoggerWrapper("Utility,HTTPParsedRequest");
-
request = aRequest;
encoding = anEncoding;
maxUploadSize = aMaxUploadSize;
tempDir = aTempDir;
- stringValues = new HashMap();
- listValues = new HashMap();
- files = new Vector();
+ parameterStringValues = new HashMap();
+ parameterListValues = new HashMap();
+ files = new ArrayList();
parseRequest(aRequest);
}
}
public String getParameter(String aName) {
- return (String) stringValues.get(aName);
+ return (String) parameterStringValues.get(aName);
+ }
+
+ public Collection getParameterNames() {
+ return parameterStringValues.keySet();
+ }
+
+ public String getHeader(String aName) {
+ return request.getHeader(aName);
}
public List getFiles() {
}
public List getParameterList(String aName) {
- if (listValues.containsKey(aName))
- return (List) listValues.get(aName);
+ if (parameterListValues.containsKey(aName))
+ return (List) parameterListValues.get(aName);
else
- return new Vector();
+ return Collections.EMPTY_LIST;
}
protected void parseRequest(HttpServletRequest aRequest) throws UtilExc, UtilFailure {
while (e.hasMoreElements()) {
String name = (String) e.nextElement();
- stringValues.put(name, aRequest.getParameter(name));
- List listValue = new Vector(Arrays.asList(aRequest.getParameterValues(name)));
- listValues.put(name, listValue);
+ parameterStringValues.put(name, aRequest.getParameter(name));
+ List listValue = new ArrayList(Arrays.asList(aRequest.getParameterValues(name)));
+ parameterListValues.put(name, listValue);
}
if (parts.size()>0 && ((String) parts.get(0)).trim().toLowerCase().equals(MULTIPART_FORMDATA_CONTENTTYPE)) {
protected void parseMultipartRequest() throws UtilExc, UtilFailure {
try {
- FileUpload upload = new FileUpload();
+ DiskFileUpload upload = new DiskFileUpload();
+ upload.setSizeThreshold(100000);
upload.setSizeMax(maxUploadSize);
- upload.setSizeThreshold(4096);
+ upload.setHeaderEncoding(encoding);
upload.setRepositoryPath(tempDir);
List items = upload.parseRequest(request);
FileItem item = (FileItem) i.next();
if (item.isFormField()) {
- if (!stringValues.containsKey(item.getName())) {
- stringValues.put(item.getFieldName(), item.getString(encoding));
+ if (!parameterStringValues.containsKey(item.getName())) {
+ parameterStringValues.put(item.getFieldName(), item.getString(encoding));
}
- List listValue = (List) listValues.get(item.getFieldName());
+ List listValue = (List) parameterListValues.get(item.getFieldName());
if (listValue == null) {
- listValue = new Vector();
- listValues.put(item.getFieldName(), listValue);
+ listValue = new ArrayList();
+ parameterListValues.put(item.getFieldName(), listValue);
}
listValue.add(item.getString(encoding));
}