remm        01/01/30 11:40:23

  Modified:    catalina/src/share/org/apache/catalina/util RequestUtil.java
  Log:
  - Add additional URLDecode methods, which allow to specify the character
    encoding to use.
  
  Revision  Changes    Path
  1.13      +75 -22    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/RequestUtil.java
  
  Index: RequestUtil.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/RequestUtil.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- RequestUtil.java  2001/01/30 04:14:49     1.12
  +++ RequestUtil.java  2001/01/30 19:40:19     1.13
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/RequestUtil.java,v
 1.12 2001/01/30 04:14:49 remm Exp $
  - * $Revision: 1.12 $
  - * $Date: 2001/01/30 04:14:49 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/RequestUtil.java,v
 1.13 2001/01/30 19:40:19 remm Exp $
  + * $Revision: 1.13 $
  + * $Date: 2001/01/30 19:40:19 $
    *
    * ====================================================================
    *
  @@ -78,7 +78,7 @@
    *
    * @author Craig R. McClanahan
    * @author Tim Tye
  - * @version $Revision: 1.12 $ $Date: 2001/01/30 04:14:49 $
  + * @version $Revision: 1.13 $ $Date: 2001/01/30 19:40:19 $
    */
   
   public final class RequestUtil {
  @@ -256,26 +256,79 @@
        */
       public static String URLDecode(String str) {
           
  -     if (str != null) {
  -            int len = str.length();
  -            byte[] bytes = new byte[len];
  -            str.getBytes(0, len, bytes, 0);
  -            int ix = 0;
  -            int ox = 0;
  -            
  -            while (ix < len) {
  -                byte b = bytes[ix++];     // Get byte to test
  -                if (b == '+') {
  -                    b = (byte)' ';
  -                } else if (b == '%') {
  -                    b = (byte) ((convertHexDigit(bytes[ix++]) << 4)
  -                                + convertHexDigit(bytes[ix++]));
  -                } 
  -                bytes[ox++] = b;
  +        return URLDecode(str, null);
  +        
  +    }
  +
  +
  +    /**
  +     * Decode and return the specified URL-encoded String.
  +     * 
  +     * @param str The url-encoded string
  +     * @param enc The encoding to use; if null, the default encoding is used
  +     * @exception IllegalArgumentException if a '%' character is not followed
  +     * by a valid 2-digit hexadecimal number
  +     */
  +    public static String URLDecode(String str, String enc) {
  +        
  +        if (str == null)
  +            return (null);
  +        
  +        int len = str.length();
  +        byte[] bytes = new byte[len];
  +        str.getBytes(0, len, bytes, 0);
  +        
  +        return URLDecode(bytes, enc);
  +        
  +    }
  +
  +
  +    /**
  +     * Decode and return the specified URL-encoded byte array.
  +     * 
  +     * @param bytes The url-encoded byte array
  +     * @exception IllegalArgumentException if a '%' character is not followed
  +     * by a valid 2-digit hexadecimal number
  +     */
  +    public static String URLDecode(byte[] bytes) {
  +        return URLDecode(bytes, null);
  +    }
  +
  +
  +    /**
  +     * Decode and return the specified URL-encoded byte array.
  +     * 
  +     * @param bytes The url-encoded byte array
  +     * @param enc The encoding to use; if null, the default encoding is used
  +     * @exception IllegalArgumentException if a '%' character is not followed
  +     * by a valid 2-digit hexadecimal number
  +     */
  +    public static String URLDecode(byte[] bytes, String enc) {
  +        
  +        if (bytes == null)
  +            return (null);
  +        
  +        int len = bytes.length;
  +        int ix = 0;
  +        int ox = 0;
  +        while (ix < len) {
  +            byte b = bytes[ix++];     // Get byte to test
  +            if (b == '+') {
  +                b = (byte)' ';
  +            } else if (b == '%') {
  +                b = (byte) ((convertHexDigit(bytes[ix++]) << 4)
  +                            + convertHexDigit(bytes[ix++]));
  +            } 
  +            bytes[ox++] = b;
  +        }
  +        if (enc != null) {
  +            try {
  +                return new String(bytes, 0, ox, enc);
  +            } catch (Exception e) {
  +                e.printStackTrace();
               }
  -            return new String(bytes, 0, ox);
           }
  -        return null;
  +        return new String(bytes, 0, ox);
           
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to