Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@jakarta.apache.org Received: (qmail 10440 invoked by uid 500); 11 Apr 2001 13:54:50 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: tomcat-dev@jakarta.apache.org Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 10431 invoked from network); 11 Apr 2001 13:54:49 -0000 Message-ID: <004e01c0c28f$02f1d950$090512ac@efcon> From: "Jan Fnukal" To: Subject: Support for different Charsets Date: Wed, 11 Apr 2001 15:55:04 +0200 MIME-Version: 1.0 X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 X-MIMETrack: Itemize by SMTP Server on BRNO_01/EFCON(Release 5.0.3 (Intl)|21 March 2000) at 11.04.2001 15:55:05, Serialize by Router on BRNO_01/EFCON(Release 5.0.3 (Intl)|21 March 2000) at 11.04.2001 15:55:07, Serialize complete at 11.04.2001 15:55:07 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="iso-8859-2" X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N Hi all, org.apache.tomcat.core.RequestImpl.handleParameters() could look like this: private void handleParameters() { if(!didParameters) { String qString=getQueryString(); if(qString!=null) { didParameters=true; // RequestUtil.processFormData( qString, parameters ); parameters = javax.servlet.http.HttpUtils.parseQueryString(qString); } } why write same thing two times? This works fine. By the way there is path for javax.servlet.http.HttpUtils.parseQueryString(). It handle different encoding than ISO Latin-1, depending on java setting (or it could be hardcoded in). I thing like this is the best way beacouse you can set JVM locale differently for every mashine (ISO Latin 1 works enyway) and java cares abaut convetion beacouse the new String() /* * Parse a name in the query string. */ static public String parseName(String s, StringBuffer sb) { sb.setLength(0); byte[] ss1 = {33}; // inserted beacouse of locale patch for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); switch (c) { case '+': sb.append(' '); break; case '%': try { // old code (works for ISO Latin 1): // stringbuffer.append((char)Integer.parseInt(s.substring(i + 1, i + 3), 16)); // we have url format that is in ISO latin 1 as bytes // put this to array ss1[0] = (byte)Integer.parseInt("0"+s.substring(i + 1, i + 3).toLowerCase(), 16); i += 2; // let's java make defaut encoding on mashine (server) (in java properties) String encchar = "?"; // "?" for badly encoded characters // useful if hard set encoding - this need to catch UnsupportedEncodingException // or hardcoded (may be in tomcat propperties) // try { encchar = new String(ss1); // ,"Cp1250"); // } catch (Exception e) { // System.err.println("HttpUtils.parseName: UnsupportedEncodingException"); // } sb.append( encchar ); // end of patch } catch (NumberFormatException e) { // XXX // need to be more specific about illegal arg throw new IllegalArgumentException(); } catch (StringIndexOutOfBoundsException e) { String rest = s.substring(i); sb.append(rest); if (rest.length()==2) i++; } break; default: sb.append(c); break; } } return sb.toString(); } I have to learn how to add it to CVS so be patient with me. Any comments? Jan Fnukal e-mail: jfnukal@efcon.cz tel: +420-5-4142 5628 EfCon a.s. Jaselska 25 611 57 Brno Czech Republic www.efcon.cz