image bugfixx - mir now depends on jai imagio
[mir.git] / source / mir / util / HTTPRequestParser.java
index 55b2d00..60df288 100755 (executable)
-package mir.util;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-\r
-public class HTTPRequestParser {\r
-  private HttpServletRequest request;\r
-  private String encoding;\r
-\r
-  public HTTPRequestParser(HttpServletRequest aRequest) {\r
-    this(aRequest, aRequest.getCharacterEncoding());\r
-  }\r
-\r
-  public HTTPRequestParser(HttpServletRequest aRequest, String anEncoding) {\r
-    request = aRequest;\r
-    encoding = anEncoding;\r
-  }\r
-\r
-  public boolean hasParameter(String aName) {\r
-    return request.getParameter(aName)!=null;\r
-  }\r
-\r
-  public String getParameterWithDefault(String aName, String aDefault) {\r
-    if (hasParameter(aName))\r
-      return getParameter(aName);\r
-    else\r
-      return aDefault;\r
-  }\r
-\r
-  public String getParameter(String aName) {\r
-    try {\r
-      String result = request.getParameter(aName);\r
-\r
-      if (result != null && encoding!=null && !encoding.equals(request.getCharacterEncoding())) {\r
-        result = new String(result.getBytes(request.getCharacterEncoding()), encoding);\r
-      }\r
-\r
-      return result;\r
-    }\r
-    catch (Throwable t) {\r
-      throw new RuntimeException("HTTPRequestParser.getParameter: " + t.getMessage());\r
-    }\r
-  }\r
-\r
-  public int getIntegerWithDefault(String aName, int aDefault) {\r
-    int result = aDefault;\r
-    String value = getParameter(aName);\r
-\r
-    try {\r
-      result = Integer.parseInt(value);\r
-    }\r
-    catch (Throwable t) {\r
-    }\r
-    return result;\r
-  }\r
-}
\ No newline at end of file
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * 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  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.List;
+import java.util.Vector;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class HTTPRequestParser {
+  private HttpServletRequest request;
+  private String encoding;
+
+  public HTTPRequestParser(HttpServletRequest aRequest) {
+    this(aRequest, aRequest.getCharacterEncoding());
+  }
+
+  public HTTPRequestParser(HttpServletRequest aRequest, String anEncoding) {
+    request = aRequest;
+    encoding = anEncoding;
+  }
+
+  public boolean hasParameter(String aName) {
+    return request.getParameter(aName)!=null;
+  }
+
+  public String getParameterWithDefault(String aName, String aDefault) {
+    if (hasParameter(aName))
+      return getParameter(aName);
+    else
+      return aDefault;
+  }
+
+  public String getParameter(String aName) {
+    try {
+      String result = request.getParameter(aName);
+//      String requestEncoding = request.getCharacterEncoding();
+//      if (requestEncoding==null)
+//        requestEncoding = "ISO-8859-1";
+
+//      if (result != null && encoding!=null && !encoding.equals(requestEncoding)) {
+//        result = new String(result.getBytes(requestEncoding), encoding);
+//      }
+
+      return result;
+    }
+    catch (Throwable t) {
+      throw new RuntimeException("HTTPRequestParser.getParameter: " + t.getMessage());
+    }
+  }
+
+  public List getParameterList(String aName) {
+    try {
+      List result = new Vector();
+      String items[] = request.getParameterValues(aName);
+
+      if (items!=null) {
+        for (int i=0; i<items.length; i++) {
+          result.add(items[i]);
+        }
+      }
+
+      return result;
+    }
+    catch (Throwable t) {
+      throw new RuntimeException("HTTPRequestParser.getParameterList: " + t.getMessage());
+    }
+  }
+
+  public int getIntegerWithDefault(String aName, int aDefault) {
+    int result = aDefault;
+    String value = getParameter(aName);
+
+    try {
+      result = Integer.parseInt(value);
+    }
+    catch (Throwable t) {
+    }
+    return result;
+  }
+}