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 2003/01/21 05:04:55 UTC

cvs commit: jakarta-slide/src/tests/uri HttpsURL.java HttpURL.java

jericho     2003/01/20 20:04:55

  Modified:    src/tests/uri HttpsURL.java HttpURL.java
  Log:
  - Add useful contructors
  - Add setXxxUserinfo,setXxxUser,setXxxPassword,setXxxPath,setXxxQuery methods
  
  Revision  Changes    Path
  1.2       +49 -3     jakarta-slide/src/tests/uri/HttpsURL.java
  
  Index: HttpsURL.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/tests/uri/HttpsURL.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpsURL.java	10 Sep 2002 22:41:09 -0000	1.1
  +++ HttpsURL.java	21 Jan 2003 04:04:55 -0000	1.2
  @@ -259,6 +259,40 @@
       }
   
   
  +    /**
  +     * Construct a HTTPS URL from given components.
  +     *
  +     * @param userinfo the userinfo string
  +     * @param host the host string
  +     * @param port the port number
  +     * @param path the path string
  +     * @exception URIException
  +     */
  +    public HttpsURL(String userinfo, String host, int port, String path)
  +        throws URIException {
  +
  +        this(userinfo, host, port, path, null, null);
  +        checkValid();
  +    }
  +
  +
  +    /**
  +     * Construct a HTTPS URL from given components.
  +     *
  +     * @param userinfo the userinfo string
  +     * @param host the host string
  +     * @param port the port number
  +     * @param path the path string
  +     * @param query the query string
  +     * @exception URIException
  +     */
  +    public HttpsURL(String userinfo, String host, int port, String path,
  +            String query) throws URIException {
  +
  +        this(userinfo, host, port, path, query, null);
  +        checkValid();
  +    }
  +
   
       /**
        * Construct a HTTPS URL from given components.
  @@ -309,6 +343,18 @@
           }
           parseUriReference(buff.toString(), false);
           checkValid();
  +    }
  +
  +
  +    /**
  +     * Construct a HTTPS URL with a given relative HTTPS URL string.
  +     *
  +     * @param base the base HttpsURL
  +     * @param relative the relative HTTPS URL string
  +     * @exception URIException
  +     */
  +    public HttpsURL(HttpsURL base, String relative) throws URIException {
  +        this(base, new HttpsURL(relative));
       }
   
   
  
  
  
  1.3       +267 -9    jakarta-slide/src/tests/uri/HttpURL.java
  
  Index: HttpURL.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/tests/uri/HttpURL.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HttpURL.java	10 Sep 2002 22:41:09 -0000	1.2
  +++ HttpURL.java	21 Jan 2003 04:04:55 -0000	1.3
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -15,7 +15,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    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
  @@ -23,15 +23,15 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  + *    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", "Slide", and "Apache Software
    *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written 
  + *    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"
  @@ -259,6 +259,40 @@
       }
   
   
  +    /**
  +     * Construct a HTTP URL from given components.
  +     *
  +     * @param userinfo the userinfo string
  +     * @param host the host string
  +     * @param port the port number
  +     * @param path the path string
  +     * @exception URIException
  +     */
  +    public HttpURL(String userinfo, String host, int port, String path)
  +        throws URIException {
  +
  +        this(userinfo, host, port, path, null, null);
  +        checkValid();
  +    }
  +
  +
  +    /**
  +     * Construct a HTTP URL from given components.
  +     *
  +     * @param userinfo the userinfo string
  +     * @param host the host string
  +     * @param port the port number
  +     * @param path the path string
  +     * @param query the query string
  +     * @exception URIException
  +     */
  +    public HttpURL(String userinfo, String host, int port, String path,
  +            String query) throws URIException {
  +
  +        this(userinfo, host, port, path, query, null);
  +        checkValid();
  +    }
  +
   
       /**
        * Construct a HTTP URL from given components.
  @@ -313,6 +347,18 @@
   
   
       /**
  +     * Construct a HTTP URL with a given relative URL string.
  +     *
  +     * @param base the base HttpURL
  +     * @param relative the relative HTTP URL string
  +     * @exception URIException
  +     */
  +    public HttpURL(HttpURL base, String relative) throws URIException {
  +        this(base, new HttpURL(relative));
  +    }
  +
  +
  +    /**
        * Construct a HTTP URL with a given relative URL.
        *
        * @param base the base HttpURL
  @@ -376,6 +422,116 @@
       // ----------------------------------------------------------- The userinfo
   
       /**
  +     * Set the raw-escaped user and password.
  +     *
  +     * @param escapedUser the raw-escaped user
  +     * @param escapedPassword the raw-escaped password; could be null
  +     * @exception URIException escaped user not valid or user required; escaped
  +     * password not valid or username missed
  +     */
  +    public void setRawUserinfo(char[] escapedUser, char[] escapedPassword)
  +        throws URIException {
  +
  +        if (escapedUser == null || escapedUser.length == 0)
  +            throw new URIException(URIException.PARSING, "user required");
  +        if (!validate(escapedUser, within_userinfo) ||
  +                ((escapedPassword != null) &&
  +                 !validate(escapedPassword, within_userinfo)))
  +            throw new URIException(URIException.ESCAPING,
  +                    "escaped userinfo not valid");
  +        String username = new String(escapedUser);
  +        String password = (escapedPassword == null) ? null :
  +            new String(escapedPassword);
  +        String userinfo = username + ((password == null) ? "" : ":" + password);
  +        String hostname = new String(getRawHost());
  +        String hostport = (_port == -1) ? hostname : hostname + _port;
  +        String authority = userinfo + "@" + hostport;
  +        _userinfo = userinfo.toCharArray();
  +        _authority = authority.toCharArray();
  +        setURI();
  +    }
  +
  +
  +    /**
  +     * Set the raw-escaped user and password.
  +     *
  +     * @param escapedUser the escaped user
  +     * @param escapedPassword the escaped password; could be null
  +     * @exception URIException escaped user not valid or user required; escaped
  +     * password not valid or username missed
  +     * @throws NullPointerException null user
  +     */
  +    public void setEscapedUserinfo(String escapedUser, String escapedPassword)
  +        throws URIException {
  +
  +        setRawUserinfo(escapedUser.toCharArray(), (escapedPassword == null) ?
  +            null : escapedPassword.toCharArray());
  +    }
  +
  +
  +    /**
  +     * Set the user and password.
  +     *
  +     * @param user the user
  +     * @param password the password; could be null
  +     * @exception URIException encoding error or username missed
  +     * @throws NullPointerException null user
  +     */
  +    public void setUserinfo(String user, String password) throws URIException {
  +        setRawUserinfo(encode(user, within_userinfo), (password == null) ?
  +                null : encode(password, within_userinfo));
  +    }
  +
  +
  +    /**
  +     * Set the raw-escaped user.
  +     *
  +     * @param the raw-escaped user
  +     * @exception URIException escaped user not valid or user required
  +     */
  +    public void setRawUser(char[] escapedUser) throws URIException {
  +        if (escapedUser == null || escapedUser.length == 0)
  +            throw new URIException(URIException.PARSING, "user required");
  +        if (!validate(escapedUser, within_userinfo))
  +            throw new URIException(URIException.ESCAPING,
  +                    "escaped user not valid");
  +        String username = new String(escapedUser);
  +        String password = new String(getRawPassword());
  +        String userinfo = username + ((password == null) ? "" : ":" + password);
  +        String hostname = new String(getRawHost());
  +        String hostport = (_port == -1) ? hostname : hostname + _port;
  +        String authority = userinfo + "@" + hostport;
  +        _userinfo = userinfo.toCharArray();
  +        _authority = authority.toCharArray();
  +        setURI();
  +    }
  +
  +
  +    /**
  +     * Set the escaped user string.
  +     *
  +     * @param escapedUser the escaped user string
  +     * @exception URIException escaped user not valid
  +     * @throws NullPointerException null user
  +     */
  +    public void setEscapedUser(String escapedUser) throws URIException {
  +        setRawUser(escapedUser.toCharArray());
  +    }
  +
  +
  +    /**
  +     * Set the user string.
  +     *
  +     * @param user the user string
  +     * @exception URIException user encoding error
  +     * @throws NullPointerException null user
  +     */
  +    public void setUser(String user) throws URIException {
  +        setRawUser(encode(user, allowed_within_userinfo));
  +    }
  +
  +
  +    /**
        * Get the raw-escaped user.
        *
        * @return the raw-escaped user
  @@ -419,6 +575,56 @@
   
   
       /**
  +     * Set the raw-escaped password.
  +     *
  +     * @param password the raw-escaped password; could be null
  +     * @exception URIException escaped password not valid or username missed
  +     */
  +    public void setRawPassword(char[] escapedPassword) throws URIException {
  +        if (escapedPassword != null &&
  +                !validate(escapedPassword, within_userinfo))
  +            throw new URIException(URIException.ESCAPING,
  +                    "escaped password not valid");
  +        if (getRawUser() == null || getRawUser().length == 0)
  +            throw new URIException(URIException.PARSING, "username required");
  +        String username = new String(getRawUser());
  +        String password = new String(escapedPassword);
  +        // an emtpy string is allowed as a password
  +        String userinfo = username + ((password == null) ? "" : ":" + password);
  +        String hostname = new String(getRawHost());
  +        String hostport = (_port == -1) ? hostname : hostname + _port;
  +        String authority = userinfo + "@" + hostport;
  +        _userinfo = userinfo.toCharArray();
  +        _authority = authority.toCharArray();
  +        setURI();
  +    }
  +
  +
  +    /**
  +     * Set the escaped password string.
  +     *
  +     * @param password the escaped password string; could be null
  +     * @exception URIException escaped password not valid or username missed
  +     */
  +    public void setEscapedPassword(String escapedPassword) throws URIException {
  +        setRawPassword((escapedPassword == null) ? null :
  +                escapedPassword.toCharArray());
  +    }
  +
  +
  +    /**
  +     * Set the password string.
  +     *
  +     * @param password the password string; could be null
  +     * @exception URIException encoding error or username missed
  +     */
  +    public void setPassword(String password) throws URIException {
  +        setRawPassword((password == null) ? null :
  +                encode(password, allowed_within_userinfo));
  +    }
  +
  +
  +    /**
        * Get the raw-escaped password.
        *
        * @return the raw-escaped password
  @@ -445,7 +651,7 @@
           return (password == null) ? null : new String(password);
       }
   
  - 
  +
       /**
        * Get the password.
        *
  @@ -492,6 +698,58 @@
       public char[] getRawPath() {
           char[] path =  super.getRawPath();
           return (path == null || path.length == 0) ? rootPath : path;
  +    }
  +
  +    // -------------------------------------------------------------- The query
  +
  +    /**
  +     * Set the query as the name and value pair.
  +     *
  +     * @param queryName the query string.
  +     * @param queryValue the query string.
  +     * @exception URIException incomplete trailing escape pattern
  +     * Or unsupported character encoding
  +     * @throws NullPointerException null query
  +     * @see #encode
  +     */
  +    public void setQuery(String queryName, String queryValue)
  +        throws URIException {
  +
  +        StringBuffer buff = new StringBuffer();
  +        buff.append(encode(queryName, allowed_within_query));
  +        buff.append('=');
  +        buff.append(encode(queryValue, allowed_within_query));
  +        _query = buff.toString().toCharArray();
  +        setURI();
  +    }
  +
  +
  +    /**
  +     * Set the query as the name and value pairs.
  +     *
  +     * @param queryName the array of the query string.
  +     * @param queryValue the array of the query string.
  +     * @exception URIException incomplete trailing escape pattern,
  +     * unsupported character encoding or wrong array size
  +     * @throws NullPointerException null query
  +     * @see #encode
  +     */
  +    public void setQuery(String[] queryName, String[] queryValue)
  +        throws URIException {
  +
  +        int length = queryName.length;
  +        if (length != queryValue.length)
  +            throw new URIException("wrong array size of query");
  +
  +        StringBuffer buff = new StringBuffer();
  +        for (int i = 0; i < length; i++) {
  +            buff.append(encode(queryName[i], allowed_within_query));
  +            buff.append('=');
  +            buff.append(encode(queryValue[i], allowed_within_query));
  +            if (i + 1 < length) buff.append('&');
  +        }
  +        _query = buff.toString().toCharArray();
  +        setURI();
       }
   
       // ---------------------------------------------------------------- Utility
  
  
  

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