- experimental opensessions
[mir.git] / source / mir / util / HTTPRequestParser.java
index 20bfd91..043dc7c 100755 (executable)
@@ -1,58 +1,89 @@
-package mir.util;
-
-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 int getIntegerWithDefault(String aName, int aDefault) {
-    int result = aDefault;
-    String value = getParameter(aName);
-
-    try {
-      result = Integer.parseInt(value);
-    }
-    catch (Throwable t) {
-    }
-    return result;
-  }
-}
\ No newline at end of file
+/*\r
+ * Copyright (C) 2001, 2002  The Mir-coders group\r
+ *\r
+ * This file is part of Mir.\r
+ *\r
+ * Mir is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * Mir is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Mir; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ *\r
+ * In addition, as a special exception, The Mir-coders gives permission to link\r
+ * the code of this program with the com.oreilly.servlet library, any library\r
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced\r
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of\r
+ * the above that use the same license as the above), and distribute linked\r
+ * combinations including the two.  You must obey the GNU General Public\r
+ * License in all respects for all of the code used other than the above\r
+ * mentioned libraries.  If you modify this file, you may extend this exception\r
+ * to your version of the file, but you are not obligated to do so.  If you do\r
+ * not wish to do so, delete this exception statement from your version.\r
+ */\r
+\r
+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
+      String requestEncoding = request.getCharacterEncoding();\r
+      if (requestEncoding==null)\r
+        requestEncoding = "ISO-8859-1";\r
+\r
+      if (result != null && encoding!=null && !encoding.equals(requestEncoding)) {\r
+        result = new String(result.getBytes(requestEncoding), 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
+}\r