X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fmisc%2FWebdbMultipartRequest.java;h=5b1871fa3b9070ad841b944d2cc17777df2a8afc;hb=07c30d26fa01513214528c35f3004952f3d6a890;hp=8e61acda08b880692e7b7effe21d1d3a0ac9e176;hpb=07406c649982d8496617dfbf92097a27705303c2;p=mir.git diff --git a/source/mir/misc/WebdbMultipartRequest.java b/source/mir/misc/WebdbMultipartRequest.java index 8e61acda..5b1871fa 100755 --- a/source/mir/misc/WebdbMultipartRequest.java +++ b/source/mir/misc/WebdbMultipartRequest.java @@ -19,23 +19,78 @@ import com.oreilly.servlet.*; public class WebdbMultipartRequest { HttpServletRequest req=null; - HashMap parameters = new HashMap(); + Hashtable parameters = new Hashtable(); MultipartParser mp=null; public static ArrayList requestList; public WebdbMultipartRequest(HttpServletRequest theReq) throws IOException { req=theReq; - mp = new MultipartParser(req, 1024*8192); // maximum eight megabyte + int maxSize = Integer.parseInt(MirConfig.getProp("MaxMediaUploadSize")); + mp = new MultipartParser(req, 1024*maxSize); requestList = new ArrayList(); _evaluateRequest(); } + /** + * 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 + * 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. + */ public HashMap getParameters(){ - return parameters; + HashMap pHash = new HashMap(); + String value = new String(); + + Enumeration Keys = parameters.keys(); + while(Keys.hasMoreElements()) { + String KeyNm = (String)Keys.nextElement(); + Vector values = (Vector)parameters.get(KeyNm); + if (values == null || values.size() == 0) { + value = null; + } else { + value = (String)values.elementAt(values.size() - 1); + } //endif + pHash.put(KeyNm, value); + } // end while + return pHash; } + /** + * 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 + * normal, decoded form. A single value is returned as a one-element array. + * + * @param name the parameter name. + * @return the parameter values. + */ + public String[] getParameterValues(String name) { + try { + Vector values = (Vector)parameters.get(name); + if (values == null || values.size() == 0) { + return null; + } + String[] valuesArray = new String[values.size()]; + values.copyInto(valuesArray); + return valuesArray; + } + catch (Exception e) { + return null; + } + } private void _evaluateRequest() throws IOException{ @@ -47,7 +102,12 @@ public class WebdbMultipartRequest // It's a parameter part, add it to the vector of values ParamPart paramPart = (ParamPart) part; String value = paramPart.getStringValue(); - parameters.put(name,value); + Vector existingValues = (Vector)parameters.get(name); + if (existingValues == null) { + existingValues = new Vector(); + parameters.put(name, existingValues); + } + existingValues.addElement(value); } else if (part.isFile()) { // nur das erste uploadfile beruecksichtigen @@ -62,5 +122,5 @@ public class WebdbMultipartRequest } } // while */ } - + }