jericho     2002/07/06 19:22:18

  Modified:    src/util/org/apache/util URI.java
  Log:
  - Add the clone method...  and explain the reason...
  - Change the protected method, indexOf to indexFirstOf... for the clearness.
  
  Revision  Changes    Path
  1.9       +79 -25    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- URI.java  16 Jun 2002 16:46:31 -0000      1.8
  +++ URI.java  7 Jul 2002 02:22:18 -0000       1.9
  @@ -64,6 +64,7 @@
   package org.apache.util;
   
   import java.io.IOException;
  +import java.io.Serializable;
   import java.io.UnsupportedEncodingException;
   import java.util.BitSet;
   import java.security.AccessController;
  @@ -131,7 +132,7 @@
    * @version $Revision$ $Date: 2002/03/14 15:14:01 
    */
   
  -public class URI implements Comparable, java.io.Serializable {
  +public class URI implements Cloneable, Comparable, Serializable {
   
   
       // --------------------------------------------------------- Constructors
  @@ -1642,7 +1643,7 @@
            *  ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
            * </pre></blockquote><p>
            */
  -        int at = indexOf(tmp, ":/?#", from);
  +        int at = indexFirstOf(tmp, ":/?#", from);
           if (at == -1) {
               at = 0;
           }
  @@ -1684,7 +1685,7 @@
               _is_hier_part = true;
               if (at + 2 < length && tmp.charAt(at + 1) == '/') {
                   // the temporary index to start the search from
  -                int next = indexOf(tmp, "/?#", at + 2);
  +                int next = indexFirstOf(tmp, "/?#", at + 2);
                   if (next == -1) {
                       next = (tmp.substring(at + 2).length() == 0) ? at + 2 :
                       tmp.length();
  @@ -1707,10 +1708,9 @@
            *  ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
            * </pre></blockquote><p>
            */
  -        if (from < length) { // && tmp.charAt(from) != '?' &&
  -                // tmp.charAt(from) != '#') {
  +        if (from < length) {
               // rel_path = rel_segment [ abs_path ]
  -            int next = indexOf(tmp, "?#", from);
  +            int next = indexFirstOf(tmp, "?#", from);
               if (next == -1) {
                   next = tmp.length();
               }
  @@ -1777,28 +1777,28 @@
   
   
       /**
  -     * Get the earlier one among indexs that the characters as to be indexed
  -     * are from the given string.
  +     * Get the earlier index that to be searched for the first occurrance in
  +     * one of any of the given string.
        *
        * @param s the string to be indexed
        * @param delims the delimiters used to index
        * @return the earlier index if there are delimiters
        */
  -    protected int indexOf(String s, String delims) {
  -        return indexOf(s, delims, -1);
  +    protected int indexFirstOf(String s, String delims) {
  +        return indexFirstOf(s, delims, -1);
       }
   
   
       /**
  -     * Get the earlier one among indexs that the characters as to be indexed
  -     * are from the given string.
  +     * Get the earlier index that to be searched for the first occurrance in
  +     * one of any of the given string.
        *
        * @param s the string to be indexed
        * @param delims the delimiters used to index
        * @param offset the from index
        * @return the earlier index if there are delimiters
        */
  -    protected int indexOf(String s, String delims, int offset) {
  +    protected int indexFirstOf(String s, String delims, int offset) {
           if (s == null || s.length() == 0) {
               return -1;
           }
  @@ -1825,27 +1825,27 @@
   
   
       /**
  -     * Get the earlier index that the character as to be indexed is from the
  -     * given character array.
  +     * Get the earlier index that to be searched for the first occurrance in
  +     * one of any of the given array.
        *
        * @param s the character array to be indexed
        * @param delim the delimiter used to index
        * @return the ealier index if there are a delimiter
        */
  -    protected int indexOf(char[] s, char delim) {
  -        return indexOf(s, delim, 0);
  +    protected int indexFirstOf(char[] s, char delim) {
  +        return indexFirstOf(s, delim, 0);
       }
   
   
       /**
  -     * Get the earlier index that the character as to be indexed is from the
  -     * given character array.
  +     * Get the earlier index that to be searched for the first occurrance in
  +     * one of any of the given array.
        *
        * @param s the character array to be indexed
        * @param delim the delimiter used to index
        * @return the ealier index if there is a delimiter
        */
  -    protected int indexOf(char[] s, char delim, int offset) {
  +    protected int indexFirstOf(char[] s, char delim, int offset) {
           if (s == null || s.length == 0) {
               return -1;
           }
  @@ -3044,16 +3044,58 @@
        * Compare this URI to another object. 
        *
        * @param obj the object to be compared.
  -     * @return 0, if it's same
  +     * @return 0, if it's same,
  +     * -1, if failed, first being compared with in the authority component
        * @exception ClassCastException not URI argument
        * @exception NullPointerException character encoding error or null object
        */
       public int compareTo(Object obj) {
   
           URI another = (URI) obj;
  +        if (!equals(_authority, another.getRawAuthority())) return -1;
           return toString().compareTo(another.toString());
       }
   
  +    // ------------------------------------------------------------------ Clone
  +
  +    /**
  +     * Create and return a copy of this object.
  +     *
  +     * To copy the identical <code>URI</code> object including the userinfo
  +     * component, it should be used.
  +     *
  +     * @return a clone of this instance, null if it's failed to copy
  +     */
  +    public synchronized Object clone() {
  +
  +        URI instance = new URI();
  +
  +        instance._uri = _uri;
  +        instance._scheme = _scheme;
  +        instance._opaque = _opaque;
  +        instance._authority = _authority;
  +        instance._userinfo = _userinfo;
  +        instance._host = _host;
  +        instance._port = _port;
  +        instance._path = _path;
  +        instance._query = _query;
  +        instance._fragment = _fragment;
  +        // flags
  +        instance._is_hier_part = _is_hier_part;
  +        instance._is_opaque_part = _is_opaque_part;
  +        instance._is_net_path = _is_net_path;
  +        instance._is_abs_path = _is_abs_path;
  +        instance._is_rel_path = _is_rel_path;
  +        instance._is_reg_name = _is_reg_name;
  +        instance._is_server = _is_server;
  +        instance._is_hostname = _is_hostname;
  +        instance._is_IPv4address = _is_IPv4address;
  +        instance._is_IPv6reference = _is_IPv6reference;
  +        instance._is_only_fragment = _is_only_fragment;
  +
  +        return instance;
  +    }
  +
       // ------------------------------------------------------------ Get the URI
   
       /**
  @@ -3104,6 +3146,18 @@
   
       /**
        * Get the escaped URI string.
  +     *
  +     * On the document, the URI-reference form is only used without the userinfo
  +     * component like http://jakarta.apache.org/slide by the security reason.
  +     * But the user can specify and type the URI-reference form with the
  +     * userinfo component in the class.
  +     *
  +     * In other words, this URI and any its subclasses must not be exported the
  +     * URI-reference expression with the userinfo component like
  +     * http://user:password@hostport/restricted_zone.
  +     * It means that the API client programmer should extract each user and
  +     * password to access manually.  Probably it will be supported in the each
  +     * subclass, however, not a whole URI-reference expression.
        *
        * @return the escaped URI string
        */
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to