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 mp = new MultipartParser(req, 1024*8192); // maximum eight megabyte
30 requestList = new ArrayList();
36 * The following comment and some code was adapted from the Oreilley cos.jar
37 * package. -mh 2001.09.20
39 * Returns all the parameters as a HashMap of Strings, any parameter
40 * that sent without a value will be null. A value
41 * is guaranteed to be in its normal, decoded form. If A parameter
42 * has multiple values, only the last one is returned (for backward
43 * compatibility). For parameters with multiple values, it's possible
44 * the last "value" may be null.
46 * @return A HashMap of String representations of the parameter values.
48 public HashMap getParameters(){
49 HashMap pHash = new HashMap();
50 String value = new String();
52 Enumeration Keys = parameters.keys();
53 while(Keys.hasMoreElements()) {
54 String KeyNm = (String)Keys.nextElement();
55 Vector values = (Vector)parameters.get(KeyNm);
56 if (values == null || values.size() == 0) {
59 value = (String)values.elementAt(values.size() - 1);
61 pHash.put(KeyNm, value);
67 * The following code and comment stolen from oreilley cos.jar.
70 * Returns the values of the named parameter as a String array, or null if
71 * the parameter was not sent. The array has one entry for each parameter
72 * field sent. If any field was sent without a value that entry is stored
73 * in the array as a null. The values are guaranteed to be in their
74 * normal, decoded form. A single value is returned as a one-element array.
76 * @param name the parameter name.
77 * @return the parameter values.
79 public String[] getParameterValues(String name) {
81 Vector values = (Vector)parameters.get(name);
82 if (values == null || values.size() == 0) {
85 String[] valuesArray = new String[values.size()];
86 values.copyInto(valuesArray);
94 private void _evaluateRequest() throws IOException{
98 while ((part = mp.readNextPart()) != null) {
99 String name = part.getName();
100 if (part.isParam()) {
101 // It's a parameter part, add it to the vector of values
102 ParamPart paramPart = (ParamPart) part;
103 String value = paramPart.getStringValue();
104 Vector existingValues = (Vector)parameters.get(name);
105 if (existingValues == null) {
106 existingValues = new Vector();
107 parameters.put(name, existingValues);
109 existingValues.addElement(value);
111 else if (part.isFile()) {
112 // nur das erste uploadfile beruecksichtigen
113 FilePart filePart = (FilePart) part;
114 String fn = filePart.getFileName();
115 if (filePart.getFileName() != null) {
116 ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
117 filePart.writeTo(byteStream);
118 requestList.add(i,new MpRequest(byteStream.toByteArray(),filePart.getFileName(),filePart.getContentType()));