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/12/22 17:06:09 UTC

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

jericho     2002/12/22 08:06:09

  Modified:    src/util/org/apache/util URI.java URIException.java
  Log:
  URI:
  - Fix a bug not to set fragment in a constructor
  - Rename the method from setUriReference to setURI (not including fragment)
  - Remove the '#' sign from the allowed_within_query
  - Fix some javadoc messages
  - Treat the null query in the setXXXQuery
  - Remove the fragment from setting the query, what if set by API programmer
    (Add the removeFragmentIdentifer method)
  - Add the URIReference methods
  
  URIException:
  - Fix some javadoc messages
  
  Revision  Changes    Path
  1.23      +129 -50   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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- URI.java	3 Nov 2002 17:42:08 -0000	1.22
  +++ URI.java	22 Dec 2002 16:06:08 -0000	1.23
  @@ -216,7 +216,9 @@
           _opaque = encode(scheme_specific_part, allowed_opaque_part);
           // Set flag
           _is_opaque_part = true;
  -        setUriReference();
  +        _fragment = fragment.toCharArray(); 
  +
  +        setURI();
       }
   
   
  @@ -436,7 +438,7 @@
               this._is_opaque_part = relative._is_opaque_part;
               this._opaque = relative._opaque;
               this._fragment = relative._fragment;
  -            this.setUriReference();
  +            this.setURI();
               return;
           }
           if (relative._scheme != null) {
  @@ -492,7 +494,7 @@
           if (relative._fragment != null) {
               this._fragment = relative._fragment;
           }
  -        this.setUriReference();
  +        this.setURI();
       }
   
       // --------------------------------------------------- Instance Variables
  @@ -1478,7 +1480,6 @@
       static {
           allowed_within_query.or(allowed_query);
           allowed_within_query.andNot(reserved); // excluded 'reserved'
  -        allowed_within_query.clear('#'); // avoid confict with the fragment
       }
   
   
  @@ -1607,8 +1608,8 @@
        *
        * @param component the URI character sequence
        * @return original character sequence
  -     * @exception URIException incomplete trailing escape pattern
  -     * or unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * character encoding
        */
       protected static String decode(char[] component) throws URIException {
           return decode(component, _protocolCharset);
  @@ -1642,8 +1643,8 @@
        * @param component the URI character sequence
        * @param charset the protocol charset
        * @return original character sequence
  -     * @exception URIException incomplete trailing escape pattern
  -     * or unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * character encoding
        */
       protected static String decode(char[] component, String charset)
           throws URIException {
  @@ -1959,7 +1960,7 @@
           }
   
           // set this URI.
  -        setUriReference();
  +        setURI();
       }
   
   
  @@ -2149,7 +2150,7 @@
        *
        * @see #getRawURI
        */
  -    protected void setUriReference() {
  +    protected void setURI() {
           // set _uri
           StringBuffer buf = new StringBuffer();
           // ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
  @@ -2185,11 +2186,7 @@
               buf.append('?');
               buf.append(_query);
           }
  -        if (_fragment != null) { // has_fragment
  -            buf.append('#');
  -            buf.append(_fragment);
  -        }
  -
  +        // ignore the fragment identifier
           _uri = buf.toString().toCharArray();
       }
   
  @@ -2464,7 +2461,7 @@
        */
       public void setRawAuthority(char[] escapedAuthority) throws URIException {
           parseAuthority(new String(escapedAuthority), true);
  -        setUriReference();
  +        setURI();
       }
   
   
  @@ -2480,7 +2477,7 @@
           throws URIException {
   
           parseAuthority(escapedAuthority, true);
  -        setUriReference();
  +        setURI();
       }
   
   
  @@ -2845,8 +2842,8 @@
        * Get the basename of the path.
        *
        * @return the basename string
  -     * @exception URIException incomplete trailing escape pattern
  -     * Or unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * character encoding
        * @see #decode
        */
       public String getName() throws URIException {
  @@ -2893,8 +2890,8 @@
        * Get the path and query.
        *
        * @return the path and query string.
  -     * @exception URIException incomplete trailing escape pattern
  -     * Or unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * character encoding
        * @see #decode
        */
       public String getPathQuery() throws URIException {
  @@ -2909,14 +2906,18 @@
        *
        * @param escapedQuery the raw-escaped query
        * @exception URIException escaped query not valid
  -     * @throws NullPointerException null query
        */
       public void setRawQuery(char[] escapedQuery) throws URIException {
  +        if (escapedQuery == null) {
  +            _query = null;
  +            setURI();
  +            return;
  +        }
           if (!validate(escapedQuery, query))
               throw new URIException(URIException.ESCAPING,
                       "escaped query not valid");
  -        _query = escapedQuery;
  -        setUriReference();
  +        _query = removeFragmentIdentifier(escapedQuery);
  +        setURI();
       }
   
   
  @@ -2925,26 +2926,40 @@
        *
        * @param escapedQuery the escaped query string
        * @exception URIException escaped query not valid
  -     * @throws NullPointerException null query
        */
       public void setEscapedQuery(String escapedQuery) throws URIException {
  +        if (escapedQuery == null) {
  +            _query = null;
  +            setURI();
  +            return;
  +        }
           setRawQuery(escapedQuery.toCharArray());
       }
   
   
       /**
        * Set the query.
  +     * <p>
        * When a query string is not misunderstood the reserved special characters
        * ("&amp;", "=", "+", ",", and "$") within a query component, it is
        * recommended to use in encoding the whole query with this method.
  +     * <p>
  +     * The additional APIs for the special purpose using by the reserved
  +     * special characters used in each protocol are implemented in each protocol
  +     * classes inherited from <code>URI</code>.  So refer to the same-named APIs
  +     * implemented in each specific protocol instance.
        *
        * @param query the query string.
  -     * @exception URIException incomplete trailing escape pattern
  -     * Or unsupported character encoding
  -     * @throws NullPointerException null query
  +     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * character encoding
        * @see #encode
        */
       public void setQuery(String query) throws URIException {
  +        if (query == null) {
  +            _query = null;
  +            setURI();
  +            return;
  +        }
           setRawQuery(encode(query, allowed_query));
       }
   
  @@ -2973,8 +2988,8 @@
        * Get the query.
        *
        * @return the query string.
  -     * @exception URIException incomplete trailing escape pattern
  -     * Or unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * character encoding
        * @see #decode
        */
       public String getQuery() throws URIException {
  @@ -2988,14 +3003,18 @@
        *
        * @param escapedFragment the raw-escaped fragment
        * @exception URIException escaped fragment not valid
  -     * @throws NullPointerException null fragment
        */
       public void setRawFragment(char[] escapedFragment) throws URIException {
  +        if (escapedFragment == null) {
  +            _fragment = null;
  +            return;
  +        }
           if (!validate(escapedFragment, fragment))
               throw new URIException(URIException.ESCAPING,
                       "escaped fragment not valid");
  -        _fragment = escapedFragment;
  -        setUriReference();
  +        // remove the fragment identifier
  +        _fragment = removeFragmentIdentifier(escapedFragment);
  +        setURI();
       }
   
   
  @@ -3004,29 +3023,34 @@
        *
        * @param escapedFragment the escaped fragment string
        * @exception URIException escaped fragment not valid
  -     * @throws NullPointerException null fragment
        */
       public void setEscapedFragment(String escapedFragment) throws URIException {
  +        if (escapedFragment == null) {
  +            _fragment = null;
  +            return;
  +        }
           char[] fragmentSequence = escapedFragment.toCharArray();
           if (!validate(fragmentSequence, fragment))
               throw new URIException(URIException.ESCAPING,
                       "escaped fragment not valid");
           _fragment = fragmentSequence;
  -        setUriReference();
  +        setURI();
       }
   
   
       /**
        * Set the fragment.
        *
  -     * @param the fragment string.
  +     * @param fragment the fragment string.
        * @exception URIException
  -     * Or unsupported character encoding
  -     * @throws NullPointerException null fragment
        */
       public void setFragment(String fragment) throws URIException {
  +        if (fragment == null) {
  +            _fragment = null;
  +            return;
  +        }
           _fragment = encode(fragment, allowed_fragment);
  -        setUriReference();
  +        setURI();
       }
   
   
  @@ -3064,8 +3088,8 @@
        * Get the fragment.
        *
        * @return the fragment string
  -     * @exception URIException incomplete trailing escape pattern
  -     * Or unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * character encoding
        * @see #decode
        */
       public String getFragment() throws URIException {
  @@ -3075,6 +3099,23 @@
       // ------------------------------------------------------------- Utilities 
   
       /**
  +     * Remove the fragment identifier of the given component.
  +     *
  +     * @param component the component that a fragment may be included
  +     * @return the component that the fragment identifier is removed
  +     */
  +    protected char[] removeFragmentIdentifier(char[] component) {
  +        if (component == null) return null;
  +        int lastIndex = new String(component).indexOf('#');
  +        if (lastIndex != -1) {
  +            component = new String(component).substring(0,
  +                    lastIndex).toCharArray();
  +        }
  +        return component;
  +    }
  +
  +
  +    /**
        * Normalize the given hier path part.
        *
        * @param path the path to normalize
  @@ -3319,7 +3360,7 @@
        * When you want to get each part of the userinfo, you need to use the
        * specific methods in the specific URL. It depends on the specific URL.
        *
  -     * @return URI character sequence
  +     * @return the URI character sequence
        */
       public char[] getRawURI() {
           return _uri;
  @@ -3330,7 +3371,7 @@
        * It can be gotten the URI character sequence. It's escaped.
        * For the purpose of the protocol to be transported, it will be useful.
        *
  -     * @return the URI string
  +     * @return the escaped URI string
        */
       public String getEscapedURI() {
           return (_uri == null) ? null : new String(_uri);
  @@ -3340,13 +3381,51 @@
       /**
        * It can be gotten the URI character sequence.
        *
  -     * @return the URI string
  -     * @exception URIException incomplete trailing escape pattern
  -     * Or unsupported character encoding
  +     * @return the original URI string
  +     * @exception URIException incomplete trailing escape pattern or unsupported
  +     * character encoding
        * @see #decode
        */
       public String getURI() throws URIException {
           return (_uri == null) ? null : decode(_uri);
  +    }
  +
  +
  +    /**
  +     * Get the URI reference character sequence.
  +     *
  +     * @return the URI reference character sequence
  +     */
  +    public char[] getRawURIReference() {
  +        if (_fragment == null) return _uri;
  +        if (_uri == null) return _fragment;
  +        // if _uri != null &&  _fragment != null
  +        String uriReference = new String(_uri) + "#" + new String(_fragment);
  +        return uriReference.toCharArray();
  +    }
  +
  +
  +    /**
  +     * Get the escaped URI reference string.
  +     *
  +     * @return the escaped URI reference string
  +     */
  +    public String getEscapedURIReference() {
  +        char[] uriReference = getRawURIReference();
  +        return (uriReference == null) ? null : new String(uriReference);
  +    }
  +
  +
  +    /**
  +     * Get the original URI reference string.
  +     *
  +     * @return the original URI reference string
  +     * @exception URIException
  +     * @see #decode
  +     */
  +    public String getURIReference() throws URIException {
  +        char[] uriReference = getRawURIReference();
  +        return (uriReference == null) ? null : decode(uriReference);
       }
   
   
  
  
  
  1.6       +6 -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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- URIException.java	3 Nov 2002 17:42:08 -0000	1.5
  +++ URIException.java	22 Dec 2002 16:06:08 -0000	1.6
  @@ -179,7 +179,7 @@
       /**
        * Set the reason code.
        *
  -     * @param the reason code
  +     * @param reasonCode the reason code
        */
       public void setReasonCode(int reasonCode) {
           this.reasonCode = reasonCode;
  @@ -199,7 +199,7 @@
       /**
        * Set the reason message.
        *
  -     * @param the reason message
  +     * @param reason the reason message
        */
       public void setReason(String reason) {
           this.reason = reason;
  
  
  

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