You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ol...@apache.org on 2003/07/19 11:41:38 UTC

cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestURI.java

olegk       2003/07/19 02:41:38

  Modified:    httpclient/src/examples CustomHttpConnection.java
               httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java URI.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestURI.java
  Log:
  Bug fix #19618 (URI class constructors need revision, optimization)
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke & Laura Werner
  
  Revision  Changes    Path
  1.4       +4 -4      jakarta-commons/httpclient/src/examples/CustomHttpConnection.java
  
  Index: CustomHttpConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/CustomHttpConnection.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CustomHttpConnection.java	22 Apr 2003 18:11:01 -0000	1.3
  +++ CustomHttpConnection.java	19 Jul 2003 09:41:37 -0000	1.4
  @@ -89,7 +89,7 @@
               System.exit(1);
           }
   
  -        URI uri = new URI(args[0].toCharArray()); // i like this constructor :)
  +        URI uri = new URI(args[0], true);
   
           String schema = uri.getScheme();
           if ((schema == null) || (schema.equals("")))
  
  
  
  1.170     +6 -6      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.169
  retrieving revision 1.170
  diff -u -r1.169 -r1.170
  --- HttpMethodBase.java	16 Jul 2003 20:48:27 -0000	1.169
  +++ HttpMethodBase.java	19 Jul 2003 09:41:37 -0000	1.170
  @@ -266,7 +266,7 @@
               if (uri == null || uri.equals("")) {
                   uri = "/";
               }
  -            URI parsedURI = new URI(uri.toCharArray());
  +            URI parsedURI = new URI(uri, true);
               
               // only set the host if specified by the URI
               if (parsedURI.isAbsoluteURI()) {
  @@ -1120,7 +1120,7 @@
                   conn.getPort(), 
                   this.getPath()
               );
  -            redirectUri = new URI(location.toCharArray());
  +            redirectUri = new URI(location, true);
               if (redirectUri.isRelativeURI()) {
                   if (isStrictMode()) {
                       LOG.warn("Redirected location '" + location 
  
  
  
  1.39      +66 -4     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.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- URI.java	11 Jul 2003 21:55:09 -0000	1.38
  +++ URI.java	19 Jul 2003 09:41:38 -0000	1.39
  @@ -154,6 +154,43 @@
       protected URI() {
       }
   
  +    /**
  +     * Construct a URI from a string with the given charset. The input string can 
  +     * be either in escaped or unescaped form. 
  +     *
  +     * @param s URI character sequence
  +     * @param escaped <tt>true</tt> if URI character sequence is in escaped form. 
  +     *                <tt>false</tt> otherwise. 
  +     * @param charset the charset string to do escape encoding, if required
  +     * 
  +     * @throws URIException If the URI cannot be created.
  +     * @throws NullPointerException if input string is <code>null</code>
  +     * 
  +     * @see #getProtocolCharset
  +     */
  +    public URI(String s, boolean escaped, String charset)
  +        throws URIException, NullPointerException {
  +        protocolCharset = charset;
  +        parseUriReference(s, escaped);
  +    }
  +
  +    /**
  +     * Construct a URI from a string with the given charset. The input string can 
  +     * be either in escaped or unescaped form. 
  +     *
  +     * @param s URI character sequence
  +     * @param escaped <tt>true</tt> if URI character sequence is in escaped form. 
  +     *                <tt>false</tt> otherwise. 
  +     * 
  +     * @throws URIException If the URI cannot be created.
  +     * @throws NullPointerException if input string is <code>null</code>
  +     * 
  +     * @see #getProtocolCharset
  +     */
  +    public URI(String s, boolean escaped)
  +        throws URIException, NullPointerException {
  +        parseUriReference(s, escaped);
  +    }
   
       /**
        * Construct a URI as an escaped form of a character array with the given
  @@ -164,6 +201,8 @@
        * @throws URIException If the URI cannot be created.
        * @throws NullPointerException if <code>escaped</code> is <code>null</code>
        * @see #getProtocolCharset
  +     * 
  +     * @deprecated Use #URI(String, boolean, String)
        */
       public URI(char[] escaped, String charset) 
           throws URIException, NullPointerException {
  @@ -181,6 +220,8 @@
        * @throws URIException If the URI cannot be created.
        * @throws NullPointerException if <code>escaped</code> is <code>null</code>
        * @see #getDefaultProtocolCharset
  +     * 
  +     * @deprecated Use #URI(String, boolean)
        */
       public URI(char[] escaped) 
           throws URIException, NullPointerException {
  @@ -196,6 +237,8 @@
        * @param charset the charset string to do escape encoding
        * @throws URIException If the URI cannot be created.
        * @see #getProtocolCharset
  +     * 
  +     * @deprecated Use #URI(String, boolean, String)
        */
       public URI(String original, String charset) throws URIException {
           protocolCharset = charset;
  @@ -215,6 +258,8 @@
        * It is one of absoluteURI and relativeURI.
        * @throws URIException If the URI cannot be created.
        * @see #getDefaultProtocolCharset
  +     * 
  +     * @deprecated Use #URI(String, boolean)
        */
       public URI(String original) throws URIException {
           parseUriReference(original, false);
  @@ -412,9 +457,26 @@
        * @param base the base URI
        * @param relative the relative URI string
        * @throws URIException If the new URI cannot be created.
  +     * 
  +     * @deprecated Use #URI(URI, String, boolean)
        */
       public URI(URI base, String relative) throws URIException {
           this(base, new URI(relative));
  +    }
  +
  +
  +    /**
  +     * Construct a general URI with the given relative URI string.
  +     *
  +     * @param base the base URI
  +     * @param relative the relative URI string
  +     * @param escaped <tt>true</tt> if URI character sequence is in escaped form. 
  +     *                <tt>false</tt> otherwise.
  +     *  
  +     * @throws URIException If the new URI cannot be created.
  +     */
  +    public URI(URI base, String relative, boolean escaped) throws URIException {
  +        this(base, new URI(relative, escaped));
       }
   
   
  
  
  
  1.5       +5 -5      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestURI.java
  
  Index: TestURI.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestURI.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestURI.java	19 Jun 2003 23:28:20 -0000	1.4
  +++ TestURI.java	19 Jul 2003 09:41:38 -0000	1.5
  @@ -96,7 +96,7 @@
           URI baseURI = null;
           
           try {
  -            baseURI = new URI( "http://a/b/c/d;p?q" );
  +            baseURI = new URI("http://a/b/c/d;p?q", false);
           } catch ( URIException e ) {
               fail( "unable to create base URI: " + e );
           }
  @@ -153,7 +153,7 @@
               URI testURI = null;
               
               try {
  -                testURI = new URI( baseURI, testRelativeURIs[i][0] );
  +                testURI = new URI( baseURI, testRelativeURIs[i][0], false );
               } catch ( URIException e ) {
                   e.printStackTrace();
                   fail( 
  
  
  

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


Re: Philasophy of URI? - Re: cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestURI.java

Posted by Sung-Gu <je...@apache.org>.
Ok, I'll say you're not gonna use char type as external interfaces...
It's not confined in constructors only...methods with  char type arguments
and other classes like HttpURL...
(Actually, I think you should be interested in HttpURL... not only URI, I believe)

Please, take care of them also with consistency...

Take care,

Sung-Gu

Philasophy of URI? - Re: cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestURI.java

Posted by Sung-Gu <je...@apache.org>.
I think you should not deprecate previous constructors.
And actually no reason to be deprecated as I see.


And about String boolean constructors,
1. JUST CONVENIENCE:
that's ok though... you'd better clear up some comments on the top of the class usage as I see.


2. FOR REVOLUTION: 
when you're not gonna distiguish empty and undefiled components of URI,
you should modify the all URI documents related that... 
uri string sequences and internal escpaed sequence are distinguished internally...
That's why char and String type is distiguished in the class... 
java.net.URL and java.net.URI are restricted to implment that... 


Sung-Gu


----- Original Message ----- 
From: <ol...@apache.org>


>        /**
>         * Construct a URI as an escaped form of a character array with the given
>   @@ -164,6 +201,8 @@
>         * @throws URIException If the URI cannot be created.
>         * @throws NullPointerException if <code>escaped</code> is <code>null</code>
>         * @see #getProtocolCharset
>   +     * 
>   +     * @deprecated Use #URI(String, boolean, String)
>         */
>        public URI(char[] escaped, String charset) 
>            throws URIException, NullPointerException {
>   @@ -181,6 +220,8 @@
>         * @throws URIException If the URI cannot be created.
>         * @throws NullPointerException if <code>escaped</code> is <code>null</code>
>         * @see #getDefaultProtocolCharset
>   +     * 
>   +     * @deprecated Use #URI(String, boolean)
>         */
>        public URI(char[] escaped) 
>            throws URIException, NullPointerException {
>   @@ -196,6 +237,8 @@
>         * @param charset the charset string to do escape encoding
>         * @throws URIException If the URI cannot be created.
>         * @see #getProtocolCharset
>   +     * 
>   +     * @deprecated Use #URI(String, boolean, String)
>         */
>        public URI(String original, String charset) throws URIException {
>            protocolCharset = charset;
>   @@ -215,6 +258,8 @@
>         * It is one of absoluteURI and relativeURI.
>         * @throws URIException If the URI cannot be created.
>         * @see #getDefaultProtocolCharset
>   +     * 
>   +     * @deprecated Use #URI(String, boolean)
>         */
>        public URI(String original) throws URIException {
>            parseUriReference(original, false);
>   @@ -412,9 +457,26 @@
>         * @param base the base URI
>         * @param relative the relative URI string
>         * @throws URIException If the new URI cannot be created.
>   +     * 
>   +     * @deprecated Use #URI(URI, String, boolean)
>         */
>        public URI(URI base, String relative) throws URIException {
>            this(base, new URI(relative));
>   +    }
>   +
>   +
>   +    /**
>   +     * Construct a general URI with the given relative URI string.
>   +     *
>   +     * @param base the base URI
>   +     * @param relative the relative URI string
>   +     * @param escaped <tt>true</tt> if URI character sequence is in escaped form. 
>   +     *                <tt>false</tt> otherwise.
>   +     *  
>   +     * @throws URIException If the new URI cannot be created.
>   +     */
>   +    public URI(URI base, String relative, boolean escaped) throws URIException {
>   +        this(base, new URI(relative, escaped));
>        }