commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeri...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient URI.java HttpURL.java
Date Mon, 17 Feb 2003 04:15:33 GMT
jericho     2003/02/16 20:15:33

  Modified:    httpclient/src/java/org/apache/commons/httpclient URI.java
                        HttpURL.java
  Log:
  - Return default charset (rather than null) by getProtocolCharset method,
    when the charset for instace is not set.
  - Simplify the code by getProtocolCharset method.
  
  Revision  Changes    Path
  1.33      +30 -45    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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- URI.java	13 Feb 2003 05:08:18 -0000	1.32
  +++ URI.java	17 Feb 2003 04:15:32 -0000	1.33
  @@ -267,8 +267,7 @@
               throw new URIException(URIException.PARSING, "incorrect scheme");
           }
           _opaque = encode(schemeSpecificPart, allowed_opaque_part,
  -                (protocolCharset != null) ? protocolCharset :
  -                defaultProtocolCharset);
  +                getProtocolCharset());
           // Set flag
           _is_opaque_part = true;
           _fragment = fragment.toCharArray(); 
  @@ -2009,8 +2008,8 @@
           }
   
           // set the charset to do escape encoding
  -        String charset = (protocolCharset != null) ? protocolCharset :
  -            defaultProtocolCharset;
  +        String charset = getProtocolCharset();
  +
           /*
            * Parse the query component.
            * <p><blockquote><pre>
  @@ -2155,8 +2154,7 @@
           _is_hostname = _is_IPv4address = _is_IPv6reference = false;
   
           // set the charset to do escape encoding
  -        String charset = (protocolCharset != null) ? protocolCharset :
  -            defaultProtocolCharset;
  +        String charset = getProtocolCharset();
   
           boolean hasPort = true;
           int from = 0;
  @@ -2525,13 +2523,16 @@
   
   
       /**
  -     * Get the charset of the protocol used by this current URI instance.
  -     * It was set by the constructor for this instance.
  +     * Get the protocol charset used by this current URI instance.
  +     * It was set by the constructor for this instance. If it was not set by
  +     * contructor, it will return the default protocol charset.
        *
        * @return the protocol charset string
  +     * @see #getDefaultProtocolCharset
        */
       public String getProtocolCharset() {
  -        return protocolCharset;
  +        return (protocolCharset != null) ? protocolCharset :
  +            defaultProtocolCharset;
       }
   
   
  @@ -2699,8 +2700,7 @@
        */
       public String getAuthority() throws URIException {
           return (_authority == null) ? null : decode(_authority,
  -                (protocolCharset != null) ? protocolCharset :
  -                defaultProtocolCharset);
  +                getProtocolCharset());
       }
   
       // ----------------------------------------------------------- The userinfo
  @@ -2736,8 +2736,7 @@
        */
       public String getUserinfo() throws URIException {
           return (_userinfo == null) ? null : decode(_userinfo,
  -                (protocolCharset != null) ? protocolCharset :
  -                defaultProtocolCharset);
  +                getProtocolCharset());
       }
   
       // --------------------------------------------------------------- The host
  @@ -2767,8 +2766,7 @@
        * @see #getAuthority
        */
       public String getHost() throws URIException {
  -        return decode(_host, (protocolCharset != null) ? protocolCharset :
  -                defaultProtocolCharset);
  +        return decode(_host, getProtocolCharset());
       }
   
       // --------------------------------------------------------------- The port
  @@ -2872,8 +2870,8 @@
               return;
           }
           // set the charset to do escape encoding
  -        String charset = (protocolCharset != null) ? protocolCharset :
  -            defaultProtocolCharset;
  +        String charset = getProtocolCharset();
  +
           if (_is_net_path || _is_abs_path) {
               _path = encode(path, allowed_abs_path, charset);
           } else if (_is_rel_path) {
  @@ -3000,8 +2998,7 @@
        */
       public String getCurrentHierPath() throws URIException {
           char[] path = getRawCurrentHierPath();
  -        return (path == null) ? null : decode(path, (protocolCharset != null) ?
  -                protocolCharset : defaultProtocolCharset);
  +        return (path == null) ? null : decode(path, getProtocolCharset());
       }
   
   
  @@ -3038,8 +3035,7 @@
        */
       public String getAboveHierPath() throws URIException {
           char[] path = getRawAboveHierPath();
  -        return (path == null) ? null : decode(path, (protocolCharset != null) ?
  -                protocolCharset : defaultProtocolCharset);
  +        return (path == null) ? null : decode(path, getProtocolCharset());
       }
   
   
  @@ -3083,8 +3079,7 @@
        */
       public String getPath() throws URIException { 
           char[] path =  getRawPath();
  -        return (path == null) ? null : decode(path, (protocolCharset != null) ?
  -                protocolCharset : defaultProtocolCharset);
  +        return (path == null) ? null : decode(path, getProtocolCharset());
       }
   
   
  @@ -3134,8 +3129,7 @@
       public String getName() throws URIException {
           char[] basename = getRawName();
           return (basename == null) ? null : decode(getRawName(),
  -                (protocolCharset != null) ? protocolCharset :
  -                defaultProtocolCharset);
  +                getProtocolCharset());
       }
   
       // ----------------------------------------------------- The path and query 
  @@ -3184,8 +3178,7 @@
       public String getPathQuery() throws URIException {
           char[] rawPathQuery = getRawPathQuery();
           return (rawPathQuery == null) ? null : decode(rawPathQuery,
  -                (protocolCharset != null) ? protocolCharset :
  -                defaultProtocolCharset);
  +                getProtocolCharset());
       }
   
       // -------------------------------------------------------------- The query 
  @@ -3252,8 +3245,7 @@
               setURI();
               return;
           }
  -        setRawQuery(encode(query, allowed_query, (protocolCharset != null) ?
  -                    protocolCharset : defaultProtocolCharset));
  +        setRawQuery(encode(query, allowed_query, getProtocolCharset()));
       }
   
   
  @@ -3286,9 +3278,7 @@
        * @see #decode
        */
       public String getQuery() throws URIException {
  -        return (_query == null) ? null : decode(_query,
  -                (protocolCharset != null) ? protocolCharset :
  -                defaultProtocolCharset);
  +        return (_query == null) ? null : decode(_query, getProtocolCharset());
       }
   
       // ----------------------------------------------------------- The fragment 
  @@ -3342,8 +3332,7 @@
               hash = 0;
               return;
           }
  -        _fragment = encode(fragment, allowed_fragment, (protocolCharset != null)
  -                ? protocolCharset : defaultProtocolCharset);
  +        _fragment = encode(fragment, allowed_fragment, getProtocolCharset());
           hash = 0;
       }
   
  @@ -3388,8 +3377,7 @@
        */
       public String getFragment() throws URIException {
           return (_fragment == null) ? null : decode(_fragment,
  -                (protocolCharset != null) ? protocolCharset :
  -                defaultProtocolCharset);
  +                getProtocolCharset());
       }
   
       // ------------------------------------------------------------- Utilities 
  @@ -3726,9 +3714,7 @@
        * @see #decode
        */
       public String getURI() throws URIException {
  -        return (_uri == null) ? null : decode(_uri,
  -                (protocolCharset != null) ? protocolCharset :
  -                defaultProtocolCharset);
  +        return (_uri == null) ? null : decode(_uri, getProtocolCharset());
       }
   
   
  @@ -3770,8 +3756,7 @@
       public String getURIReference() throws URIException {
           char[] uriReference = getRawURIReference();
           return (uriReference == null) ? null : decode(uriReference,
  -                (protocolCharset != null) ? protocolCharset :
  -                defaultProtocolCharset);
  +                getProtocolCharset());
       }
   
   
  
  
  
  1.11      +10 -18    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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- HttpURL.java	13 Feb 2003 05:08:18 -0000	1.10
  +++ HttpURL.java	17 Feb 2003 04:15:33 -0000	1.11
  @@ -530,8 +530,7 @@
       public void setUserinfo(String user, String password) 
           throws URIException, NullPointerException {
           // set the charset to do escape encoding
  -        String charset = (protocolCharset != null) ? protocolCharset :
  -            defaultProtocolCharset;
  +        String charset = getProtocolCharset();
           setRawUserinfo(encode(user, within_userinfo, charset),
                   (password == null) ? null :
                   encode(password, within_userinfo, charset));
  @@ -585,9 +584,7 @@
        * @throws NullPointerException null user
        */
       public void setUser(String user) throws URIException, NullPointerException {
  -        setRawUser(encode(user, allowed_within_userinfo,
  -                    (protocolCharset != null) ? protocolCharset :
  -                    defaultProtocolCharset));
  +        setRawUser(encode(user, allowed_within_userinfo, getProtocolCharset()));
       }
   
   
  @@ -630,8 +627,7 @@
        */
       public String getUser() throws URIException {
           char[] user = getRawUser();
  -        return (user == null) ? null : decode(user, (protocolCharset != null) ?
  -                protocolCharset : defaultProtocolCharset);
  +        return (user == null) ? null : decode(user, getProtocolCharset());
       }
   
   
  @@ -683,8 +679,7 @@
        */
       public void setPassword(String password) throws URIException {
           setRawPassword((password == null) ? null : encode(password,
  -                    allowed_within_userinfo, (protocolCharset != null) ?
  -                    protocolCharset : defaultProtocolCharset));
  +                    allowed_within_userinfo, getProtocolCharset()));
       }
   
   
  @@ -725,8 +720,7 @@
       public String getPassword() throws URIException {
           char[] password = getRawPassword();
           return (password == null) ? null : decode(password,
  -                (protocolCharset != null) ? protocolCharset :
  -                defaultProtocolCharset);
  +                getProtocolCharset());
       }
   
       // --------------------------------------------------------------- The path
  @@ -782,8 +776,7 @@
   
           StringBuffer buff = new StringBuffer();
           // set the charset to do escape encoding
  -        String charset = (protocolCharset != null) ? protocolCharset :
  -            defaultProtocolCharset;
  +        String charset = getProtocolCharset();
           buff.append(encode(queryName, allowed_within_query, charset));
           buff.append('=');
           buff.append(encode(queryValue, allowed_within_query, charset));
  @@ -812,8 +805,7 @@
   
           StringBuffer buff = new StringBuffer();
           // set the charset to do escape encoding
  -        String charset = (protocolCharset != null) ? protocolCharset :
  -            defaultProtocolCharset;
  +        String charset = getProtocolCharset();
           for (int i = 0; i < length; i++) {
               buff.append(encode(queryName[i], allowed_within_query, charset));
               buff.append('=');
  
  
  

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


Mime
View raw message