You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by je...@apache.org on 2003/02/13 06:08:19 UTC

cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient URI.java HttpURL.java HttpsURL.java

jericho     2003/02/12 21:08:19

  Modified:    httpclient/src/java/org/apache/commons/httpclient/util
                        URIUtil.java
               httpclient/src/java/org/apache/commons/httpclient URI.java
                        HttpURL.java HttpsURL.java
  Log:
  Abstract:
   - Support instance charset to do escape encoding.
   - Distinguish with the concept of default charset.
  
  Targets:
   - URI, HttpURL, HttpsURL and URIUtil
  
  Details:
   - Add two contructors with given charset to be used in doing escape encoding
   - Rename the inner class, CharsetChanged to DefaultChasetChanged
     It's only global and default charset changed not for any instances.
   - Remove protected methods used for previously internal encoding and decoding
     It was internal use and no need to be deprecated.
   - Add protocolCharset variable for instances
   - Rename static methods, getXxxxCharset to getDefaultXxxxCharset and
     setXxxxCharset to setDefaultXxxxCharset
   - Add getProtocolCharset for instance use
   - Add getDefaultDocumentCharset, getDefaultDocumentCharsetByLocale,
     getDefaultDocumentCharsetByPlatform for instance use
   - Add and fix some javadoc messages
  
  Revision  Changes    Path
  1.18      +30 -30    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java
  
  Index: URIUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- URIUtil.java	31 Jan 2003 00:33:37 -0000	1.17
  +++ URIUtil.java	13 Feb 2003 05:08:18 -0000	1.18
  @@ -196,16 +196,16 @@
       /**
        * Get the all escaped and encoded string with the default protocl charset.
        * It's the same function to use <code>encode(String unescaped, Bitset
  -     * empty, URI.getProtocolCharset())</code>.
  +     * empty, URI.getDefaultProtocolCharset())</code>.
        *
        * @param unescaped an unescaped string
        * @return the escaped string
        * @exception URIException
  -     * @see URI#getProtocolCharset
  +     * @see URI#getDefaultProtocolCharset
        * @see #encode
        */
       public static String encodeAll(String unescaped) throws URIException {
  -        return encodeAll(unescaped, URI.getProtocolCharset());
  +        return encodeAll(unescaped, URI.getDefaultProtocolCharset());
       }
    
   
  @@ -236,13 +236,13 @@
        * @param unescaped an unescaped string
        * @return the escaped string
        * @exception URIException
  -     * @see URI#getProtocolCharset
  +     * @see URI#getDefaultProtocolCharset
        * @see #encode
        */
       public static String encodeWithinAuthority(String unescaped)
           throws URIException {
   
  -        return encodeWithinAuthority(unescaped, URI.getProtocolCharset());
  +        return encodeWithinAuthority(unescaped, URI.getDefaultProtocolCharset());
       }
   
   
  @@ -272,11 +272,11 @@
        * @param unescaped an unescaped string
        * @return the escaped string
        * @exception URIException
  -     * @see URI#getProtocolCharset
  +     * @see URI#getDefaultProtocolCharset
        * @see #encode
        */
       public static String encodePathQuery(String unescaped) throws URIException {
  -        return encodePathQuery(unescaped, URI.getProtocolCharset());
  +        return encodePathQuery(unescaped, URI.getDefaultProtocolCharset());
       }
   
   
  @@ -313,13 +313,13 @@
        * @param unescaped an unescaped string
        * @return the escaped string
        * @exception URIException
  -     * @see URI#getProtocolCharset
  +     * @see URI#getDefaultProtocolCharset
        * @see #encode
        */
       public static String encodeWithinPath(String unescaped)
           throws URIException {
   
  -        return encodeWithinPath(unescaped, URI.getProtocolCharset());
  +        return encodeWithinPath(unescaped, URI.getDefaultProtocolCharset());
       }
   
   
  @@ -350,11 +350,11 @@
        * @param unescaped an unescaped string
        * @return the escaped string
        * @exception URIException
  -     * @see URI#getProtocolCharset
  +     * @see URI#getDefaultProtocolCharset
        * @see #encode
        */
       public static String encodePath(String unescaped) throws URIException {
  -        return encodePath(unescaped, URI.getProtocolCharset());
  +        return encodePath(unescaped, URI.getDefaultProtocolCharset());
       }
   
   
  @@ -385,13 +385,13 @@
        * @param unescaped an unescaped string
        * @return the escaped string
        * @exception URIException
  -     * @see URI#getProtocolCharset
  +     * @see URI#getDefaultProtocolCharset
        * @see #encode
        */
       public static String encodeWithinQuery(String unescaped)
           throws URIException {
   
  -        return encodeWithinQuery(unescaped, URI.getProtocolCharset());
  +        return encodeWithinQuery(unescaped, URI.getDefaultProtocolCharset());
       }
   
   
  @@ -425,11 +425,11 @@
        * @param unescaped an unescaped string
        * @return the escaped string
        * @exception URIException
  -     * @see URI#getProtocolCharset
  +     * @see URI#getDefaultProtocolCharset
        * @see #encode
        */
       public static String encodeQuery(String unescaped) throws URIException {
  -        return encodeQuery(unescaped, URI.getProtocolCharset());
  +        return encodeQuery(unescaped, URI.getDefaultProtocolCharset());
       }
   
   
  @@ -461,13 +461,13 @@
        * @param allowed allowed characters not to be escaped
        * @return the escaped string
        * @exception URIException
  -     * @see URI#getProtocolCharset
  +     * @see URI#getDefaultProtocolCharset
        * @see Coder#encode
        */
       public static String encode(String unescaped, BitSet allowed)
           throws URIException {
   
  -        return encode(unescaped, allowed, URI.getProtocolCharset());
  +        return encode(unescaped, allowed, URI.getDefaultProtocolCharset());
       }
   
   
  @@ -496,11 +496,11 @@
        * @param escaped a string
        * @return the unescaped string
        * @exception URIException
  -     * @see URI#getProtocolCharset
  +     * @see URI#getDefaultProtocolCharset
        * @see Coder#decode
       */
       public static String decode(String escaped) throws URIException {
  -        return Coder.decode(escaped.toCharArray(), URI.getProtocolCharset());
  +        return Coder.decode(escaped.toCharArray(), URI.getDefaultProtocolCharset());
       }
   
   
  @@ -528,10 +528,10 @@
        * @param target a target string
        * @return the protocol character encoded string
        * @exception URIException
  -     * @see URI#getProtocolCharset
  +     * @see URI#getDefaultProtocolCharset
        */
       public static String toProtocolCharset(String target) throws URIException {
  -        return toUsingCharset(target, URI.getDocumentCharset(), URI.getProtocolCharset());
  +        return toUsingCharset(target, URI.getDefaultDocumentCharset(), URI.getDefaultProtocolCharset());
       }
   
   
  @@ -547,7 +547,7 @@
       public static String toProtocolCharset(String target, String charset)
           throws URIException {
   
  -        return toUsingCharset(target, URI.getDocumentCharset(), charset);
  +        return toUsingCharset(target, URI.getDefaultDocumentCharset(), charset);
       }
   
   
  @@ -558,11 +558,11 @@
        * @param target a target string
        * @return the document character encoded string
        * @exception URIException
  -     * @see URI#getDocumentCharset
  +     * @see URI#getDefaultDocumentCharset
        */
       public static String toDocumentCharset(String target) throws URIException {
  -        return toUsingCharset(target, URI.getProtocolCharset(),
  -                URI.getDocumentCharset());
  +        return toUsingCharset(target, URI.getDefaultProtocolCharset(),
  +                URI.getDefaultDocumentCharset());
       }
   
   
  @@ -578,7 +578,7 @@
       public static String toDocumentCharset(String target, String charset)
           throws URIException {
   
  -        return toUsingCharset(target, URI.getProtocolCharset(), charset);
  +        return toUsingCharset(target, URI.getDefaultProtocolCharset(), charset);
       }
   
   
  
  
  
  1.32      +264 -159  jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URI.java
  
  Index: URI.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URI.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- URI.java	31 Jan 2003 00:33:36 -0000	1.31
  +++ URI.java	13 Feb 2003 05:08:18 -0000	1.32
  @@ -152,10 +152,29 @@
   
   
       // ----------------------------------------------------------- Constructors
  -    /** Create an instance */
  +
  +    /** Create an instance as an internal use */
       protected URI() {
       }
   
  +
  +    /**
  +     * Construct a URI as an escaped form of a character array with the given
  +     * charset.
  +     *
  +     * @param escaped the URI character sequence
  +     * @param charset the charset string to do escape encoding
  +     * @throws URIException If the URI cannot be created.
  +     * @throws NullPointerException if <code>escaped</code> is <code>null</code>
  +     * @see #getProtocolCharset
  +     */
  +    public URI(char[] escaped, String charset) 
  +        throws URIException, NullPointerException {
  +        protocolCharset = charset;
  +        parseUriReference(new String(escaped), true);
  +    }
  +
  +
       /**
        * Construct a URI as an escaped form of a character array.
        * An URI can be placed within double-quotes or angle brackets like 
  @@ -164,6 +183,7 @@
        * @param escaped the URI character sequence
        * @throws URIException If the URI cannot be created.
        * @throws NullPointerException if <code>escaped</code> is <code>null</code>
  +     * @see #getDefaultProtocolCharset
        */
       public URI(char[] escaped) 
           throws URIException, NullPointerException {
  @@ -172,6 +192,21 @@
   
   
       /**
  +     * Construct a URI from the given string with the given charset.
  +     *
  +     * @param original the string to be represented to URI character sequence
  +     * It is one of absoluteURI and relativeURI.
  +     * @param charset the charset string to do escape encoding
  +     * @throws URIException If the URI cannot be created.
  +     * @see #getProtocolCharset
  +     */
  +    public URI(String original, String charset) throws URIException {
  +        protocolCharset = charset;
  +        parseUriReference(original, false);
  +    }
  +
  +
  +    /**
        * Construct a URI from the given string.
        * <p><blockquote><pre>
        *   URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
  @@ -182,17 +217,20 @@
        * @param original the string to be represented to URI character sequence
        * It is one of absoluteURI and relativeURI.
        * @throws URIException If the URI cannot be created.
  +     * @see #getDefaultProtocolCharset
        */
       public URI(String original) throws URIException {
           parseUriReference(original, false);
       }
   
  +
       /**
        * Construct a URI from a URL.
        *
        * @param url a valid URL.
        * @throws URIException If the URI cannot be created.
        * @since 2.0 
  +     * @deprecated currently somewhat wrong and diffrent with java.net.URL usage
        */
       public URI(URL url) throws URIException {
           this(url.toString());
  @@ -212,7 +250,8 @@
        * @param scheme the scheme string
        * @param schemeSpecificPart scheme_specific_part
        * @param fragment the fragment string
  -     * @exception URIException If the URI cannot be created.
  +     * @throws URIException If the URI cannot be created.
  +     * @see #getDefaultProtocolCharset
        */
       public URI(String scheme, String schemeSpecificPart, String fragment)
           throws URIException {
  @@ -227,7 +266,9 @@
           } else {
               throw new URIException(URIException.PARSING, "incorrect scheme");
           }
  -        _opaque = encode(schemeSpecificPart, allowed_opaque_part);
  +        _opaque = encode(schemeSpecificPart, allowed_opaque_part,
  +                (protocolCharset != null) ? protocolCharset :
  +                defaultProtocolCharset);
           // Set flag
           _is_opaque_part = true;
           _fragment = fragment.toCharArray(); 
  @@ -253,7 +294,8 @@
        * @param path the path string
        * @param query the query string
        * @param fragment the fragment string
  -     * @exception URIException If the new URI cannot be created.
  +     * @throws URIException If the new URI cannot be created.
  +     * @see #getDefaultProtocolCharset
        */
       public URI(String scheme, String authority, String path, String query,
                  String fragment) throws URIException {
  @@ -295,7 +337,8 @@
        * @param userinfo the userinfo string
        * @param host the host string
        * @param port the port number
  -     * @exception URIException If the new URI cannot be created.
  +     * @throws URIException If the new URI cannot be created.
  +     * @see #getDefaultProtocolCharset
        */
       public URI(String scheme, String userinfo, String host, int port)
           throws URIException {
  @@ -312,7 +355,8 @@
        * @param host the host string
        * @param port the port number
        * @param path the path string
  -     * @exception URIException If the new URI cannot be created.
  +     * @throws URIException If the new URI cannot be created.
  +     * @see #getDefaultProtocolCharset
        */
       public URI(String scheme, String userinfo, String host, int port,
               String path) throws URIException {
  @@ -330,7 +374,8 @@
        * @param port the port number
        * @param path the path string
        * @param query the query string
  -     * @exception URIException If the new URI cannot be created.
  +     * @throws URIException If the new URI cannot be created.
  +     * @see #getDefaultProtocolCharset
        */
       public URI(String scheme, String userinfo, String host, int port,
               String path, String query) throws URIException {
  @@ -349,7 +394,8 @@
        * @param path the path string
        * @param query the query string
        * @param fragment the fragment string
  -     * @exception URIException If the new URI cannot be created.
  +     * @throws URIException If the new URI cannot be created.
  +     * @see #getDefaultProtocolCharset
        */
       public URI(String scheme, String userinfo, String host, int port,
               String path, String query, String fragment) throws URIException {
  @@ -367,7 +413,8 @@
        * @param host the host string
        * @param path the path string
        * @param fragment the fragment string
  -     * @exception URIException If the new URI cannot be created.
  +     * @throws URIException If the new URI cannot be created.
  +     * @see #getDefaultProtocolCharset
        */
       public URI(String scheme, String host, String path, String fragment)
           throws URIException {
  @@ -381,7 +428,7 @@
        *
        * @param base the base URI
        * @param relative the relative URI string
  -     * @exception URIException If the new URI cannot be created.
  +     * @throws URIException If the new URI cannot be created.
        */
       public URI(URI base, String relative) throws URIException {
           this(base, new URI(relative));
  @@ -436,7 +483,7 @@
        *
        * @param base the base URI
        * @param relative the relative URI
  -     * @exception URIException If the new URI cannot be created.
  +     * @throws URIException If the new URI cannot be created.
        */
       public URI(URI base, URI relative) throws URIException {
   
  @@ -542,28 +589,45 @@
   
   
       /**
  +     * The charset of the protocol used by this URI instance.
  +     */
  +    protected String protocolCharset = null;
  +
  +
  +    /**
        * The default charset of the protocol.  RFC 2277, 2396
        */
  -    protected static String _protocolCharset = "UTF-8";
  +    protected static String defaultProtocolCharset = "UTF-8";
   
   
       /**
        * The default charset of the document.  RFC 2277, 2396
        * The platform's charset is used for the document by default.
        */
  -    protected static String _documentCharset = null;
  -    // Static initializer for _documentCharset
  +    protected static String defaultDocumentCharset = null;
  +    protected static String defaultDocumentCharsetByLocale = null;
  +    protected static String defaultDocumentCharsetByPlatform = null;
  +    // Static initializer for defaultDocumentCharset
       static {
           Locale locale = Locale.getDefault();
  +        // in order to support backward compatiblity
           if (locale != null) {
  -            // in order to support backward compatiblity
  -            _documentCharset = LocaleToCharsetMap.getCharset(locale);
  -        } else {
  -            _documentCharset = (String) AccessController.doPrivileged(
  -                    new GetPropertyAction("file.encoding"));
  +            defaultDocumentCharsetByLocale =
  +                LocaleToCharsetMap.getCharset(locale);
  +            // set the default document charset
  +            defaultDocumentCharset = defaultDocumentCharsetByLocale;
  +        }
  +        // in order to support platform encoding
  +        defaultDocumentCharsetByPlatform =
  +            (String) AccessController.doPrivileged(
  +                new GetPropertyAction("file.encoding"));
  +        if (defaultDocumentCharset == null) {
  +            // set the default document charset
  +            defaultDocumentCharset = defaultDocumentCharsetByPlatform;
           }
       }
   
  +
       /**
        * The scheme.
        */
  @@ -1551,21 +1615,6 @@
       // ------------------------------------------ Character and escape encoding
       
       /**
  -     * Encode with the default protocol charset.
  -     *
  -     * @param original the original character sequence
  -     * @param allowed those characters that are allowed within a component
  -     * @return URI character sequence
  -     * @exception URIException null component or unsupported character encoding
  -     */
  -    protected static char[] encode(String original, BitSet allowed)
  -        throws URIException {
  -
  -        return encode(original, allowed, _protocolCharset);
  -    }
  -
  -
  -    /**
        * Encodes URI string.
        *
        * This is a two mapping, one from original characters to octets, and
  @@ -1598,7 +1647,7 @@
        * @param allowed those characters that are allowed within a component
        * @param charset the protocol charset
        * @return URI character sequence
  -     * @exception URIException null component or unsupported character encoding
  +     * @throws URIException null component or unsupported character encoding
        */
       protected static char[] encode(String original, BitSet allowed,
               String charset) throws URIException {
  @@ -1638,19 +1687,6 @@
   
   
       /**
  -     * Decode with the default protocol charset.
  -     *
  -     * @param component the URI character sequence
  -     * @return original character sequence
  -     * @exception URIException incomplete trailing escape pattern or unsupported
  -     * character encoding
  -     */
  -    protected static String decode(char[] component) throws URIException {
  -        return decode(component, _protocolCharset);
  -    }
  -
  -
  -    /**
        * Decodes URI encoded string.
        *
        * This is a two mapping, one from URI characters to octets, and
  @@ -1677,7 +1713,7 @@
        * @param component the URI character sequence
        * @param charset the protocol charset
        * @return original character sequence
  -     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * @throws URIException incomplete trailing escape pattern or unsupported
        * character encoding
        */
       protected static String decode(char[] component, String charset)
  @@ -1820,7 +1856,7 @@
        *
        * @param original the original character sequence
        * @param escaped <code>true</code> if <code>original</code> is escaped
  -     * @exception URIException If an error occurs.
  +     * @throws URIException If an error occurs.
        */
       protected void parseUriReference(String original, boolean escaped)
           throws URIException {
  @@ -1948,14 +1984,14 @@
               }
               if (!_is_abs_path) {
                   if (!escaped && prevalidate(tmp.substring(from, next),
  -                            disallowed_rel_path) || escaped 
  -                                && validate(tmp.substring(from, next).toCharArray(),
  +                            disallowed_rel_path) || escaped &&
  +                        validate(tmp.substring(from, next).toCharArray(),
                               rel_path)) {
                       // Set flag
                       _is_rel_path = true;
                   } else if (!escaped && prevalidate(tmp.substring(from, next),
  -                            disallowed_opaque_part) || escaped 
  -                                && validate(tmp.substring(from, next).toCharArray(),
  +                            disallowed_opaque_part) || escaped &&
  +                        validate(tmp.substring(from, next).toCharArray(),
                               opaque_part)) {
                       // Set flag
                       _is_opaque_part = true;
  @@ -1972,6 +2008,9 @@
               at = next;
           }
   
  +        // set the charset to do escape encoding
  +        String charset = (protocolCharset != null) ? protocolCharset :
  +            defaultProtocolCharset;
           /*
            * Parse the query component.
            * <p><blockquote><pre>
  @@ -1986,7 +2025,7 @@
                   next = tmp.length();
               }
               _query = (escaped) ? tmp.substring(at + 1, next).toCharArray() 
  -                : encode(tmp.substring(at + 1, next), allowed_query);
  +                : encode(tmp.substring(at + 1, next), allowed_query, charset);
               at = next;
           }
   
  @@ -2003,7 +2042,7 @@
                   _fragment = "".toCharArray();
               } else {
                   _fragment = (escaped) ? tmp.substring(at + 1).toCharArray() 
  -                    : encode(tmp.substring(at + 1), allowed_fragment);
  +                    : encode(tmp.substring(at + 1), allowed_fragment, charset);
               }
           }
   
  @@ -2106,7 +2145,7 @@
        *
        * @param original the original character sequence of authority component
        * @param escaped <code>true</code> if <code>original</code> is escaped
  -     * @exception URIException If an error occurs.
  +     * @throws URIException If an error occurs.
        */
       protected void parseAuthority(String original, boolean escaped)
           throws URIException {
  @@ -2115,13 +2154,18 @@
           _is_reg_name = _is_server =
           _is_hostname = _is_IPv4address = _is_IPv6reference = false;
   
  +        // set the charset to do escape encoding
  +        String charset = (protocolCharset != null) ? protocolCharset :
  +            defaultProtocolCharset;
  +
           boolean hasPort = true;
           int from = 0;
           int next = original.indexOf('@');
           if (next != -1) { // neither -1 and 0
               // each protocol extented from URI supports the specific userinfo
               _userinfo = (escaped) ? original.substring(0, next).toCharArray() 
  -                : encode(original.substring(0, next), allowed_userinfo);
  +                : encode(original.substring(0, next), allowed_userinfo,
  +                        charset);
               from = next + 1;
           }
           next = original.indexOf('[', from);
  @@ -2134,7 +2178,8 @@
               }
               // In IPv6reference, '[', ']' should be excluded
               _host = (escaped) ? original.substring(from, next).toCharArray() 
  -                : encode(original.substring(from, next), allowed_IPv6reference);
  +                : encode(original.substring(from, next), allowed_IPv6reference,
  +                        charset);
               // Set flag
               _is_IPv6reference = true;
           } else { // only for !_is_IPv6reference
  @@ -2162,7 +2207,7 @@
               _is_IPv6reference = false;
               // set a registry-based naming authority
               _authority = (escaped) ? original.toString().toCharArray() 
  -                : encode(original.toString(), allowed_reg_name);
  +                : encode(original.toString(), allowed_reg_name, charset);
           } else {
               if (original.length() - 1 > next && hasPort 
                   && original.charAt(next) == ':') { // not empty
  @@ -2425,36 +2470,37 @@
        *
        * <p>
        * Always all the time, the setter method is always succeeded and throws
  -     * <code>CharsetChanged</code> exception.
  +     * <code>DefaultCharsetChanged</code> exception.
        *
        * So API programmer must follow the following way:
  -     * <code>
  -     *  import org.apache.util.URI$CharsetChanged;
  +     * <code><pre>
  +     *  import org.apache.util.URI$DefaultCharsetChanged;
        *      .
        *      .
        *      .
        *  try {
  -     *      URI.setProtocolCharset("UTF-8");
  -     *  } catch (CharsetChanged cc) {
  -     *      if (cc.getReasonCode() == CharsetChanged.PROTOCOL_CHARSET) {
  -     *      // let user know the default protocol charset changed
  +     *      URI.setDefaultProtocolCharset("UTF-8");
  +     *  } catch (DefaultCharsetChanged cc) {
  +     *      // CASE 1: the exception could be ignored, when it is set by user
  +     *      if (cc.getReasonCode() == DefaultCharsetChanged.PROTOCOL_CHARSET) {
  +     *      // CASE 2: let user know the default protocol charset changed
        *      } else {
  -     *      // let user know the default document charset changed
  +     *      // CASE 2: let user know the default document charset changed
        *      }
        *  }
  -     *  </code>
  +     *  </pre></code>
        *
        * The API programmer is responsible to set the correct charset.
        * And each application should remember its own charset to support.
        *
        * @param charset the default charset for each protocol
  -     * @throws CharsetChanged charset changed
  +     * @throws DefaultDefaultCharsetChanged default charset changed
        */
  -    public static void setProtocolCharset(String charset) 
  -        throws CharsetChanged {
  +    public static void setDefaultProtocolCharset(String charset) 
  +        throws DefaultCharsetChanged {
               
  -        _protocolCharset = charset;
  -        throw new CharsetChanged(CharsetChanged.PROTOCOL_CHARSET,
  +        defaultProtocolCharset = charset;
  +        throw new DefaultCharsetChanged(DefaultCharsetChanged.PROTOCOL_CHARSET,
                   "the default protocol charset changed");
       }
   
  @@ -2471,10 +2517,21 @@
        * For support of global compatibility it is STRONGLY RECOMMENDED that
        * clients and servers use UTF-8 encoding when exchanging URIs.
        *
  -     * @return the charset string
  +     * @return the default charset string
        */
  -    public static String getProtocolCharset() {
  -        return _protocolCharset;
  +    public static String getDefaultProtocolCharset() {
  +        return defaultProtocolCharset;
  +    }
  +
  +
  +    /**
  +     * Get the charset of the protocol used by this current URI instance.
  +     * It was set by the constructor for this instance.
  +     *
  +     * @return the protocol charset string
  +     */
  +    public String getProtocolCharset() {
  +        return protocolCharset;
       }
   
   
  @@ -2489,47 +2546,68 @@
        * <p>
        *
        * Always all the time, the setter method is always succeeded and throws
  -     * <code>CharsetChanged</code> exception.
  +     * <code>DefaultCharsetChanged</code> exception.
        *
        * So API programmer must follow the following way:
  -     * <code>
  -     *  import org.apache.util.URI$CharsetChanged;
  +     * <code><pre>
  +     *  import org.apache.util.URI$DefaultCharsetChanged;
        *      .
        *      .
        *      .
        *  try {
  -     *      URI.setDocumentCharset("EUC-KR");
  -     *  } catch (CharsetChanged cc) {
  -     *      if (cc.getReasonCode() == CharsetChanged.DOCUMENT_CHARSET) {
  -     *      // let user know the default document charset changed
  +     *      URI.setDefaultDocumentCharset("EUC-KR");
  +     *  } catch (DefaultCharsetChanged cc) {
  +     *      // CASE 1: the exception could be ignored, when it is set by user
  +     *      if (cc.getReasonCode() == DefaultCharsetChanged.DOCUMENT_CHARSET) {
  +     *      // CASE 2: let user know the default document charset changed
        *      } else {
  -     *      // let user know the default protocol charset changed
  +     *      // CASE 2: let user know the default protocol charset changed
        *      }
        *  }
  -     *  </code>
  +     *  </pre></code>
        *
        * The API programmer is responsible to set the correct charset.
        * And each application should remember its own charset to support.
        *
        * @param charset the default charset for the document
  -     * @throws CharsetChanged charset changed
  +     * @throws DefaultCharsetChanged default charset changed
        */
  -    public static void setDocumentCharset(String charset) 
  -        throws CharsetChanged {
  +    public static void setDefaultDocumentCharset(String charset) 
  +        throws DefaultCharsetChanged {
               
  -        _documentCharset = charset;
  -        throw new CharsetChanged(CharsetChanged.DOCUMENT_CHARSET,
  +        defaultDocumentCharset = charset;
  +        throw new DefaultCharsetChanged(DefaultCharsetChanged.DOCUMENT_CHARSET,
                   "the default document charset changed");
       }
   
   
       /**
  -     * Get the default charset of the document.
  +     * Get the recommended default charset of the document.
        *
  -     * @return the charset string
  +     * @return the default charset string
        */
  -    public static String getDocumentCharset() {
  -        return _documentCharset;
  +    public static String getDefaultDocumentCharset() {
  +        return defaultDocumentCharset;
  +    }
  +
  +
  +    /**
  +     * Get the default charset of the document by locale.
  +     *
  +     * @return the default charset string by locale
  +     */
  +    public static String getDefaultDocumentCharsetByLocale() {
  +        return defaultDocumentCharsetByLocale;
  +    }
  +
  +
  +    /**
  +     * Get the default charset of the document by platform.
  +     *
  +     * @return the default charset string by platform
  +     */
  +    public static String getDefaultDocumentCharsetByPlatform() {
  +        return defaultDocumentCharsetByPlatform;
       }
   
       // ------------------------------------------------------------- The scheme
  @@ -2564,7 +2642,7 @@
        * </pre></blockquote><p>
        *
        * @param escapedAuthority the raw escaped authority
  -     * @exception URIException If {@link 
  +     * @throws URIException If {@link 
        * #parseAuthority(java.lang.String,boolean)} fails
        * @throws NullPointerException null authority
        */
  @@ -2582,7 +2660,7 @@
        * Note that there is no setAuthority method by the escape encoding reason.
        *
        * @param escapedAuthority the escaped authority string
  -     * @exception URIException If {@link 
  +     * @throws URIException If {@link 
        * #parseAuthority(java.lang.String,boolean)} fails
        */
       public void setEscapedAuthority(String escapedAuthority)
  @@ -2617,10 +2695,12 @@
        * Get the authority.
        *
        * @return the authority
  -     * @exception URIException If {@link #decode(char[])} fails
  +     * @throws URIException If {@link #decode} fails
        */
       public String getAuthority() throws URIException {
  -        return (_authority == null) ? null : decode(_authority);
  +        return (_authority == null) ? null : decode(_authority,
  +                (protocolCharset != null) ? protocolCharset :
  +                defaultProtocolCharset);
       }
   
       // ----------------------------------------------------------- The userinfo
  @@ -2651,11 +2731,13 @@
        * Get the userinfo.
        *
        * @return the userinfo
  -     * @exception URIException If {@link #decode(char[])} fails
  +     * @throws URIException If {@link #decode} fails
        * @see #getAuthority
        */
       public String getUserinfo() throws URIException {
  -        return (_userinfo == null) ? null : decode(_userinfo);
  +        return (_userinfo == null) ? null : decode(_userinfo,
  +                (protocolCharset != null) ? protocolCharset :
  +                defaultProtocolCharset);
       }
   
       // --------------------------------------------------------------- The host
  @@ -2681,11 +2763,12 @@
        * </pre></blockquote><p>
        *
        * @return the host
  -     * @exception URIException If {@link #decode(char[])} fails
  +     * @throws URIException If {@link #decode} fails
        * @see #getAuthority
        */
       public String getHost() throws URIException {
  -        return decode(_host);
  +        return decode(_host, (protocolCharset != null) ? protocolCharset :
  +                defaultProtocolCharset);
       }
   
       // --------------------------------------------------------------- The port
  @@ -2709,7 +2792,7 @@
        * Set the raw-escaped path.
        *
        * @param escapedPath the path character sequence
  -     * @exception URIException encoding error or not proper for initial instance
  +     * @throws URIException encoding error or not proper for initial instance
        * @see #encode
        */
       public void setRawPath(char[] escapedPath) throws URIException {
  @@ -2761,7 +2844,7 @@
        * Set the escaped path.
        *
        * @param escapedPath the escaped path string
  -     * @exception URIException encoding error or not proper for initial instance
  +     * @throws URIException encoding error or not proper for initial instance
        * @see #encode
        */
       public void setEscapedPath(String escapedPath) throws URIException {
  @@ -2778,7 +2861,7 @@
        * Set the path.
        *
        * @param path the path string
  -     * @exception URIException set incorrectly or fragment only
  +     * @throws URIException set incorrectly or fragment only
        * @see #encode
        */
       public void setPath(String path) throws URIException {
  @@ -2788,8 +2871,11 @@
               setURI();
               return;
           }
  +        // set the charset to do escape encoding
  +        String charset = (protocolCharset != null) ? protocolCharset :
  +            defaultProtocolCharset;
           if (_is_net_path || _is_abs_path) {
  -            _path = encode(path, allowed_abs_path);
  +            _path = encode(path, allowed_abs_path, charset);
           } else if (_is_rel_path) {
               StringBuffer buff = new StringBuffer(path.length());
               int at = path.indexOf('/');
  @@ -2798,16 +2884,18 @@
                           "incorrect relative path");
               }
               if (at > 0) {
  -                buff.append(encode(path.substring(0, at), allowed_rel_path));
  -                buff.append(encode(path.substring(at), allowed_abs_path));
  +                buff.append(encode(path.substring(0, at), allowed_rel_path,
  +                            charset));
  +                buff.append(encode(path.substring(at), allowed_abs_path,
  +                            charset));
               } else {
  -                buff.append(encode(path, allowed_rel_path));
  +                buff.append(encode(path, allowed_rel_path, charset));
               }
               _path = buff.toString().toCharArray();
           } else if (_is_opaque_part) {
               StringBuffer buf = new StringBuffer();
  -            buf.insert(0, encode(path.substring(0, 1), uric_no_slash));
  -            buf.insert(1, encode(path.substring(1), uric));
  +            buf.insert(0, encode(path.substring(0, 1), uric_no_slash, charset));
  +            buf.insert(1, encode(path.substring(1), uric, charset));
               _opaque = buf.toString().toCharArray();
           } else {
               throw new URIException(URIException.PARSING, "incorrect path");
  @@ -2822,7 +2910,7 @@
        * @param basePath a character array of the basePath
        * @param relPath a character array of the relPath
        * @return the resolved path
  -     * @exception URIException no more higher path level to be resolved
  +     * @throws URIException no more higher path level to be resolved
        */
       protected char[] resolvePath(char[] basePath, char[] relPath)
           throws URIException {
  @@ -2857,7 +2945,7 @@
        *
        * @param path the path
        * @return the current hierarchy level
  -     * @exception URIException no hierarchy level
  +     * @throws URIException no hierarchy level
        */
       protected char[] getRawCurrentHierPath(char[] path) throws URIException {
   
  @@ -2884,7 +2972,7 @@
        * Get the raw-escaped current hierarchy level.
        *
        * @return the raw-escaped current hierarchy level
  -     * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails.
  +     * @throws URIException If {@link #getRawCurrentHierPath(char[])} fails.
        */
       public char[] getRawCurrentHierPath() throws URIException {
           return (_path == null) ? null : getRawCurrentHierPath(_path);
  @@ -2895,7 +2983,7 @@
        * Get the escaped current hierarchy level.
        *
        * @return the escaped current hierarchy level
  -     * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails.
  +     * @throws URIException If {@link #getRawCurrentHierPath(char[])} fails.
        */
       public String getEscapedCurrentHierPath() throws URIException {
           char[] path = getRawCurrentHierPath();
  @@ -2907,12 +2995,13 @@
        * Get the current hierarchy level.
        *
        * @return the current hierarchy level
  -     * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails.
  +     * @throws URIException If {@link #getRawCurrentHierPath(char[])} fails.
        * @see #decode
        */
       public String getCurrentHierPath() throws URIException {
           char[] path = getRawCurrentHierPath();
  -        return (path == null) ? null : decode(path);
  +        return (path == null) ? null : decode(path, (protocolCharset != null) ?
  +                protocolCharset : defaultProtocolCharset);
       }
   
   
  @@ -2920,7 +3009,7 @@
        * Get the level above the this hierarchy level.
        *
        * @return the raw above hierarchy level
  -     * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails.
  +     * @throws URIException If {@link #getRawCurrentHierPath(char[])} fails.
        */
       public char[] getRawAboveHierPath() throws URIException {
           char[] path = getRawCurrentHierPath();
  @@ -2932,7 +3021,7 @@
        * Get the level above the this hierarchy level.
        *
        * @return the raw above hierarchy level
  -     * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails.
  +     * @throws URIException If {@link #getRawCurrentHierPath(char[])} fails.
        */
       public String getEscapedAboveHierPath() throws URIException {
           char[] path = getRawAboveHierPath();
  @@ -2944,12 +3033,13 @@
        * Get the level above the this hierarchy level.
        *
        * @return the above hierarchy level
  -     * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails.
  +     * @throws URIException If {@link #getRawCurrentHierPath(char[])} fails.
        * @see #decode
        */
       public String getAboveHierPath() throws URIException {
           char[] path = getRawAboveHierPath();
  -        return (path == null) ? null : decode(path);
  +        return (path == null) ? null : decode(path, (protocolCharset != null) ?
  +                protocolCharset : defaultProtocolCharset);
       }
   
   
  @@ -2988,12 +3078,13 @@
        *   path          = [ abs_path | opaque_part ]
        * </pre></blockquote><p>
        * @return the path string
  -     * @exception URIException If {@link #decode(char[])} fails.
  +     * @throws URIException If {@link #decode} fails.
        * @see #decode
        */
       public String getPath() throws URIException { 
           char[] path =  getRawPath();
  -        return (path == null) ? null : decode(path);
  +        return (path == null) ? null : decode(path, (protocolCharset != null) ?
  +                protocolCharset : defaultProtocolCharset);
       }
   
   
  @@ -3036,13 +3127,15 @@
        * Get the basename of the path.
        *
        * @return the basename string
  -     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * @throws URIException incomplete trailing escape pattern or unsupported
        * character encoding
        * @see #decode
        */
       public String getName() throws URIException {
           char[] basename = getRawName();
  -        return (basename == null) ? null : decode(getRawName());
  +        return (basename == null) ? null : decode(getRawName(),
  +                (protocolCharset != null) ? protocolCharset :
  +                defaultProtocolCharset);
       }
   
       // ----------------------------------------------------- The path and query 
  @@ -3084,13 +3177,15 @@
        * Get the path and query.
        *
        * @return the path and query string.
  -     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * @throws URIException incomplete trailing escape pattern or unsupported
        * character encoding
        * @see #decode
        */
       public String getPathQuery() throws URIException {
           char[] rawPathQuery = getRawPathQuery();
  -        return (rawPathQuery == null) ? null : decode(rawPathQuery);
  +        return (rawPathQuery == null) ? null : decode(rawPathQuery,
  +                (protocolCharset != null) ? protocolCharset :
  +                defaultProtocolCharset);
       }
   
       // -------------------------------------------------------------- The query 
  @@ -3099,7 +3194,7 @@
        * Set the raw-escaped query.
        *
        * @param escapedQuery the raw-escaped query
  -     * @exception URIException escaped query not valid
  +     * @throws URIException escaped query not valid
        */
       public void setRawQuery(char[] escapedQuery) throws URIException {
           if (escapedQuery == null || escapedQuery.length == 0) {
  @@ -3122,7 +3217,7 @@
        * Set the escaped query string.
        *
        * @param escapedQuery the escaped query string
  -     * @exception URIException escaped query not valid
  +     * @throws URIException escaped query not valid
        */
       public void setEscapedQuery(String escapedQuery) throws URIException {
           if (escapedQuery == null) {
  @@ -3147,7 +3242,7 @@
        * implemented in each specific protocol instance.
        *
        * @param query the query string.
  -     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * @throws URIException incomplete trailing escape pattern or unsupported
        * character encoding
        * @see #encode
        */
  @@ -3157,7 +3252,8 @@
               setURI();
               return;
           }
  -        setRawQuery(encode(query, allowed_query));
  +        setRawQuery(encode(query, allowed_query, (protocolCharset != null) ?
  +                    protocolCharset : defaultProtocolCharset));
       }
   
   
  @@ -3185,12 +3281,14 @@
        * Get the query.
        *
        * @return the query string.
  -     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * @throws URIException incomplete trailing escape pattern or unsupported
        * character encoding
        * @see #decode
        */
       public String getQuery() throws URIException {
  -        return (_query == null) ? null : decode(_query);
  +        return (_query == null) ? null : decode(_query,
  +                (protocolCharset != null) ? protocolCharset :
  +                defaultProtocolCharset);
       }
   
       // ----------------------------------------------------------- The fragment 
  @@ -3199,7 +3297,7 @@
        * Set the raw-escaped fragment.
        *
        * @param escapedFragment the raw-escaped fragment
  -     * @exception URIException escaped fragment not valid
  +     * @throws URIException escaped fragment not valid
        */
       public void setRawFragment(char[] escapedFragment) throws URIException {
           if (escapedFragment == null || escapedFragment.length == 0) {
  @@ -3220,7 +3318,7 @@
        * Set the escaped fragment string.
        *
        * @param escapedFragment the escaped fragment string
  -     * @exception URIException escaped fragment not valid
  +     * @throws URIException escaped fragment not valid
        */
       public void setEscapedFragment(String escapedFragment) throws URIException {
           if (escapedFragment == null) {
  @@ -3236,7 +3334,7 @@
        * Set the fragment.
        *
        * @param fragment the fragment string.
  -     * @exception URIException If an error occurs.
  +     * @throws URIException If an error occurs.
        */
       public void setFragment(String fragment) throws URIException {
           if (fragment == null || fragment.length() == 0) {
  @@ -3244,7 +3342,8 @@
               hash = 0;
               return;
           }
  -        _fragment = encode(fragment, allowed_fragment);
  +        _fragment = encode(fragment, allowed_fragment, (protocolCharset != null)
  +                ? protocolCharset : defaultProtocolCharset);
           hash = 0;
       }
   
  @@ -3283,12 +3382,14 @@
        * Get the fragment.
        *
        * @return the fragment string
  -     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * @throws URIException incomplete trailing escape pattern or unsupported
        * character encoding
        * @see #decode
        */
       public String getFragment() throws URIException {
  -        return (_fragment == null) ? null : decode(_fragment);
  +        return (_fragment == null) ? null : decode(_fragment,
  +                (protocolCharset != null) ? protocolCharset :
  +                defaultProtocolCharset);
       }
   
       // ------------------------------------------------------------- Utilities 
  @@ -3317,7 +3418,7 @@
        *
        * @param path the path to normalize
        * @return the normalized path
  -     * @exception URIException no more higher path level to be normalized
  +     * @throws URIException no more higher path level to be normalized
        */
       protected char[] normalize(char[] path) throws URIException {
   
  @@ -3360,7 +3461,8 @@
               if (at == 0) {
                   // no more higher path level to be normalized
                   if (!endsWithSlash && normalized.endsWith("/")) {
  -                    normalized = normalized.substring(0, normalized.length() - 1);
  +                    normalized =
  +                        normalized.substring(0, normalized.length() - 1);
                   } else if (endsWithSlash && !normalized.endsWith("/")) {
                       normalized = normalized + "/";
                   }
  @@ -3388,7 +3490,7 @@
       /**
        * Normalize the path part of this URI.
        *
  -     * @exception URIException no more higher path level to be normalized
  +     * @throws URIException no more higher path level to be normalized
        */
       public void normalize() throws URIException {
           _path = normalize(_path);
  @@ -3528,7 +3630,7 @@
        * @param obj the object to be compared.
        * @return 0, if it's same,
        * -1, if failed, first being compared with in the authority component
  -     * @exception ClassCastException not URI argument
  +     * @throws ClassCastException not URI argument
        */
       public int compareTo(Object obj) throws ClassCastException {
   
  @@ -3565,6 +3667,8 @@
           instance._path = _path;
           instance._query = _query;
           instance._fragment = _fragment;
  +        // the charset to do escape encoding for this instance
  +        instance.protocolCharset = protocolCharset;
           // flags
           instance._is_hier_part = _is_hier_part;
           instance._is_opaque_part = _is_opaque_part;
  @@ -3617,12 +3721,14 @@
        * It can be gotten the URI character sequence.
        *
        * @return the original URI string
  -     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * @throws URIException incomplete trailing escape pattern or unsupported
        * character encoding
        * @see #decode
        */
       public String getURI() throws URIException {
  -        return (_uri == null) ? null : decode(_uri);
  +        return (_uri == null) ? null : decode(_uri,
  +                (protocolCharset != null) ? protocolCharset :
  +                defaultProtocolCharset);
       }
   
   
  @@ -3659,11 +3765,13 @@
        * Get the original URI reference string.
        *
        * @return the original URI reference string
  -     * @throws URIException If {@link #decode(char[])} fails.
  +     * @throws URIException If {@link #decode} fails.
        */
       public String getURIReference() throws URIException {
           char[] uriReference = getRawURIReference();
  -        return (uriReference == null) ? null : decode(uriReference);
  +        return (uriReference == null) ? null : decode(uriReference,
  +                (protocolCharset != null) ? protocolCharset :
  +                defaultProtocolCharset);
       }
   
   
  @@ -3694,12 +3802,8 @@
       /** 
        * The charset-changed normal operation to represent to be required to
        * alert to user the fact the default charset is changed.
  -     * 
  -     * TODO: This should be renamed to CharsetChangedException and made a top
  -     * level class.  There is no reason (that I can see) to have this as an
  -     * inner class.
        */
  -    public static class CharsetChanged extends RuntimeException {
  +    public static class DefaultCharsetChanged extends RuntimeException {
   
           // ------------------------------------------------------- constructors
   
  @@ -3709,7 +3813,7 @@
            * @param reasonCode the reason code
            * @param reason the reason
            */
  -        public CharsetChanged(int reasonCode, String reason) {
  +        public DefaultCharsetChanged(int reasonCode, String reason) {
               super(reason);
               this.reason = reason;
               this.reasonCode = reasonCode;
  @@ -3820,7 +3924,8 @@
            */
           public static String getCharset(Locale locale) {
               // try for an full name match (may include country)
  -            String charset = (String) LOCALE_TO_CHARSET_MAP.get(locale.toString());
  +            String charset =
  +                (String) LOCALE_TO_CHARSET_MAP.get(locale.toString());
               if (charset != null) { 
                   return charset;
               }
  
  
  
  1.10      +107 -55   jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpURL.java
  
  Index: HttpURL.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpURL.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- HttpURL.java	28 Jan 2003 22:25:22 -0000	1.9
  +++ HttpURL.java	13 Feb 2003 05:08:18 -0000	1.10
  @@ -73,16 +73,36 @@
   
       // ----------------------------------------------------------- Constructors
   
  -    /** Create an instance. */
  +    /** Create an instance as an internal use. */
       protected HttpURL() {
       }
   
  +
  +    /**
  +     * Construct a HTTP URL as an escaped form of a character array with the
  +     * given charset to do escape encoding.
  +     *
  +     * @param escaped the HTTP URL character sequence
  +     * @param charset the charset string to do escape encoding
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @throws NullPointerException if <code>escaped</code> is <code>null</code>
  +     * @see #getProtocolCharset
  +     */
  +    public HttpURL(char[] escaped, String charset)
  +        throws URIException, NullPointerException {
  +        protocolCharset = charset;
  +        parseUriReference(new String(escaped), true);
  +        checkValid();
  +    }
  +
  +
       /**
        * Construct a HTTP URL as an escaped form of a character array.
        *
        * @param escaped the HTTP URL character sequence
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
        * @throws NullPointerException if <code>escaped</code> is <code>null</code>
  +     * @see #getDefaultProtocolCharset
        */
       public HttpURL(char[] escaped) throws URIException, NullPointerException {
           parseUriReference(new String(escaped), true);
  @@ -91,26 +111,30 @@
   
   
       /**
  -     * Construct a HTTP URL from a given string.
  +     * Construct a HTTP URL from a given string with the given charset to do
  +     * escape encoding.
        *
        * @param original the HTTP URL string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @param charset the charset string to do escape encoding
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getProtocolCharset
        */
  -    public HttpURL(String original) throws URIException {
  +    public HttpURL(String original, String charset) throws URIException {
  +        protocolCharset = charset;
           parseUriReference(original, false);
           checkValid();
       }
   
   
       /**
  -     * Construct a HTTP URL from given components.
  +     * Construct a HTTP URL from a given string.
        *
  -     * @param host the host string
  -     * @param path the path string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @param original the HTTP URL string
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
  -    public HttpURL(String host, String path) throws URIException {
  -        this(null, host, -1, path, null, null);
  +    public HttpURL(String original) throws URIException {
  +        parseUriReference(original, false);
           checkValid();
       }
   
  @@ -121,7 +145,8 @@
        * @param host the host string
        * @param port the port number
        * @param path the path string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpURL(String host, int port, String path) throws URIException {
           this(null, host, port, path, null, null);
  @@ -136,7 +161,8 @@
        * @param port the port number
        * @param path the path string
        * @param query the query string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpURL(String host, int port, String path, String query)
           throws URIException {
  @@ -152,7 +178,8 @@
        * @param user the user name
        * @param password his or her password
        * @param host the host string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpURL(String user, String password, String host)
           throws URIException {
  @@ -171,7 +198,8 @@
        * @param password his or her password
        * @param host the host string
        * @param port the port number
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpURL(String user, String password, String host, int port)
           throws URIException {
  @@ -191,7 +219,8 @@
        * @param host the host string
        * @param port the port number
        * @param path the path string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpURL(String user, String password, String host, int port,
               String path) throws URIException {
  @@ -212,7 +241,8 @@
        * @param port the port number
        * @param path the path string
        * @param query The query string.
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpURL(String user, String password, String host, int port,
               String path, String query) throws URIException {
  @@ -231,7 +261,8 @@
        * @param path the path string
        * @param query the query string
        * @param fragment the fragment string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpURL(String host, String path, String query, String fragment)
           throws URIException {
  @@ -249,7 +280,8 @@
        * @param path the path string
        * @param query the query string
        * @param fragment the fragment string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpURL(String userinfo, String host, String path, String query,
               String fragment) throws URIException {
  @@ -266,7 +298,8 @@
        * @param host the host string
        * @param port the port number
        * @param path the path string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpURL(String userinfo, String host, int port, String path)
           throws URIException {
  @@ -284,7 +317,8 @@
        * @param port the port number
        * @param path the path string
        * @param query the query string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpURL(String userinfo, String host, int port, String path,
               String query) throws URIException {
  @@ -303,7 +337,8 @@
        * @param path the path string
        * @param query the query string
        * @param fragment the fragment string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpURL(String userinfo, String host, int port, String path,
               String query, String fragment) throws URIException {
  @@ -351,7 +386,7 @@
        *
        * @param base the base HttpURL
        * @param relative the relative HTTP URL string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
        */
       public HttpURL(HttpURL base, String relative) throws URIException {
           this(base, new HttpURL(relative));
  @@ -363,7 +398,7 @@
        *
        * @param base the base HttpURL
        * @param relative the relative HttpURL
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
        */
       public HttpURL(HttpURL base, HttpURL relative) throws URIException {
           super(base, relative);
  @@ -439,7 +474,7 @@
        *
        * @param escapedUser the raw-escaped user
        * @param escapedPassword the raw-escaped password; could be null
  -     * @exception URIException escaped user not valid or user required; escaped
  +     * @throws URIException escaped user not valid or user required; escaped
        * password not valid or username missed
        */
       public void setRawUserinfo(char[] escapedUser, char[] escapedPassword)
  @@ -472,7 +507,7 @@
        *
        * @param escapedUser the escaped user
        * @param escapedPassword the escaped password; could be null
  -     * @exception URIException escaped user not valid or user required; escaped
  +     * @throws URIException escaped user not valid or user required; escaped
        * password not valid or username missed
        * @throws NullPointerException null user
        */
  @@ -489,13 +524,17 @@
        *
        * @param user the user
        * @param password the password; could be null
  -     * @exception URIException encoding error or username missed
  +     * @throws URIException encoding error or username missed
        * @throws NullPointerException null user
        */
       public void setUserinfo(String user, String password) 
           throws URIException, NullPointerException {
  -        setRawUserinfo(encode(user, within_userinfo), (password == null) 
  -            ? null : encode(password, within_userinfo));
  +        // set the charset to do escape encoding
  +        String charset = (protocolCharset != null) ? protocolCharset :
  +            defaultProtocolCharset;
  +        setRawUserinfo(encode(user, within_userinfo, charset),
  +                (password == null) ? null :
  +                encode(password, within_userinfo, charset));
       }
   
   
  @@ -503,7 +542,7 @@
        * Set the raw-escaped user.
        *
        * @param escapedUser the raw-escaped user
  -     * @exception URIException escaped user not valid or user required
  +     * @throws URIException escaped user not valid or user required
        */
       public void setRawUser(char[] escapedUser) throws URIException {
           if (escapedUser == null || escapedUser.length == 0) {
  @@ -529,10 +568,11 @@
        * Set the escaped user string.
        *
        * @param escapedUser the escaped user string
  -     * @exception URIException escaped user not valid
  +     * @throws URIException escaped user not valid
        * @throws NullPointerException null user
        */
  -    public void setEscapedUser(String escapedUser) throws URIException, NullPointerException {
  +    public void setEscapedUser(String escapedUser)
  +        throws URIException, NullPointerException {
           setRawUser(escapedUser.toCharArray());
       }
   
  @@ -541,11 +581,13 @@
        * Set the user string.
        *
        * @param user the user string
  -     * @exception URIException user encoding error
  +     * @throws URIException user encoding error
        * @throws NullPointerException null user
        */
       public void setUser(String user) throws URIException, NullPointerException {
  -        setRawUser(encode(user, allowed_within_userinfo));
  +        setRawUser(encode(user, allowed_within_userinfo,
  +                    (protocolCharset != null) ? protocolCharset :
  +                    defaultProtocolCharset));
       }
   
   
  @@ -584,11 +626,12 @@
        * Get the user.
        *
        * @return the user name
  -     * @exception URIException If {@link #decode(char[])} fails
  +     * @throws URIException If {@link #decode} fails
        */
       public String getUser() throws URIException {
           char[] user = getRawUser();
  -        return (user == null) ? null : decode(user);
  +        return (user == null) ? null : decode(user, (protocolCharset != null) ?
  +                protocolCharset : defaultProtocolCharset);
       }
   
   
  @@ -596,7 +639,7 @@
        * Set the raw-escaped password.
        *
        * @param escapedPassword the raw-escaped password; could be null
  -     * @exception URIException escaped password not valid or username missed
  +     * @throws URIException escaped password not valid or username missed
        */
       public void setRawPassword(char[] escapedPassword) throws URIException {
           if (escapedPassword != null 
  @@ -624,7 +667,7 @@
        * Set the escaped password string.
        *
        * @param escapedPassword the escaped password string; could be null
  -     * @exception URIException escaped password not valid or username missed
  +     * @throws URIException escaped password not valid or username missed
        */
       public void setEscapedPassword(String escapedPassword) throws URIException {
           setRawPassword((escapedPassword == null) ? null 
  @@ -636,11 +679,12 @@
        * Set the password string.
        *
        * @param password the password string; could be null
  -     * @exception URIException encoding error or username missed
  +     * @throws URIException encoding error or username missed
        */
       public void setPassword(String password) throws URIException {
  -        setRawPassword((password == null) ? null 
  -            : encode(password, allowed_within_userinfo));
  +        setRawPassword((password == null) ? null : encode(password,
  +                    allowed_within_userinfo, (protocolCharset != null) ?
  +                    protocolCharset : defaultProtocolCharset));
       }
   
   
  @@ -676,11 +720,13 @@
        * Get the password.
        *
        * @return the password
  -     * @exception URIException If {@link #decode(char[],String)} fails.
  +     * @throws URIException If {@link #decode(char[],String)} fails.
        */
       public String getPassword() throws URIException {
           char[] password = getRawPassword();
  -        return (password == null) ? null : decode(password);
  +        return (password == null) ? null : decode(password,
  +                (protocolCharset != null) ? protocolCharset :
  +                defaultProtocolCharset);
       }
   
       // --------------------------------------------------------------- The path
  @@ -689,7 +735,7 @@
        * Get the raw-escaped current hierarchy level.
        *
        * @return the raw-escaped current hierarchy level
  -     * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails.
  +     * @throws URIException If {@link #getRawCurrentHierPath(char[])} fails.
        */
       public char[] getRawCurrentHierPath() throws URIException {
           return (_path == null || _path.length == 0) ? rootPath 
  @@ -701,7 +747,7 @@
        * Get the level above the this hierarchy level.
        *
        * @return the raw above hierarchy level
  -     * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails.
  +     * @throws URIException If {@link #getRawCurrentHierPath(char[])} fails.
        */
       public char[] getRawAboveHierPath() throws URIException {
           char[] path = getRawCurrentHierPath();
  @@ -726,7 +772,7 @@
        *
        * @param queryName the query string.
        * @param queryValue the query string.
  -     * @exception URIException incomplete trailing escape pattern
  +     * @throws URIException incomplete trailing escape pattern
        * Or unsupported character encoding
        * @throws NullPointerException null query
        * @see #encode
  @@ -735,9 +781,12 @@
           throws URIException, NullPointerException {
   
           StringBuffer buff = new StringBuffer();
  -        buff.append(encode(queryName, allowed_within_query));
  +        // set the charset to do escape encoding
  +        String charset = (protocolCharset != null) ? protocolCharset :
  +            defaultProtocolCharset;
  +        buff.append(encode(queryName, allowed_within_query, charset));
           buff.append('=');
  -        buff.append(encode(queryValue, allowed_within_query));
  +        buff.append(encode(queryValue, allowed_within_query, charset));
           _query = buff.toString().toCharArray();
           setURI();
       }
  @@ -748,7 +797,7 @@
        *
        * @param queryName the array of the query string.
        * @param queryValue the array of the query string.
  -     * @exception URIException incomplete trailing escape pattern,
  +     * @throws URIException incomplete trailing escape pattern,
        * unsupported character encoding or wrong array size
        * @throws NullPointerException null query
        * @see #encode
  @@ -762,10 +811,13 @@
           }
   
           StringBuffer buff = new StringBuffer();
  +        // set the charset to do escape encoding
  +        String charset = (protocolCharset != null) ? protocolCharset :
  +            defaultProtocolCharset;
           for (int i = 0; i < length; i++) {
  -            buff.append(encode(queryName[i], allowed_within_query));
  +            buff.append(encode(queryName[i], allowed_within_query, charset));
               buff.append('=');
  -            buff.append(encode(queryValue[i], allowed_within_query));
  +            buff.append(encode(queryValue[i], allowed_within_query, charset));
               if (i + 1 < length) { 
                   buff.append('&');
               }
  @@ -779,7 +831,7 @@
       /**
        * Verify the valid class use for construction.
        *
  -     * @exception URIException the wrong scheme use
  +     * @throws URIException the wrong scheme use
        */
       protected void checkValid() throws URIException {
           // could be explicit protocol or undefined.
  
  
  
  1.6       +63 -30    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpsURL.java
  
  Index: HttpsURL.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpsURL.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HttpsURL.java	28 Jan 2003 22:25:22 -0000	1.5
  +++ HttpsURL.java	13 Feb 2003 05:08:18 -0000	1.6
  @@ -74,17 +74,37 @@
       // ----------------------------------------------------------- Constructors
   
       /**
  -     * Create an instance.
  +     * Create an instance as an internal use.
        */
       protected HttpsURL() {
       }
   
  +
  +    /**
  +     * Construct a HTTPS URL as an escaped form of a character array with the
  +     * given charset to do escape encoding.
  +     *
  +     * @param escaped the HTTPS URL character sequence
  +     * @param charset the charset to do escape encoding
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @throws NullPointerException if <code>escaped</code> is <code>null</code>
  +     * @see #getProtocolCharset
  +     */
  +    public HttpsURL(char[] escaped, String charset)
  +        throws URIException, NullPointerException {
  +        protocolCharset = charset;
  +        parseUriReference(new String(escaped), true);
  +        checkValid();
  +    }
  +
  +
       /**
        * Construct a HTTPS URL as an escaped form of a character array.
        *
        * @param escaped the HTTPS URL character sequence
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
        * @throws NullPointerException if <code>escaped</code> is <code>null</code>
  +     * @see #getDefaultProtocolCharset
        */
       public HttpsURL(char[] escaped) throws URIException, NullPointerException {
           parseUriReference(new String(escaped), true);
  @@ -93,26 +113,30 @@
   
   
       /**
  -     * Construct a HTTPS URL from a given string.
  +     * Construct a HTTPS URL from a given string with the given charset to do
  +     * escape encoding.
        *
        * @param original the HTTPS URL string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @param charset the charset to do escape encoding
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getProtocolCharset
        */
  -    public HttpsURL(String original) throws URIException {
  +    public HttpsURL(String original, String charset) throws URIException {
  +        protocolCharset = charset;
           parseUriReference(original, false);
           checkValid();
       }
   
   
       /**
  -     * Construct a HTTPS URL from given components.
  +     * Construct a HTTPS URL from a given string.
        *
  -     * @param host the host string
  -     * @param path the path string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @param original the HTTPS URL string
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
  -    public HttpsURL(String host, String path) throws URIException {
  -        this(null, host, -1, path, null, null);
  +    public HttpsURL(String original) throws URIException {
  +        parseUriReference(original, false);
           checkValid();
       }
   
  @@ -123,7 +147,8 @@
        * @param host the host string
        * @param port the port number
        * @param path the path string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpsURL(String host, int port, String path) throws URIException {
           this(null, host, port, path, null, null);
  @@ -138,7 +163,8 @@
        * @param port the port number
        * @param path the path string
        * @param query the query string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpsURL(String host, int port, String path, String query)
           throws URIException {
  @@ -154,7 +180,8 @@
        * @param user the user name
        * @param password his or her password
        * @param host the host string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpsURL(String user, String password, String host)
           throws URIException {
  @@ -173,7 +200,8 @@
        * @param password his or her password
        * @param host the host string
        * @param port the port number
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpsURL(String user, String password, String host, int port)
           throws URIException {
  @@ -193,7 +221,8 @@
        * @param host the host string
        * @param port the port number
        * @param path the path string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpsURL(String user, String password, String host, int port,
               String path) throws URIException {
  @@ -214,7 +243,8 @@
        * @param port the port number
        * @param path the path string
        * @param query The query string.
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpsURL(String user, String password, String host, int port,
               String path, String query) throws URIException {
  @@ -233,7 +263,8 @@
        * @param path the path string
        * @param query the query string
        * @param fragment the fragment string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpsURL(String host, String path, String query, String fragment)
           throws URIException {
  @@ -251,7 +282,8 @@
        * @param path the path string
        * @param query the query string
        * @param fragment the fragment string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpsURL(String userinfo, String host, String path, String query,
               String fragment) throws URIException {
  @@ -268,7 +300,8 @@
        * @param host the host string
        * @param port the port number
        * @param path the path string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpsURL(String userinfo, String host, int port, String path)
           throws URIException {
  @@ -286,7 +319,8 @@
        * @param port the port number
        * @param path the path string
        * @param query the query string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpsURL(String userinfo, String host, int port, String path,
               String query) throws URIException {
  @@ -305,7 +339,8 @@
        * @param path the path string
        * @param query the query string
        * @param fragment the fragment string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
  +     * @see #getDefaultProtocolCharset
        */
       public HttpsURL(String userinfo, String host, int port, String path,
               String query, String fragment) throws URIException {
  @@ -353,7 +388,7 @@
        *
        * @param base the base HttpsURL
        * @param relative the relative HTTPS URL string
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
        */
       public HttpsURL(HttpsURL base, String relative) throws URIException {
           this(base, new HttpsURL(relative));
  @@ -365,7 +400,7 @@
        *
        * @param base the base HttpsURL
        * @param relative the relative HttpsURL
  -     * @exception URIException If {@link #checkValid()} fails
  +     * @throws URIException If {@link #checkValid()} fails
        */
       public HttpsURL(HttpsURL base, HttpsURL relative) throws URIException {
           super(base, relative);
  @@ -376,7 +411,6 @@
   
       /**
        * Default scheme for HTTPS URL.
  -     * TODO: Should this really be public?  Who else is going to use it?
        */
       public static final char[] DEFAULT_SCHEME = { 'h', 't', 't', 'p', 's' };
       
  @@ -390,7 +424,6 @@
   
       /**
        * Default port for HTTPS URL.
  -     * TODO: Should this really be public?  Who else is going to use it?
        */
       public static final int DEFAULT_PORT = 443;
   
  @@ -412,7 +445,7 @@
       /**
        * Verify the valid class use for construction.
        *
  -     * @exception URIException the wrong scheme use
  +     * @throws URIException the wrong scheme use
        */
       protected void checkValid() throws URIException {
           // could be explicit protocol or undefined.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org