5 import javax.servlet.*;
6 import javax.servlet.http.*;
7 import com.oreilly.servlet.multipart.*;
8 import com.oreilly.servlet.*;
13 * Copyright: Copyright (c) 2001
19 public class WebdbMultipartRequest
21 HttpServletRequest req=null;
22 Hashtable parameters = new Hashtable();
23 MultipartParser mp=null;
24 public static ArrayList requestList;
26 public WebdbMultipartRequest(HttpServletRequest theReq) throws IOException
29 int maxSize = Integer.parseInt(MirConfig.getProp("MaxMediaUploadSize"));
30 mp = new MultipartParser(req, 1024*maxSize);
31 requestList = new ArrayList();
37 * The following comment and some code was adapted from the Oreilley cos.jar
38 * package. -mh 2001.09.20
40 * Returns all the parameters as a HashMap of Strings, any parameter
41 * that sent without a value will be null. A value
42 * is guaranteed to be in its normal, decoded form. If A parameter
43 * has multiple values, only the last one is returned (for backward
44 * compatibility). For parameters with multiple values, it's possible
45 * the last "value" may be null.
47 * @return A HashMap of String representations of the parameter values.
49 public HashMap getParameters(){
50 HashMap pHash = new HashMap();
51 String value = new String();
53 Enumeration Keys = parameters.keys();
54 while(Keys.hasMoreElements()) {
55 String KeyNm = (String)Keys.nextElement();
56 Vector values = (Vector)parameters.get(KeyNm);
57 if (values == null || values.size() == 0) {
60 value = (String)values.elementAt(values.size() - 1);
62 pHash.put(KeyNm, value);
68 * The following code and comment stolen from oreilley cos.jar.
71 * Returns the values of the named parameter as a String array, or null if
72 * the parameter was not sent. The array has one entry for each parameter
73 * field sent. If any field was sent without a value that entry is stored
74 * in the array as a null. The values are guaranteed to be in their
75 * normal, decoded form. A single value is returned as a one-element array.
77 * @param name the parameter name.
78 * @return the parameter values.
80 public String[] getParameterValues(String name) {
82 Vector values = (Vector)parameters.get(name);
83 if (values == null || values.size() == 0) {
86 String[] valuesArray = new String[values.size()];
87 values.copyInto(valuesArray);
95 private void _evaluateRequest() throws IOException{
99 while ((part = mp.readNextPart()) != null) {
100 String name = part.getName();
101 if (part.isParam()) {
102 // It's a parameter part, add it to the vector of values
103 ParamPart paramPart = (ParamPart) part;
104 String value = paramPart.getStringValue();
105 Vector existingValues = (Vector)parameters.get(name);
106 if (existingValues == null) {
107 existingValues = new Vector();
108 parameters.put(name, existingValues);
110 existingValues.addElement(value);
112 else if (part.isFile()) {
113 // nur das erste uploadfile beruecksichtigen
114 FilePart filePart = (FilePart) part;
115 String fn = filePart.getFileName();
116 if (filePart.getFileName() != null) {
117 ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
118 filePart.writeTo(byteStream);
119 requestList.add(i,new MpRequest(byteStream.toByteArray(),filePart.getFileName(),filePart.getContentType()));