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
Date Tue, 29 Oct 2002 16:22:21 GMT
jericho     2002/10/29 08:22:20

  Modified:    httpclient/src/java/org/apache/commons/httpclient URI.java
  Log:
  - Support URI constructors being placed within double-quotes or angle
     brackets like "http://test.com/" and <http://test.com/>
  - Fix a bug of offset range computation
  - Fix to set query without path
  - Add and fix javadoc messages
  - Remove tab
  
  Revision  Changes    Path
  1.12      +47 -28    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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- URI.java	29 Oct 2002 13:52:09 -0000	1.11
  +++ URI.java	29 Oct 2002 16:22:19 -0000	1.12
  @@ -156,7 +156,9 @@
   
       /**
        * Construct a URI as an escaped form of a character array.
  -     *
  +     * An URI can be placed within double-quotes or angle brackets like 
  +     * "http://test.com/" and &lt;http://test.com/&gt;
  +     * 
        * @param escaped the URI character sequence
        * @exception URIException
        * @throws NullPointerException if <code>escaped</code> is <code>null</code>
  @@ -171,6 +173,8 @@
        * <p><blockquote><pre>
        *   URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
        * </pre></blockquote><p>
  +     * An URI can be placed within double-quotes or angle brackets like 
  +     * "http://test.com/" and &lt;http://test.com/&gt;
        *
        * @param original the string to be represented to URI character sequence
        * It is one of absoluteURI and relativeURI.
  @@ -188,7 +192,8 @@
        *   absoluteURI   = scheme ":" ( hier_part | opaque_part )
        *   opaque_part   = uric_no_slash *uric
        * </pre></blockquote><p>
  -     * It's for absolute URI = <scheme>:<scheme-specific-part>#<fragment>
  +     * It's for absolute URI = &lt;scheme&gt;:&lt;scheme-specific-part&gt;#
  +     * &lt;fragment&gt;.
        *
        * @param scheme the scheme string
        * @param scheme_specific_part scheme_specific_part
  @@ -223,8 +228,9 @@
        *   relativeURI   = ( net_path | abs_path | rel_path ) [ "?" query ]
        *   hier_part     = ( net_path | abs_path ) [ "?" query ]
        * </pre></blockquote><p>
  -     * It's for absolute URI = <scheme>:<path>?<query>#<fragment>
and
  -     * relative URI = <path>?<query>#<fragment>
  +     * It's for absolute URI = &lt;scheme&gt;:&lt;path&gt;?&lt;query&gt;#&lt;
  +     * fragment&gt; and relative URI = &lt;path&gt;?&lt;query&gt;#&lt;fragment
  +     * &gt;.
        *
        * @param scheme the scheme string
        * @param authority the authority string
  @@ -1707,6 +1713,7 @@
        * if -1, it means the length of the component
        * @param generous those characters that are allowed within a component
        * @return if true, it's the correct URI character sequence
  +     * @throws NullPointerException null component
        */
       protected boolean validate(char[] component, int soffset, int eoffset,
               BitSet generous) {
  @@ -1714,9 +1721,8 @@
           if (eoffset == -1) {
               eoffset = component.length -1;
           }
  -        for (int i = soffset; i < eoffset; i++) {
  -            if (!generous.get(component[i]))
  -                return false;
  +        for (int i = soffset; i <= eoffset; i++) {
  +            if (!generous.get(component[i])) return false;
           }
           return true;
       }
  @@ -1757,7 +1763,7 @@
           throws URIException {
   
           // validate and contruct the URI character sequence
  -        if (original == null) {
  +        if (original == null || original.length() == 0) {
               throw new URIException("URI-Reference required");
           }
   
  @@ -1765,6 +1771,26 @@
            *  ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
            */
           String tmp = original.trim();
  +        
  +        /**
  +         * The length of the string sequence of characters.
  +         * It may not be equal to the length of the byte array.
  +         */
  +        int length = tmp.length();
  +
  +        /**
  +         * Remove the delimiters like angle brackets around an URI.
  +         */
  +        char[] firstDelimiter = { tmp.charAt(0) };
  +        if (validate(firstDelimiter, delims)) {
  +            if (length >= 2) {
  +                char[] lastDelimiter = { tmp.charAt(length - 1) };
  +                if (validate(lastDelimiter, delims)) {
  +                    tmp = original.substring(1, length - 1);
  +                    length = length - 2;
  +                }
  +            }
  +        }
   
           /**
            * The starting index
  @@ -1782,7 +1808,6 @@
           }
   
           /**
  -	 * Find @ symbol.
            * <p><blockquote><pre>
            *     @@@@@@@@
            *  ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
  @@ -1792,13 +1817,7 @@
           if (at == -1) at = 0;
   
           /**
  -         * The length of the sequence of characters.
  -         * It may not be equal to the length of the byte array.
  -         */
  -        int length = tmp.length();
  -
  -        /**
  -	 * Find scheme.
  +         * Parse the scheme.
            * <p><blockquote><pre>
            *  scheme    =  $2 = http
            *              @
  @@ -1816,7 +1835,7 @@
           }
   
           /**
  -	 * Find authority.
  +         * Parse the authority component.
            * <p><blockquote><pre>
            *  authority =  $4 = jakarta.apache.org
            *                  @@
  @@ -1847,7 +1866,7 @@
           }
   
           /**
  -	 * Find path.
  +         * Parse the path component.
            * <p><blockquote><pre>
            *  path      =  $5 = /ietf/uri/
            *                                @@@@@@
  @@ -1883,7 +1902,7 @@
           }
   
           /**
  -	 * Find query.
  +         * Parse the query component.
            * <p><blockquote><pre>
            *  query     =  $7 = <undefined>
            *                                        @@@@@@@@@
  @@ -1901,7 +1920,7 @@
           }
   
           /**
  -	 * Find fragment.
  +         * Parse the fragment component.
            * <p><blockquote><pre>
            *  fragment  =  $9 = Related
            *                                                   @@@@@@@@
  @@ -2135,10 +2154,10 @@
               if (_path.length != 0) {
                   buf.append(_path);
               }
  -            if (_query != null) { // has_query
  -                buf.append('?');
  -                buf.append(_query);
  -            }
  +        }
  +        if (_query != null) { // has_query
  +            buf.append('?');
  +            buf.append(_query);
           }
           if (_fragment != null) { // has_fragment
               buf.append('#');
  
  
  

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


Mime
View raw message