tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jan Fnukal" <jfnu...@efcon.cz>
Subject Support for different Charsets
Date Wed, 11 Apr 2001 13:55:04 GMT
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



Mime
View raw message