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/02/24 03:16:57 UTC

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

jericho     01/02/23 18:16:57

  Modified:    src/webdav/client/src/org/apache/webdav/util GenericURI.java
  Added:       src/webdav/client/src/org/apache/webdav/util HttpURL.java
  Removed:     src/webdav/client/src/org/apache/webdav/util
                        MalformedURIException.java
  Log:
  - Make GenericURI an abstract class.
  - GenericURI constructor improved and toURL() added.
  - Add HttpURL class.
  - Use java.net.MalformedURLException rather than MalformedURIException, Because of the same function.
  - MalformedURIException removed.
  
  Revision  Changes    Path
  1.2       +105 -62   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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GenericURI.java	2001/02/23 09:43:53	1.1
  +++ GenericURI.java	2001/02/24 02:16:57	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header:
  - * $Revision:
  - * $Date:
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/GenericURI.java,v 1.2 2001/02/24 02:16:57 jericho Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/02/24 02:16:57 $
    *
    * ====================================================================
    *
  @@ -63,6 +63,9 @@
   
   package org.apache.webdav.util;
   
  +import java.net.URL;
  +import java.net.MalformedURLException;
  +
   /**
    * URI (Uniform Resource Identifiers), RFC 2396.
    * This is the generic URI version.
  @@ -71,7 +74,7 @@
    *
    * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a>
    */
  -public class GenericURI {
  +public abstract class GenericURI {
   
   
       // --------------------------------------------------------- Constructors
  @@ -84,7 +87,10 @@
        */
       public GenericURI(String uri) {
           
  -        this.uri = uri;
  +        if (uri.indexOf("://") > 0)
  +            this.uri = uri;
  +        else
  +            this.uri = getDefaultScheme() + "://"+ uri;
       }
   
   
  @@ -162,6 +168,17 @@
   
   
       /**
  +     * Get the scheme for this Generic URI.
  +     *
  +     * @return the scheme for this Generic URI.
  +     */
  +    public String getDefaultScheme() {
  +
  +	    return defaultScheme;
  +    }
  +
  +
  +    /**
        * Set the default port number for this generic URI.
        *
        * @param The port number to set for this generic URI.
  @@ -172,6 +189,17 @@
       }
   
   
  +    /**
  +     * Get the default port number for this generic URI.
  +     *
  +     * @return The port number to set for this generic URI.
  +     */
  +    public int getDefaultPort() {
  +
  +        return defaultPort;
  +    }
  +
  +
       // ------------------------------------------------------  Public Methods
   
   
  @@ -179,10 +207,10 @@
        * Get the scheme for this Generic URI.
        *
        * @return  the scheme for this Generic URI.
  -     * @exception MalformedURIException no scheme.
  +     * @exception MalformedURLException no scheme.
        */
       public String getScheme()
  -        throws MalformedURIException {
  +        throws MalformedURLException {
   
   	    return getScheme(uri);
       }
  @@ -193,10 +221,10 @@
        *
   	 * @param uri the URI string to get the scheme.
        * @return the scheme of the given URI.
  -     * @exception MalformedURIException no scheme.
  +     * @exception MalformedURLException no scheme.
        */
       public static String getScheme(String uri)
  -        throws MalformedURIException {
  +        throws MalformedURLException {
   
           return getScheme(uri, defaultScheme);
       }
  @@ -209,10 +237,10 @@
   	 * @param uri the URI string to get the scheme.
   	 * @param defaultScheme the scheme to set.
        * @return the scheme of the given URI.
  -     * @exception MalformedURIException no scheme.
  +     * @exception MalformedURLException no scheme.
        */
       public static String getScheme(String uri, String defaultScheme)
  -        throws MalformedURIException {
  +        throws MalformedURLException {
   
           int at = uri.indexOf("://");
           if (at > 0)
  @@ -220,7 +248,7 @@
   
           // Check the default.
           if (defaultScheme == null)
  -            throw new MalformedURIException("No default scheme: " + uri);
  +            throw new MalformedURLException("No default scheme: " + uri);
   
           return defaultScheme;
       }
  @@ -230,10 +258,10 @@
   	 * Get the authority part for this generic URI.
   	 *
   	 * @return the authority part of this generic URI.
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
   	 */
   	public String getAuthority()
  -	    throws MalformedURIException {
  +	    throws MalformedURLException {
   	    
           return getAuthority(uri);
   	}
  @@ -244,10 +272,10 @@
   	 *
   	 * @param uri the URI string to get the authority part.
   	 * @return the authority part of the given URI.
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
   	 */
   	public static String getAuthority(String uri)
  -	    throws MalformedURIException {
  +	    throws MalformedURLException {
   	    
           int at = uri.indexOf("://");
           if (at > 0) {
  @@ -259,7 +287,7 @@
               else
                   return uri.substring(from);
           } else
  -            throw new MalformedURIException("No scheme: " + uri);
  +            throw new MalformedURLException("No scheme: " + uri);
   	}
   
   
  @@ -267,10 +295,10 @@
   	 * Get the userinfo part for this generic URI.
   	 *
   	 * @return the userifno of this generic URI.
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
   	 */
   	public String getUserInfo()
  -	    throws MalformedURIException {
  +	    throws MalformedURLException {
   
   	    return getUserInfo(uri);
   	}
  @@ -281,10 +309,10 @@
   	 *
   	 * @param uri the URI string to get the userinfo part.
   	 * @return the userifno of the given URI.
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
   	 */
   	public static String getUserInfo(String uri)
  -	    throws MalformedURIException {
  +	    throws MalformedURLException {
   	    
           String authority = getAuthority(uri);
           
  @@ -300,11 +328,11 @@
   	 * Get the username on the userinfo for this generic URI.
   	 *
   	 * @return the username of URI
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
   	 * @see #getUserName(java.lang.String)
   	 */
   	public String getUserName()
  -	    throws MalformedURIException {
  +	    throws MalformedURLException {
   
           return getUserName(uri);
   	}
  @@ -315,10 +343,10 @@
   	 *
   	 * @param uri the URI string to get the username.
   	 * @return the username of URI
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
   	 */
   	public static String getUserName(String uri)
  -	    throws MalformedURIException {
  +	    throws MalformedURLException {
   	    
           try {
               String userInfo = getUserInfo(uri);
  @@ -339,10 +367,10 @@
   	 * Get the password on the userinfo for this URI string.
   	 *
   	 * @return the password of URI
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
   	 */
   	public String getPassword()
  -	    throws MalformedURIException {
  +	    throws MalformedURLException {
   	    
           return getPassword(uri);
   	}
  @@ -353,10 +381,10 @@
   	 *
   	 * @param uri the URI string to get the password.
   	 * @return the password of URI
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
   	 */
   	public static String getPassword(String uri)
  -	    throws MalformedURIException {
  +	    throws MalformedURLException {
   	    
           try {
               String userInfo = getUserInfo(uri);
  @@ -377,10 +405,10 @@
   	 * Get the hostport part for this generic URI.
   	 *
   	 * @return the hostport string of the URI
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
   	 */
   	public String getHostPort()
  -	    throws MalformedURIException {
  +	    throws MalformedURLException {
           
           return getHostPort(uri);	    
       }
  @@ -391,10 +419,10 @@
   	 *
   	 * @param uri the URI string to get the hostport part.
   	 * @return the hostport of URI
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
   	 */
   	public static String getHostPort(String uri)
  -	    throws MalformedURIException {
  +	    throws MalformedURLException {
   	    
           String authority = getAuthority(uri);
           
  @@ -410,10 +438,10 @@
        * Get the hostname for this generic URI.
        *
        * @return The hostname string
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
        */
       public String getHost()
  -        throws MalformedURIException {
  +        throws MalformedURLException {
   
           return getHost(uri);
       }
  @@ -424,10 +452,10 @@
        *
   	 * @param uri the URI string to get the hostname.
        * @return The hostname string
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
        */
       public static String getHost(String uri)
  -        throws MalformedURIException {
  +        throws MalformedURLException {
   
   	    String hostPort = getHostPort(uri);
   	    int to = hostPort.indexOf(":");
  @@ -442,10 +470,10 @@
        * Get the port number for this generic URI.
        *
        * @return The port number
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
        */
       public int getPort()
  -        throws MalformedURIException {
  +        throws MalformedURLException {
   
   	    return getPort(uri);
       }
  @@ -456,10 +484,10 @@
        *
   	 * @param uri the URI string to get the port number.
        * @return The port number
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
        */
       public static int getPort(String uri)
  -        throws MalformedURIException {
  +        throws MalformedURLException {
   
   	    return getPort(uri, defaultPort);
       }
  @@ -471,10 +499,10 @@
   	 * @param uri the URI string to get the port number.
   	 * @param defaultPort the default port for the given URI.
        * @return The port number
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
        */
       public static int getPort(String uri, int defaultPort)
  -        throws MalformedURIException {
  +        throws MalformedURLException {
   	    
   	    String hostPort = getHostPort(uri);
   	    int at = hostPort.indexOf(":");
  @@ -490,7 +518,7 @@
           }
   
           if (defaultPort == -1)
  -            throw new MalformedURIException("No default port: " + uri);
  +            throw new MalformedURLException("No default port: " + uri);
               
           // The default port number.
           return defaultPort;
  @@ -514,11 +542,12 @@
        * This method ignores the scheme and authority part of the URI path.
        *     
        * @param uri the specified URI string.
  +     *            It could be the generic URI and relative URI.
   	 * @return the path.
        */
       public static String getPath(String uri) {
           
  -        int at = uri.indexOf("://");
  +        int at = uri.indexOf("//");
           // Ignore the authority part of URI
           int to = uri.length();
           // check the query
  @@ -528,7 +557,7 @@
           if (uri.indexOf("#") > 0 && uri.indexOf("#") < to)
               to = uri.indexOf("#");
           if (at > 0) {
  -            int from = uri.indexOf("/", at + 3);
  +            int from = uri.indexOf("/", at + 2);
               uri = uri.substring(from, to);
           } else {
               int from = uri.indexOf("/");
  @@ -619,10 +648,10 @@
        * This method ignores the scheme and authority part for this generic URI.
        *     
   	 * @return the query string.
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
        */
       public String getQuery()
  -        throws MalformedURIException {
  +        throws MalformedURLException {
           
           return getQuery(uri);
       }
  @@ -633,16 +662,17 @@
        * This method ignores the scheme and authority part of the given URI.
        *     
        * @param uri the specified URI string.
  +     *            It could be the generic URI and relative URI.
   	 * @return the query string.
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
        */
       public static String getQuery(String uri)
  -        throws MalformedURIException {
  +        throws MalformedURLException {
           
  -        int at = uri.indexOf("://");
  +        int at = uri.indexOf("//");
           // Just ignore the authority part of URI
           if (at > 0) {
  -            at = uri.indexOf("/", at + 3);
  +            at = uri.indexOf("/", at + 2);
           } else {
               // FIXME: net_path?
               at = uri.indexOf("/");
  @@ -661,7 +691,7 @@
               else
                   return null;
           } else
  -            throw new MalformedURIException("Need to have the path part");
  +            throw new MalformedURLException("Need to have the path part");
   
       }
   
  @@ -671,10 +701,10 @@
        * This method ignores the scheme and authority part of the given URI.
        *     
   	 * @return the fragment string.
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
        */
       public String getFragment()
  -        throws MalformedURIException {
  +        throws MalformedURLException {
           
           return getFragment(uri);
       }
  @@ -684,18 +714,18 @@
        * This method ignores the scheme and authority part of the given URI.
        *     
        * @param uri the specified URI string.
  +     *            It could be the generic URI and relative URI.
   	 * @return the fragment string.
  -	 * @exception MalformedURIException
  +	 * @exception MalformedURLException
        */
       public static String getFragment(String uri)
  -        throws MalformedURIException {
  +        throws MalformedURLException {
           
  -        int at = uri.indexOf("://");
  +        int at = uri.indexOf("//");
           // Just ignore the authority part of URI
           if (at > 0) {
  -            at = uri.indexOf("/", at + 3);
  +            at = uri.indexOf("/", at + 2);
           } else {
  -            // FIXME: net_path?
               at = uri.indexOf("/");
           }
           if (at > 0) {
  @@ -708,8 +738,21 @@
               else
                   return null;
           } else
  -            throw new MalformedURIException("Need to have the path part");
  +            throw new MalformedURLException("Need to have the path part");
  +
  +    }
  +
  +
  +    /**
  +     * To support <code>java.net.URL</code> of JDK 1.1.x.
  +     *
  +     * @return <code>java.net.URL</code>
  +	 * @exception MalformedURLException
  +     */
  +    public URL toURL()
  +        throws MalformedURLException {
   
  +        return new URL(getScheme() + "://" + getHostPort() + getPath());
       }
   
   
  @@ -737,7 +780,7 @@
   
                       return true;
   
  -            } catch(MalformedURIException ignored) {
  +            } catch(MalformedURLException ignored) {
               }
       	}
   
  
  
  
  1.1                  jakarta-slide/src/webdav/client/src/org/apache/webdav/util/HttpURL.java
  
  Index: HttpURL.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/HttpURL.java,v 1.1 2001/02/24 02:16:57 jericho Exp $
   * $Revision: 1.1 $
   * $Date: 2001/02/24 02:16:57 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.webdav.util;
  
  import java.io.IOException;
  import java.net.URL;
  import java.net.MalformedURLException;
  
  /**
   * This is for the HTTP URL of the generic URI version.
   * 
   * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a>
   */
  public class HttpURL extends GenericURI {
  
  
      // --------------------------------------------------------- Constructors
  
  
      /**
       * This Constructor
       *
       * @param the URI string.
       */
      public HttpURL(String httpUrl) {
          
          super(httpUrl);
          setDefaultScheme(scheme);
          setDefaultPort(port);
      }
  
  
      /**
       * This Constructor
       *
       * @param the scheme string.
       * @param the host string.
       * @param the path string.
       */
      public HttpURL(String scheme, String host, String path) {
          
          super(scheme, host, path);
          setDefaultScheme(scheme);
          setDefaultPort(port);
      }
  
  
      /**
       * This Constructor
       *
       * @param the scheme string.
       * @param the host string.
       * @param the port number.
       * @param the path string.
       */
      public HttpURL(String scheme, String host, int port, String path) {
          
          super(scheme, host, port, path);
          setDefaultScheme(scheme);
          setDefaultPort(port);
      }
  
  
      // ------------------------------------------------------------ Constants
  
  
      /** 
       * Default scheme for HTTP URL.
       */
      public final static String scheme = "http";
  
  
      /** 
       * Default port for HTTP URL.
       */
      public final static int port = 80;
  
  
  }