You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by je...@apache.org on 2002/09/29 11:13:12 UTC

cvs commit: jakarta-slide/src/util/org/apache/util URIException.java URI.java

jericho     2002/09/29 02:13:12

  Modified:    src/util/org/apache/util URIException.java URI.java
  Log:
  - (URI) Add a relative URI constructor as argument with URI and String
  - (URI) Fix a bug to parse a string including 'virtual http url addresses'.
  - (URI) Fix a wrong calculation about the getRawName method.
  - (URIException) Let the exception inherited from IOException.
  
  Revision  Changes    Path
  1.3       +18 -6     jakarta-slide/src/util/org/apache/util/URIException.java
  
  Index: URIException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/util/org/apache/util/URIException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- URIException.java	17 Aug 2002 08:54:12 -0000	1.2
  +++ URIException.java	29 Sep 2002 09:13:12 -0000	1.3
  @@ -63,16 +63,28 @@
   
   package org.apache.util;
   
  +import java.io.IOException;
  +
   /**
    * The URI parsing and escape encoding exception.
  + * <p>
  + * Why is it from IOException?
  + * To simplify the programming style for the inherited exception instances.
  + * <p>
    *
    * @author <a href="mailto:jericho at apache.org">Sung-Gu</a>
    * @version $Revision$ $Date: 2002/03/14 15:14:01 
    */
  -
  -public class URIException extends Exception {
  +public class URIException extends IOException {
   
       // ----------------------------------------------------------- constructors
  +
  +    /**
  +     * Default constructor.
  +     */
  +    public URIException() {
  +    }
  +
   
       /**
        * The constructor with a reason code argument.
  
  
  
  1.20      +32 -12    jakarta-slide/src/util/org/apache/util/URI.java
  
  Index: URI.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/util/org/apache/util/URI.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- URI.java	10 Sep 2002 22:41:09 -0000	1.19
  +++ URI.java	29 Sep 2002 09:13:12 -0000	1.20
  @@ -305,6 +305,18 @@
   
   
       /**
  +     * Construct a general URI with the given relative URI string.
  +     *
  +     * @param base the base URI
  +     * @param relative the relative URI string
  +     * @exception URIException
  +     */
  +    public URI(URI base, String relative) throws URIException {
  +        this(base, new URI(relative));
  +    }
  +
  +
  +    /**
        * Construct a general URI with the given relative URI.
        * <p><blockquote><pre>
        *   URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
  @@ -1634,15 +1646,23 @@
           int from = 0;
   
           /**
  +         * The test flag whether the URI is started from the path component.
  +         */
  +        boolean isStartedFromPath = false;
  +        int atColon = tmp.indexOf(':');
  +        int atSlash = tmp.indexOf('/');
  +        if (atColon < 0 || (atSlash >= 0 && atSlash < atColon)) {
  +            isStartedFromPath = true;
  +        }
  +
  +        /**
            * <p><blockquote><pre>
            *     @@@@@@@@
            *  ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
            * </pre></blockquote><p>
            */
  -        int at = indexFirstOf(tmp, ":/?#", from);
  -        if (at == -1) {
  -            at = 0;
  -        }
  +        int at = indexFirstOf(tmp, isStartedFromPath ? "/?#" : ":/?#", from);
  +        if (at == -1) at = 0;
   
           /**
            * The length of the sequence of characters.
  @@ -1657,7 +1677,7 @@
            *  ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
            * </pre></blockquote><p>
            */
  -        if (0 < at && at < length && tmp.charAt(at) == ':') {
  +        if (at < length && tmp.charAt(at) == ':') {
               char[] target = tmp.substring(0, at).toLowerCase().toCharArray();
               if (validate(target, scheme)) {
                   _scheme = target;
  @@ -2603,15 +2623,15 @@
           if (_path == null) return null;
   
           int at = 0;
  -        for (int i = _path.length - 1; i >= 0 ; i--) {
  +        for (int i = _path.length - 1; i >= 0; i--) {
               if (_path[i] == '/') {
  -                at = i;
  +                at = i + 1;
                   break;
               }
           }
           int len = _path.length - at;
           char[] basename =  new char[len];
  -        System.arraycopy(_path, at + 1, basename, 0, len);
  +        System.arraycopy(_path, at, basename, 0, len);
           return basename;
       }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>