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 2001/04/26 15:08:37 UTC

cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/util GenericURI.java HttpURL.java

jericho     01/04/26 06:08:37

  Modified:    src/webdav/client/src/org/apache/webdav/util GenericURI.java
                        HttpURL.java
  Log:
  - Keep in step with URIUtil class.
  - Add useful constructors in HttpURL.
  
  Revision  Changes    Path
  1.17      +427 -103  jakarta-slide/src/webdav/client/src/org/apache/webdav/util/GenericURI.java
  
  Index: GenericURI.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/GenericURI.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- GenericURI.java	2001/04/16 02:27:14	1.16
  +++ GenericURI.java	2001/04/26 13:08:33	1.17
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/GenericURI.java,v 1.16 2001/04/16 02:27:14 jericho Exp $
  - * $Revision: 1.16 $
  - * $Date: 2001/04/16 02:27:14 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/GenericURI.java,v 1.17 2001/04/26 13:08:33 jericho Exp $
  + * $Revision: 1.17 $
  + * $Date: 2001/04/26 13:08:33 $
    *
    * ====================================================================
    *
  @@ -66,9 +66,11 @@
   import java.net.MalformedURLException;
   
   /**
  - * URI (Uniform Resource Identifiers), RFC 2396.
  - * This is the generic URI version.
  + * This is the generic URI(Uniform Resource Identifiers) version of RFC 2396.
    *
  + * Generic-URI =
  + *    scheme ":" [ "//" server ] [ "/" ] [ path_segments ] [ "?" query ]
  + *
    * It's assumed that URI is escaped by URI encoding and processed.
    * Care should be taken when a URL contains escaped delimiters for a
    * given protocol that these are not unescaped before transmission.
  @@ -92,65 +94,97 @@
        */
       public GenericURI(String escapedURI) {
   
  -        if (escapedURI.indexOf("://") > 0)
  -            this.URI = escapedURI;
  -        else
  -            this.URI = getDefaultScheme() + "://"+ escapedURI;
  +        URI = (escapedURI.indexOf("://") > 0) ? escapedURI :
  +            getDefaultScheme() + "://" + escapedURI;
       }
   
   
       /**
        * This Constructor
        *
  -     * @param scheme The escaped scheme string.
  -     * @param authority The escaped authority string.
  -     * @param path The escaped path string.
  +     * @param scheme The scheme string.
  +     * @param escapedAuthority The escaped authority string.
  +     * @param path The path string.
        */
  -    public GenericURI(String scheme, String authority, String path) {
  +    public GenericURI(String scheme, String escapedAuthority, String path) {
   
           if (!path.startsWith("/"))
               path = "/" + path;
  -        URI = scheme + "://" + authority + path;
  +        URI = URIUtil.escape(scheme, URIUtil.schemeReserved()) + "://" +
  +            URIUtil.escape(escapedAuthority, URIUtil.authorityReserved())+
  +            URIUtil.escape(path, URIUtil.pathReserved());
       }
   
   
       /**
        * This Constructor
        *
  -     * @param scheme The escaped scheme string.
  -     * @param host The escaped host string.
  -     * @param port The escaped port number.
  -     * @param path The escaped path string.
  +     * @param scheme The scheme string.
  +     * @param host The host string.
  +     * @param port The port number.
  +     * @param path The path string.
        */
       public GenericURI(String scheme, String host, int port, String path) {
   
           if (!path.startsWith("/"))
               path = "/" + path;
  -        URI = (port == defaultPort) ? scheme + "://" + host + path :
  -            scheme + "://" + host + ":" + port + path;
  +        URI = URIUtil.escape(scheme, URIUtil.schemeReserved()) + "://" +
  +            URIUtil.escape(host, URIUtil.hostReserved()) +
  +            ((port == defaultPort) ? "" : ":" + port) +
  +            URIUtil.escape(path, URIUtil.pathReserved());
       }
   
   
       /**
        * This Constructor
        *
  -     * @param scheme The escaped scheme string.
  -     * @param host The escaped host string.
  -     * @param port The escaped port number.
  -     * @param path The escaped path string.
  -     * @param query The escaped query string.
  +     * @param scheme The scheme string.
  +     * @param host The host string.
  +     * @param port The port number.
  +     * @param path The path string.
  +     * @param query The query string.
        */
       public GenericURI(String scheme, String host, int port, String path,
                         String query) {
   
           if (!path.startsWith("/"))
               path = "/" + path;
  -        URI = (port == defaultPort) ?
  -            scheme + "://" + host + path + "?" + query :
  -            scheme + "://" + host + ":" + port + path + "?" + query;
  +        URI = URIUtil.escape(scheme, URIUtil.schemeReserved()) + "://" +
  +            URIUtil.escape(host, URIUtil.hostReserved()) +
  +            ((port == defaultPort) ? "" : ":" + port) +
  +            URIUtil.escape(path, URIUtil.pathReserved()) + "?" +
  +            URIUtil.escape(query, URIUtil.queryReserved());
       }
   
   
  +    /**
  +     * This Constructor
  +     *
  +     * @param scheme The scheme string.
  +     * @param userName The username string.
  +     * @param password The password string.
  +     * @param host The host string.
  +     * @param port The port number.
  +     * @param path The path string.
  +     * @param query The query string.
  +     */
  +    public GenericURI(String scheme, String userName, String password,
  +                      String host, int port, String path, String query) {
  +        
  +        if (!path.startsWith("/"))
  +            path = "/" + path;
  +        URI = URIUtil.escape(scheme, URIUtil.schemeReserved()) + "://" +
  +            ((userName == null) ? "" :
  +             URIUtil.escape(userName) + ((password == null) ? "" :
  +                                         ":" + URIUtil.escape(password))
  +             + "@") +
  +            URIUtil.escape(host, URIUtil.hostReserved()) +
  +            ((port == defaultPort) ? "" : ":" + port) +
  +            URIUtil.escape(path, URIUtil.pathReserved()) + "?" +
  +            URIUtil.escape(query, URIUtil.queryReserved());
  +    }
  +
  +
       // --------------------------------------------------- Instance Variables
   
   
  @@ -167,7 +201,7 @@
        *
        * @see #setDefaultScheme(java.lang.String)
        */
  -    private static String defaultScheme = null;
  +    private String defaultScheme = null;
   
   
       /**
  @@ -176,29 +210,38 @@
        *
        * @see #setDefaultPort(int)
        */
  -    private static int defaultPort = -1;
  +    private int defaultPort = -1;
   
   
       // ----------------------------------------------------------- Properties
   
   
       /**
  -     * Get the unescaped URI string.
  +     * Get the escaped URI string.
        */
  -    public String getUnscapedURI() {
  -        // TODO: return the unescaped URI string by URI encoding.
  +    public String getEscapedURI() {
           return URI;
       }
   
   
       /**
  -     * Get the escaped URI string.
  +     * Get the URI string.
        */
       public String getURI() {
  -        return URI;
  +        return URIUtil.unescape(URI);
       }
   
   
  +    /**
  +     * This is an wrapper method for java.net.URL
  +     *
  +     * @return The external form of this URI.
  +     */
  +    public String toExternalForm() {
  +        return getEscapedURI();
  +    }
  +
  +
       // ---------------------------------------------------  Protected methods
   
   
  @@ -254,38 +297,84 @@
       }
   
   
  +
  +    /**
  +     * Get the escaped scheme for this Generic URI.
  +     *
  +     * @return The escaped scheme for this Generic URI.
  +     * @exception MalformedURLException no scheme.
  +     */
  +    public String getEscapedScheme()
  +        throws MalformedURLException {
  +
  +        return getEscapedScheme(URI);
  +    }
  +
  +
       /**
        * Get the scheme of the given URI string.
        *
  -     * @param URI The URI string to get the scheme.
  +     * @param escapedURI The escaped URI string to get the scheme.
        * @return The scheme of the given URI.
        * @exception MalformedURLException no scheme.
        */
  -    public static String getScheme(String URI)
  +    public String getScheme(String escapedURI)
           throws MalformedURLException {
   
  -        return getScheme(URI, defaultScheme);
  +        return getScheme(escapedURI, defaultScheme);
       }
   
   
       /**
  +     * Get the escaped scheme of the given URI string.
  +     *
  +     * @param  escapedURI The escaped URI string to get the scheme.
  +     * @return The escaped scheme of the given URI.
  +     * @exception MalformedURLException no scheme.
  +     */
  +    public String getEscapedScheme(String escapedURI)
  +        throws MalformedURLException {
  +
  +        return getEscapedScheme(escapedURI, defaultScheme);
  +    }
  +
  +
  +    /**
        * Get the scheme of the given URI string.
        *
  -     * @param URI The URI string to get the scheme.
  +     * @param escapedURI The URI string to get the scheme.
        * @param defaultScheme The scheme to set.
        * @return The scheme of the given URI.
        * @exception MalformedURLException no scheme.
  +     */
  +    public static String getScheme(String escapedURI,
  +                                   String defaultScheme)
  +        throws MalformedURLException {
  +
  +        return URIUtil.unescape(getEscapedScheme(escapedURI, defaultScheme));
  +    }
  +    
  +    
  +    /**
  +     * Get the escaped scheme of the given URI string.
  +     *
  +     * @param escapedURI The URI string to get the scheme.
  +     * @param defaultScheme The scheme to set.
  +     * @return The escaped scheme of the given URI.
  +     * @exception MalformedURLException no scheme.
        */
  -    public static String getScheme(String URI, String defaultScheme)
  +    public static synchronized String getEscapedScheme(String escapedURI,
  +                                                       String defaultScheme)
           throws MalformedURLException {
   
  -        int at = URI.indexOf("://");
  +        int at = escapedURI.indexOf("://");
           if (at > 0)
  -            return URI.substring(0, at);
  +            return escapedURI.substring(0, at);
   
           // Check the default.
           if (defaultScheme == null)
  -            throw new MalformedURLException("No default scheme: " + URI);
  +            throw new MalformedURLException("No default scheme: "
  +                                            + escapedURI);
   
           return defaultScheme;
       }
  @@ -305,6 +394,19 @@
   
   
       /**
  +     * Get the escaped authority part for this generic URI.
  +     *
  +     * @return The escaped authority part of this generic URI.
  +     * @exception MalformedURLException
  +     */
  +    public String getEscapedAuthority()
  +        throws MalformedURLException {
  +
  +        return getEscapedAuthority(URI);
  +    }
  +
  +
  +    /**
        * Get the authority part of the given escaped URI string.
        *
        * @param escapedURI The escaped URI string to get the authority part.
  @@ -314,6 +416,20 @@
       public static String getAuthority(String escapedURI)
           throws MalformedURLException {
   
  +        return URIUtil.unescape(getEscapedAuthority(escapedURI));
  +    }
  +
  +
  +    /**
  +     * Get the escaped authority part of the given escaped URI string.
  +     *
  +     * @param escapedURI The escaped URI string to get the authority part.
  +     * @return The escaped authority part of the given URI.
  +     * @exception MalformedURLException
  +     */
  +    public static synchronized String getEscapedAuthority(String escapedURI)
  +        throws MalformedURLException {
  +
           int at = escapedURI.indexOf("://");
           if (at > 0) {
               int from = at + 3;
  @@ -340,6 +456,19 @@
   
   
       /**
  +     * Get the escaped userinfo part for this generic URI.
  +     *
  +     * @return The escaped userifno of this generic URI.
  +     * @exception MalformedURLException
  +     */
  +    public String getEscapedUserInfo()
  +        throws MalformedURLException {
  +
  +        return getEscapedUserInfo(URI);
  +    }
  +
  +
  +    /**
        * Get the userinfo part of the given escaped URI string.
        *
        * @param escapedURI The escaped URI string to get the userinfo part.
  @@ -348,8 +477,22 @@
        */
       public static String getUserInfo(String escapedURI)
           throws MalformedURLException {
  +
  +        return URIUtil.unescape(getEscapedUserInfo(escapedURI));
  +    }
  +
  +
  +    /**
  +     * Get the escaped userinfo part of the given escaped URI string.
  +     *
  +     * @param escapedURI The escaped URI string to get the userinfo part.
  +     * @return The userifno of the given URI.
  +     * @exception MalformedURLException
  +     */
  +    public static synchronized String getEscapedUserInfo(String escapedURI)
  +        throws MalformedURLException {
   
  -        String authority = getAuthority(escapedURI);
  +        String authority = getEscapedAuthority(escapedURI);
           int to = authority.indexOf("@");
   
           return (to > 0) ? authority.substring(0, to) : null;
  @@ -359,19 +502,19 @@
       /**
        * Set the username and password for this URI.
        *
  -     * @param userName The escaped username string.
  -     * @param password The escaped password string.
  +     * @param userName The username string.
  +     * @param password The password string.
        * @exception MalformedURLException
        */
       public void setUserInfo(String userName, String password)
           throws MalformedURLException {
  -
  -        // TODO: save the username and passsowrd by URI encoding.
   
  -        URI = getScheme() + "://" +
  -            ((userName != null) ?
  -             userName + ((password != null) ?  ":" + password : "") + "@" : "")
  -            + getHostPort() + getPathQuery();
  +        URI = getEscapedScheme() + "://" +
  +            ((userName == null) ? "" :
  +             URIUtil.escape(userName) + ((password == null) ? "" :
  +                                         ":" + URIUtil.escape(password))
  +             + "@")
  +            + getEscapedHostPort() + getEscapedPathQuery();
       }
   
   
  @@ -392,18 +535,19 @@
       /**
        * Get the username on the userinfo of the given URI string.
        *
  -     * @param escapedURI the escaped URI string to get the username.
  +     * @param escapedURI The escaped URI string to get the username.
        * @return The username of URI
        * @exception MalformedURLException
        */
  -    public static String getUserName(String escapedURI)
  +    public static synchronized String getUserName(String escapedURI)
           throws MalformedURLException {
   
           try {
  -            String userInfo = getUserInfo(escapedURI);
  +            String userInfo = getEscapedUserInfo(escapedURI);
               int to = userInfo.indexOf(":");
   
  -            return (to > 0) ? userInfo.substring(0, to) : userInfo;
  +            String username = (to > 0) ? userInfo.substring(0, to) : userInfo;
  +            return URIUtil.unescape(username);
           } catch (NullPointerException npe) {
               // No userinfo
               return null;
  @@ -431,14 +575,15 @@
        * @return The password of URI
        * @exception MalformedURLException
        */
  -    public static String getPassword(String escapedURI)
  +    public static synchronized String getPassword(String escapedURI)
           throws MalformedURLException {
   
           try {
  -            String userInfo = getUserInfo(escapedURI);
  +            String userInfo = getEscapedUserInfo(escapedURI);
               int at = userInfo.indexOf(":");
   
  -            return (at >= 0) ? userInfo.substring(at + 1) : null;
  +            String password = (at >= 0) ? userInfo.substring(at + 1) : null;
  +            return URIUtil.unescape(password);
           } catch (NullPointerException npe) {
               // No userinfo
               return null;
  @@ -460,6 +605,19 @@
   
   
       /**
  +     * Get the escaped hostport part for this generic URI.
  +     *
  +     * @return The escaped hostport string
  +     * @exception MalformedURLException
  +     */
  +    public String getEscapedHostPort()
  +        throws MalformedURLException {
  +
  +        return getEscapedHostPort(URI);
  +    }
  +
  +
  +    /**
        * Get the hostport part of the given URI string.
        *
        * @param escapedURI The escaped URI string to get the hostport part.
  @@ -468,8 +626,22 @@
        */
       public static String getHostPort(String escapedURI)
           throws MalformedURLException {
  +
  +        return URIUtil.unescape(getEscapedHostPort(escapedURI));
  +    }
  +
  +
  +    /**
  +     * Get the escaped hostport part of the given URI string.
  +     *
  +     * @param escapedURI The escaped URI string to get the hostport part.
  +     * @return The hostport
  +     * @exception MalformedURLException
  +     */
  +    public static synchronized String getEscapedHostPort(String escapedURI)
  +        throws MalformedURLException {
   
  -        String authority = getAuthority(escapedURI);
  +        String authority = getEscapedAuthority(escapedURI);
           int at = authority.indexOf("@");
   
           return (at > 0) ? authority.substring(at + 1) : authority;
  @@ -490,6 +662,19 @@
   
   
       /**
  +     * Get the escaped hostname for this generic URI.
  +     *
  +     * @return The escaped hostname string
  +     * @exception MalformedURLException
  +     */
  +    public String getEscapedHost()
  +        throws MalformedURLException {
  +
  +        return getEscapedHost(URI);
  +    }
  +
  +
  +    /**
        * Get the hostname of the given URI string.
        *
        * @param escapedURI The escaped URI string to get the hostname.
  @@ -498,13 +683,25 @@
        */
       public static String getHost(String escapedURI)
           throws MalformedURLException {
  +
  +        return URIUtil.unescape(getEscapedHost(escapedURI));
  +    }
  +
  +
  +    /**
  +     * Get the escaped hostname of the given URI string.
  +     *
  +     * @param escapedURI The escaped URI string to get the hostname.
  +     * @return The escaped hostname string
  +     * @exception MalformedURLException
  +     */
  +    public static synchronized String getEscapedHost(String escapedURI)
  +        throws MalformedURLException {
   
  -        String hostPort = getHostPort(escapedURI);
  +        String hostPort = getEscapedHostPort(escapedURI);
           int to = hostPort.indexOf(":");
  -        if (to > 0)
  -            return hostPort.substring(0, to);
  -        else
  -            return hostPort;
  +
  +        return (to > 0) ? hostPort.substring(0, to) : hostPort;
       }
   
   
  @@ -528,7 +725,7 @@
        * @return The port number
        * @exception MalformedURLException
        */
  -    public static int getPort(String escapedURI)
  +    public int getPort(String escapedURI)
           throws MalformedURLException {
   
           return getPort(escapedURI, defaultPort);
  @@ -538,18 +735,18 @@
       /**
        * Get the port number of the given URI string.
        *
  -     * @param escapedURI the escaped URI string to get the port number.
  -     * @param defaultPort the default port for the given URI.
  +     * @param escapedURI The escaped URI string to get the port number.
  +     * @param defaultPort The default port for the given URI.
        * @return The port number
        * @exception MalformedURLException
        */
  -    public static int getPort(String escapedURI, int defaultPort)
  +    public static synchronized int getPort(String escapedURI, int defaultPort)
           throws MalformedURLException {
   
  -        String hostPort = getHostPort(escapedURI);
  +        String hostPort = getEscapedHostPort(escapedURI);
           int at = hostPort.indexOf(":");
           if (at > 0) {
  -            String port = hostPort.substring(at + 1);
  +            String port = URIUtil.unescape(hostPort.substring(at + 1));
               try {
                   // Support the form like http://thinkfree.com:/~jericho
                   return port.equals("") ? defaultPort : Integer.parseInt(port);
  @@ -571,10 +768,21 @@
        * Get the net_path and query of the given escaped URI string.
        * The methods returns the net_loc and abs_path.
        *
  -     * @return the nel_path and query.
  +     * @return The net_path and query.
        */
       public String getNetPathQuery() {
  -        return getNetPathQuery(URI.toString());
  +        return getNetPathQuery(URI);
  +    }
  +
  +
  +    /**
  +     * Get the escaped net_path and query of the given escaped URI string.
  +     * The methods returns the net_loc and abs_path.
  +     *
  +     * @return The escaped net_path and query.
  +     */
  +    public String getEscapedNetPathQuery() {
  +        return getEscapedNetPathQuery(URI);
       }
   
   
  @@ -582,10 +790,24 @@
        * Get the net_path and query of the given escaped URI string.
        * The methods returns the net_loc and abs_path.
        *
  -     * @param escapedURI the specified URI string.
  -     * @return the net_path and query.
  +     * @param escapedURI The escaped URI string.
  +     * @return The net_path and query.
        */
       public static String getNetPathQuery(String escapedURI) {
  +        return URIUtil.unescape(getEscapedNetPathQuery(escapedURI));
  +    }
  +
  +
  +    /**
  +     * Get the net_path and query of the given escaped URI string.
  +     * The methods returns the net_loc and abs_path.
  +     *
  +     * @param escapedURI The escaped URI string.
  +     * @return The escaped net_path and query.
  +     */
  +    public static synchronized String getEscapedNetPathQuery
  +        (String escapedURI) {
  +
           // consider of net_path
           int from = escapedURI.indexOf("//");
           // Ignore the authority part of URI
  @@ -595,9 +817,7 @@
           if (escapedURI.indexOf("#") > from)
               to = escapedURI.indexOf("#");
           // get only the path.
  -        escapedURI = (from >= 0) ? escapedURI.substring(from, to) : null;
  -
  -        return escapedURI;
  +        return (from >= 0) ? escapedURI.substring(from, to) : null;
       }
   
   
  @@ -606,11 +826,23 @@
        * This method just ignores the scheme and authority part of the URI path.
        * So this method doesn't throw any exception.
        *
  -     * @return the escaped abs_path or rel_path, and query.
  +     * @return The abs_path or rel_path, and query.
        */
       public String getPathQuery() {
           return getPathQuery(URI);
       }
  +    
  +    
  +    /**
  +     * Get the escaped abs_path or rel_path, and query for this generic URI.
  +     * This method just ignores the scheme and authority part of the URI path.
  +     * So this method doesn't throw any exception.
  +     *
  +     * @return The escaped abs_path or rel_path, and query.
  +     */
  +    public String getEscapedPathQuery() {
  +        return getEscapedPathQuery(URI);
  +    }
   
   
       /**
  @@ -618,10 +850,23 @@
        * This method just ignores the scheme and authority part of the URI path.
        * So this method doesn't throw any exception.
        *
  -     * @param escapedURI the specified escaped URI string.
  -     * @return the escaped abs_path or rel_path, and query.
  +     * @param escapedURI The escaped URI string.
  +     * @return The abs_path or rel_path, and query.
        */
       public static String getPathQuery(String escapedURI) {
  +        return URIUtil.unescape(getEscapedPathQuery(escapedURI));
  +    }
  +
  +
  +    /**
  +     * Get the escaped abs_path or rel_path, and query of the escaped given
  +     * URI string.  This method just ignores the scheme and authority part of
  +     * the URI path. So this method doesn't throw any exception.
  +     *
  +     * @param escapedURI The escaped URI string.
  +     * @return The escaped abs_path or rel_path, and query.
  +     */
  +    public static synchronized String getEscapedPathQuery(String escapedURI) {
   
           // consider of net_path
           int at = escapedURI.indexOf("//");
  @@ -633,26 +878,23 @@
           if (escapedURI.indexOf("#") > from)
               to = escapedURI.indexOf("#");
           // get only the wanted path.
  -        escapedURI = (from >= 0) ? escapedURI.substring(from, to) : "/";
  -
  -        return escapedURI;
  -   }
  +        return (from >= 0) ? escapedURI.substring(from, to) : "/";
  +    }
   
   
       /**
        * Set the path for this generic URI.
        *
  -     * @return The specified path.
  +     * @param path The specified path.
        * @exception MalformedURLException
        */
       public void setPath(String path)
           throws MalformedURLException {
   
  -        // TODO: save the path by URI encoding.
  -
           if (!path.startsWith("/"))
               path = "/" + path;
  -        URI = getScheme() + "://" + getAuthority() + path;
  +        URI = getEscapedScheme() + "://" + getEscapedAuthority()
  +            + URIUtil.escape(path, URIUtil.pathReserved());
       }
   
   
  @@ -660,7 +902,7 @@
        * Get the path for this generic URI.
        * This method ignores the scheme and authority part of the URI path.
        *
  -     * @return the path.
  +     * @return The path.
        */
       public String getPath() {
           return getPath(URI);
  @@ -668,14 +910,37 @@
   
   
       /**
  +     * Get the escaped path for this generic URI.
  +     * This method ignores the scheme and authority part of the URI path.
  +     *
  +     * @return The escaped path.
  +     */
  +    public String getEscapedPath() {
  +        return getEscapedPath(URI);
  +    }
  +
  +
  +    /**
        * Get the path of the given escaped URI string.
        * This method ignores the scheme and authority part of the URI path.
        *
        * @param escapedURI The specified escaped URI string.
  -     * @return the path.
  +     * @return The path.
        */
       public static String getPath(String escapedURI) {
  +        return URIUtil.unescape(getEscapedPath(escapedURI));
  +    }
  +
   
  +    /**
  +     * Get the path of the given escaped URI string.
  +     * This method ignores the scheme and authority part of the URI path.
  +     *
  +     * @param escapedURI The specified escaped URI string.
  +     * @return The escaped path.
  +     */
  +    public static synchronized String getEscapedPath(String escapedURI) {
  +
           // consider of net_path
           int at = escapedURI.indexOf("//");
           int from = escapedURI.indexOf("/", (at >= 0) ? at + 2 : 0);
  @@ -688,9 +953,7 @@
           if (escapedURI.indexOf("#") > from && escapedURI.indexOf("#") < to)
               to = escapedURI.indexOf("#");
           // get only the path.
  -        escapedURI = (from >= 0) ? escapedURI.substring(from, to) : "/";
  -
  -        return escapedURI;
  +        return (from >= 0) ? escapedURI.substring(from, to) : "/";
       }
   
   
  @@ -710,10 +973,10 @@
        * Get the parent path of the given already-normalized path.
        * This method ignores the forward part of the URI path.
        *
  -     * @param escapedPath The specified escaped path string.
  +     * @param escapedPath The escaped path string.
        * @return The parent path of the given already-normalized path.
        */
  -    public static String getParent(String escapedPath) {
  +    public static synchronized String getParent(String escapedPath) {
   
           String pathname = getPath(escapedPath);
   
  @@ -730,7 +993,7 @@
               pathname = pathname.substring(0, at+1);
           }
   
  -        return pathname;
  +        return URIUtil.unescape(pathname);
       }
   
   
  @@ -751,7 +1014,7 @@
        * @return The collection name, if the path is a collection,
        *         The resource name, if the path is a resource.
        */
  -    public static String getName(String escapedPath) {
  +    public static synchronized String getName(String escapedPath) {
   
           // Return a string starting with the '/' charcater.
           String name = getPath(escapedPath);
  @@ -761,7 +1024,8 @@
           // Remove the last '/' character.
           if (name.endsWith("/"))
               name = name.substring(0, name.length()-1);
  -        return name.substring(name.lastIndexOf("/") + 1);
  +
  +        return URIUtil.unescape(name.substring(name.lastIndexOf("/") + 1));
       }
   
   
  @@ -780,10 +1044,24 @@
   
   
       /**
  +     * Get the escaped query for this generic URI.
  +     * This method ignores the scheme and authority part for this generic URI.
  +     *
  +     * @return The escaped query string.
  +     * @exception MalformedURLException
  +     */
  +    public String getEscapedQuery()
  +        throws MalformedURLException {
  +
  +        return getEscapedQuery(URI);
  +    }
  +
  +
  +    /**
        * Get the query of the given URI string.
        * This method ignores the scheme and authority part of the given URI.
        *
  -     * @param escapedURI The specified escaped URI string.
  +     * @param escapedURI The escaped URI string.
        *                   It could be the generic URI and relative URI.
        * @return The query string.
        * @exception MalformedURLException
  @@ -791,6 +1069,22 @@
       public static String getQuery(String escapedURI)
           throws MalformedURLException {
   
  +        return URIUtil.unescape(getEscapedQuery(escapedURI));
  +    }
  +
  +
  +    /**
  +     * Get the escaped query of the given URI string.
  +     * This method ignores the scheme and authority part of the given URI.
  +     *
  +     * @param escapedURI The escaped URI string.
  +     *                   It could be the generic URI and relative URI.
  +     * @return The escaped query string.
  +     * @exception MalformedURLException
  +     */
  +    public static synchronized String getEscapedQuery(String escapedURI)
  +        throws MalformedURLException {
  +
           int at = escapedURI.indexOf("//");
           // Just ignore the authority part of URI
           at = (at > 0) ? escapedURI.indexOf("/", at + 2) :
  @@ -825,10 +1119,24 @@
   
   
       /**
  +     * Get the escaped fragment for this generic URI.
  +     * This method ignores the scheme and authority part of the given URI.
  +     *
  +     * @return The escaped fragment string.
  +     * @exception MalformedURLException
  +     */
  +    public String getEscapedFragment()
  +        throws MalformedURLException {
  +
  +        return getEscapedFragment(URI);
  +    }
  +
  +
  +    /**
        * Get the fragment of the given escaped URI string.
        * This method ignores the scheme and authority part of the given URI.
        *
  -     * @param escapedURI The specified URI string.
  +     * @param escapedURI The escaped URI string.
        *                   It could be the generic URI and relative URI.
        * @return The fragment string.
        * @exception MalformedURLException
  @@ -836,6 +1144,22 @@
       public static String getFragment(String escapedURI)
           throws MalformedURLException {
   
  +        return URIUtil.unescape(getEscapedFragment(escapedURI));
  +    }
  +
  +
  +    /**
  +     * Get the fragment of the given escaped URI string.
  +     * This method ignores the scheme and authority part of the given URI.
  +     *
  +     * @param escapedURI The escaped URI string.
  +     *                   It could be the generic URI and relative URI.
  +     * @return The escaped fragment string.
  +     * @exception MalformedURLException
  +     */
  +    public static synchronized String getEscapedFragment(String escapedURI)
  +        throws MalformedURLException {
  +
           int at = escapedURI.indexOf("//");
           // Just ignore the authority part of URI
           at = (at > 0) ? escapedURI.indexOf("/", at + 2) :
  @@ -883,12 +1207,12 @@
   
   
       /**
  -     * Get the URI string.
  +     * Get the escaped URI string.
        *
        * @return The URI string.
        */
       public String toString() {
  -        return URI;
  +        return getEscapedURI();
       }
   
   }
  
  
  
  1.9       +156 -27   jakarta-slide/src/webdav/client/src/org/apache/webdav/util/HttpURL.java
  
  Index: HttpURL.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/HttpURL.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- HttpURL.java	2001/04/06 11:57:31	1.8
  +++ HttpURL.java	2001/04/26 13:08:35	1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/HttpURL.java,v 1.8 2001/04/06 11:57:31 jericho Exp $
  - * $Revision: 1.8 $
  - * $Date: 2001/04/06 11:57:31 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/HttpURL.java,v 1.9 2001/04/26 13:08:35 jericho Exp $
  + * $Revision: 1.9 $
  + * $Date: 2001/04/26 13:08:35 $
    *
    * ====================================================================
    *
  @@ -80,11 +80,11 @@
       /**
        * This Constructor
        *
  -     * @param httpURL the URI string.
  +     * @param httpURL The escaped URI string.
        */
  -    public HttpURL(String httpURL) {
  +    public HttpURL(String escapedHttpURL) {
   
  -        super(httpURL);
  +        super(escapedHttpURL);
           setDefaultScheme(scheme);
           setDefaultPort(port);
       }
  @@ -93,13 +93,12 @@
       /**
        * This Constructor
        *
  -     * @param scheme the scheme string.
  -     * @param host the host string.
  -     * @param path the path string.
  +     * @param host The host string.
  +     * @param path The path string.
        */
  -    public HttpURL(String scheme, String host, String path) {
  +    public HttpURL(String host, String path) {
   
  -        super(scheme, host, path);
  +        super(scheme, host, port, path);
           setDefaultScheme(scheme);
           setDefaultPort(port);
       }
  @@ -108,12 +107,11 @@
       /**
        * This Constructor
        *
  -     * @param scheme the scheme string.
  -     * @param host the host string.
  -     * @param port the port number.
  -     * @param path the path string.
  +     * @param host The host string.
  +     * @param port The port number.
  +     * @param path The path string.
        */
  -    public HttpURL(String scheme, String host, int port, String path) {
  +    public HttpURL(String host, int port, String path) {
   
           super(scheme, host, port, path);
           setDefaultScheme(scheme);
  @@ -124,14 +122,81 @@
       /**
        * This Constructor
        *
  +     * @param host The host string.
  +     * @param path The path string.
  +     * @param query The query string.
  +     */
  +    public HttpURL(String host, String path, String query) {
  +        super(scheme, host, port, path, query);
  +        setDefaultScheme(scheme);
  +        setDefaultPort(port);
  +    }
  +
  +
  +    /**
  +     * This Constructor
  +     *
  +     * @param host The host string.
  +     * @param port The port number.
  +     * @param path The path string.
  +     * @param query The query string.
  +     */
  +    public HttpURL(String host, int port, String path, String query) {
  +
  +        super(scheme, host, port, path, query);
  +        setDefaultScheme(scheme);
  +        setDefaultPort(port);
  +    }
  +
  +
  +    /**
  +     * This Constructor
  +     *
  +     * @param userName The username string.
  +     * @param password The password string.
  +     * @param host The host string.
  +     * @param path The path string.
  +     * @param query The query string.
  +     */
  +    public HttpURL(String userName, String password, String host,
  +                   String path, String query) {
  +
  +        super(scheme, userName, password, host, port, path, query);
  +        setDefaultScheme(scheme);
  +        setDefaultPort(port);
  +    }
  +
  +
  +    /**
  +     * This Constructor
  +     *
  +     * @param userName The username string.
  +     * @param password The password string.
  +     * @param host The host string.
  +     * @param port The port number.
  +     * @param path The path string.
  +     * @param query The query string.
  +     */
  +    public HttpURL(String userName, String password, String host, int port,
  +                   String path, String query) {
  +
  +        super(scheme, userName, password, host, port, path, query);
  +        setDefaultScheme(scheme);
  +        setDefaultPort(port);
  +    }
  +
  +
  +    /**
  +     * This Constructor
  +     *
        * @param httpURL The http URL.
        * @param path The added relative path.
        */
       public HttpURL(HttpURL httpURL, String path) {
   
  -        this(httpURL.toString().endsWith("/") ?
  -             httpURL.toString() + path : httpURL.toString() + "/" + path);
  -        
  +        this(httpURL.toString() +
  +             (httpURL.toString().endsWith("/") ? "" : "/") +
  +             URIUtil.escape(path, URIUtil.pathReserved()));
       }
   
   
  @@ -162,10 +227,9 @@
       /**
        * Get the scheme for this Generic URI.
        *
  -     * @return the scheme for this Generic URI.
  +     * @return The scheme for this Generic URI.
        */
       protected String getDefaultScheme() {
  -
           return scheme;
       }
   
  @@ -173,10 +237,9 @@
       /**
        * Get the default port number for this generic URI.
        *
  -     * @return the port number to set for this generic URI.
  +     * @return The port number to set for this generic URI.
        */
       protected int getDefaultPort() {
  -
           return port;
       }
   
  @@ -190,12 +253,31 @@
        * @return The http URL.
        */
       public HttpURL getHttpURL() {
  +        return new HttpURL(getEscapedURI());
  +    }
  +
   
  -        return new HttpURL(getURI());
  +    /**
  +     * Get the escaped http URL string.
  +     *
  +     * @return The escaped http URL string.
  +     */
  +    public String getEscapedHttpURL() {
  +        return getHttpURL().toString();
       }
   
   
       /**
  +     * Get the http URL string.
  +     *
  +     * @return The http URL string.
  +     */
  +    public String getUnescapedHttpURL() {
  +        return URIUtil.unescape(getHttpURL().toString());
  +    }
  +
  +
  +    /**
        * Get the HttpURL instance except for password.
        *
        * @return The http URL except for password.
  @@ -211,6 +293,30 @@
   
   
       /**
  +     * Get the escaped HttpURL string except for password.
  +     *
  +     * @return The escaped http URL string except for password.
  +     */
  +    public String getEscapedHttpURLExceptForPassword()
  +        throws MalformedURLException {
  +
  +        return getHttpURLExceptForPassword().toString();
  +    }
  +
  +
  +    /**
  +     * Get the HttpURL string except for password.
  +     *
  +     * @return The http URL string except for password.
  +     */
  +    public String getUnescapedHttpURLExceptForPassword()
  +        throws MalformedURLException {
  +
  +        return URIUtil.unescape(getHttpURLExceptForPassword().toString());
  +    }
  +
  +
  +    /**
        * Get the HttpURL instance except for userinfo.
        *
        * @return The http URL except for password.
  @@ -226,6 +332,31 @@
   
   
       /**
  +     * Get the escaped HttpURL string except for userinfo.
  +     *
  +     * @return The escaped http URL string except for password.
  +     */
  +    public String getEscapedHttpURLExceptForUserInfo()
  +        throws MalformedURLException {
  +
  +        return getHttpURLExceptForUserInfo().toString();
  +    }
  +
  +
  +
  +    /**
  +     * Get the HttpURL string except for userinfo.
  +     *
  +     * @return The http URL string except for password.
  +     */
  +    public String getUnescapedHttpURLExceptForUserInfo()
  +        throws MalformedURLException {
  +
  +        return URIUtil.unescape(getHttpURLExceptForUserInfo().toString());
  +    }
  +
  +
  +    /**
        * To support <code>java.net.URL</code> of JDK 1.1.x.
        *
        * @return <code>java.net.URL</code>
  @@ -234,9 +365,7 @@
       public URL toURL()
           throws MalformedURLException {
   
  -        return new URL(getHttpURLExceptForUserInfo().toString());
  +        return new URL(getUnescapedHttpURLExceptForUserInfo().toString());
       }
   
   }
  -
  -