package mir.misc;
-import java.util.*;
-import java.io.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
-import com.oreilly.servlet.multipart.*;
-import com.oreilly.servlet.*;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.servlet.http.HttpServletRequest;
+
+import mir.config.MirPropertiesConfiguration;
+import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
+
+import com.oreilly.servlet.multipart.FilePart;
+import com.oreilly.servlet.multipart.MultipartParser;
+import com.oreilly.servlet.multipart.ParamPart;
+import com.oreilly.servlet.multipart.Part;
/**
* Title:
HttpServletRequest req=null;
Hashtable parameters = new Hashtable();
MultipartParser mp=null;
- public static ArrayList requestList;
+ FileHandler _fHandler;
- public WebdbMultipartRequest(HttpServletRequest theReq) throws IOException
+ public WebdbMultipartRequest(HttpServletRequest theReq, FileHandler handler)
+ throws FileHandlerException, FileHandlerUserException, IOException, PropertiesConfigExc
{
req=theReq;
- int maxSize = Integer.parseInt(MirConfig.getProp("MaxMediaUploadSize"));
+ int maxSize;
+ try {
+ maxSize =
+ MirPropertiesConfiguration.instance().getInt("MaxMediaUploadSize");
+ } catch (PropertiesConfigExc e) {
+ maxSize = 1024;
+ throw e;
+ }
mp = new MultipartParser(req, 1024*maxSize);
- requestList = new ArrayList();
+ _fHandler = handler;
_evaluateRequest();
}
/**
- * The following comment and some code was adapted from the Oreilley cos.jar
+ * The following comment and some code was adapted from the Oreilley cos.jar
* package. -mh 2001.09.20
*
- * Returns all the parameters as a HashMap of Strings, any parameter
- * that sent without a value will be null. A value
- * is guaranteed to be in its normal, decoded form. If A parameter
- * has multiple values, only the last one is returned (for backward
+ * Returns all the parameters as a Map of Strings, any parameter
+ * that sent without a value will be null. A value
+ * is guaranteed to be in its normal, decoded form. If A parameter
+ * has multiple values, only the last one is returned (for backward
* compatibility). For parameters with multiple values, it's possible
* the last "value" may be null.
*
- * @return A HashMap of String representations of the parameter values.
+ * @return A Map of String representations of the parameter values.
*/
- public HashMap getParameters(){
- HashMap pHash = new HashMap();
+ public Map getParameters(){
+ Map pHash = new HashMap();
String value = new String();
Enumeration Keys = parameters.keys();
* The following code and comment stolen from oreilley cos.jar.
* -mh. 2001.09.20
*
- * Returns the values of the named parameter as a String array, or null if
- * the parameter was not sent. The array has one entry for each parameter
- * field sent. If any field was sent without a value that entry is stored
- * in the array as a null. The values are guaranteed to be in their
+ * Returns the values of the named parameter as a String array, or null if
+ * the parameter was not sent. The array has one entry for each parameter
+ * field sent. If any field was sent without a value that entry is stored
+ * in the array as a null. The values are guaranteed to be in their
* normal, decoded form. A single value is returned as a one-element array.
*
* @param name the parameter name.
}
}
- private void _evaluateRequest() throws IOException{
+ private void _evaluateRequest() throws FileHandlerException,
+ FileHandlerUserException, IOException {
Part part;
- int i = 0;
+ int i = 1;
while ((part = mp.readNextPart()) != null) {
String name = part.getName();
if (part.isParam()) {
FilePart filePart = (FilePart) part;
String fn = filePart.getFileName();
if (filePart.getFileName() != null) {
- ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
- filePart.writeTo(byteStream);
- requestList.add(i,new MpRequest(byteStream.toByteArray(),filePart.getFileName(),filePart.getContentType()));
+ if (_fHandler != null)
+ _fHandler.setFile(filePart, i, getParameters());
i++;
}
}