froehlich 02/02/13 01:35:11 Modified: src/java/org/apache/cocoon/environment/http HttpRequest.java HttpEnvironment.java Log: applied patch from MIYABE Tatsuhiko [[EMAIL PROTECTED]]. Form encoding enhancement! Revision Changes Path 1.3 +45 -3 xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpRequest.java Index: HttpRequest.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpRequest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HttpRequest.java 4 Feb 2002 09:45:07 -0000 1.2 +++ HttpRequest.java 13 Feb 2002 09:35:11 -0000 1.3 @@ -70,7 +70,7 @@ * to provide request information for HTTP servlets. * * @author <a href="mailto:giacomo@apache,org">Giacomo Pati</a> - * @version CVS $Id: HttpRequest.java,v 1.2 2002/02/04 09:45:07 cziegeler Exp $ + * @version CVS $Id: HttpRequest.java,v 1.3 2002/02/13 09:35:11 froehlich Exp $ */ public class HttpRequest implements Request { @@ -81,6 +81,12 @@ /** The HttpEnvironment object */ private HttpEnvironment env = null; + /** The character encoding of parameters */ + private String form_encoding = null; + + /** The default form encoding of the servlet container */ + private String container_encoding = null; + /** * Creates a HttpServletRequest based on a real HttpServletRequest object */ @@ -245,6 +251,18 @@ return this.req.getCharacterEncoding(); } + public void setCharacterEncoding(String form_encoding) + throws java.io.UnsupportedEncodingException { + this.form_encoding = form_encoding; + } + + /** + * Sets the default encoding of the servlet container. + */ + public void setContainerEncoding(String container_encoding) { + this.container_encoding = container_encoding; + } + public int getContentLength() { return this.req.getContentLength(); } @@ -258,7 +276,23 @@ } public String getParameter(String name) { - return this.req.getParameter(name); + String value = this.req.getParameter(name); + if (this.form_encoding == null) { + return value; + } + return decode(value); + } + + private String decode(String str) { + try { + if (this.container_encoding == null) + this.container_encoding = "ISO-8859-1"; + byte[] bytes = str.getBytes(this.container_encoding); + return new String(bytes, form_encoding); + } catch (java.io.UnsupportedEncodingException uee) { + throw new RuntimeException("Unsupported Encoding Exception: " + + uee.getMessage()); + } } public Enumeration getParameterNames() { @@ -266,7 +300,15 @@ } public String[] getParameterValues(String name) { - return this.req.getParameterValues(name); + String[] values = this.req.getParameterValues(name); + if (this.form_encoding == null) { + return values; + } + String[] decoded_values = new String[values.length]; + for (int i = 0; i < values.length; ++i) { + decoded_values[i] = decode(values[i]); + } + return decoded_values; } public String getProtocol() { 1.6 +7 -3 xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java Index: HttpEnvironment.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- HttpEnvironment.java 7 Feb 2002 08:59:17 -0000 1.5 +++ HttpEnvironment.java 13 Feb 2002 09:35:11 -0000 1.6 @@ -71,7 +71,7 @@ /** * @author ? - * @version CVS $Id: HttpEnvironment.java,v 1.5 2002/02/07 08:59:17 cziegeler Exp $ + * @version CVS $Id: HttpEnvironment.java,v 1.6 2002/02/13 09:35:11 froehlich Exp $ */ public class HttpEnvironment extends AbstractEnvironment implements Redirector { @@ -103,11 +103,15 @@ HttpServletRequest req, HttpServletResponse res, ServletContext servletContext, - HttpContext context) - throws MalformedURLException, IOException { + HttpContext context, + String containerEncoding, + String defaultFormEncoding) + throws MalformedURLException, IOException { super(uri, req.getParameter(Constants.VIEW_PARAM), rootURL, req.getParameter(Constants.ACTION_PARAM)); this.request = new HttpRequest (req, this); + this.request.setCharacterEncoding(defaultFormEncoding); + this.request.setContainerEncoding(containerEncoding); this.response = new HttpResponse (res); this.webcontext = context; this.outputStream = response.getOutputStream();
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]