jericho     2002/06/16 09:46:31

  Modified:    src/util/org/apache/util URI.java
  Added:       src/util/org/apache/util URIException.java
  Log:
  - Add some documents related encoding thingys...
  - Specify the URIException and Unsupported encoding
    from obscure exception. (It should work with all version of JDK 1.2 above...)
  
  Revision  Changes    Path
  1.8       +256 -122  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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- URI.java  19 May 2002 18:12:16 -0000      1.7
  +++ URI.java  16 Jun 2002 16:46:31 -0000      1.8
  @@ -143,10 +143,13 @@
        * Construct a URI as an escaped form of a character array.
        *
        * @param escaped the URI character sequence
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        * @throws NullPointerException if <code>escaped</code> is <code>null</code>
  -     * @exception Exception
        */
  -    public URI(char[] escaped) throws Exception {
  +    public URI(char[] escaped)
  +        throws UnsupportedEncodingException, URIException {
  +
           parseUriReference(new String(escaped), true);
       }
   
  @@ -159,9 +162,12 @@
        *
        * @param original the string to be represented to URI character sequence
        * It is one of absoluteURI and relativeURI.
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        */
  -    public URI(String original) throws Exception {
  +    public URI(String original)
  +        throws UnsupportedEncodingException, URIException {
  +
           parseUriReference(original, false);
       }
   
  @@ -178,18 +184,21 @@
        * @param scheme the scheme string
        * @param scheme_specific_part scheme_specific_part
        * @param fragment the fragment string
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        */
       public URI(String scheme, String scheme_specific_part, String fragment)
  -    throws Exception {
  +        throws UnsupportedEncodingException, URIException {
  +
           // validate and contruct the URI character sequence
           if (scheme == null) {
  -           throw new IllegalArgumentException("scheme required");
  +           throw new URIException("scheme required");
           }
           char[] s = scheme.toLowerCase().toCharArray();
           if (validate(s, this.scheme)) {
               _scheme = s; // is_absoluteURI
           } else {
  -            throw new IllegalArgumentException("incorrect scheme");
  +            throw new URIException("incorrect scheme");
           }
           _opaque = encode(scheme_specific_part, allowed_opaque_part);
           // Set flag
  @@ -214,9 +223,12 @@
        * @param path the path string
        * @param query the query string
        * @param fragment the fragment string
  +     * @exception URIException
        */
       public URI(String scheme, String authority, String path, String query,
  -               String fragment) throws Exception {
  +               String fragment)
  +        throws UnsupportedEncodingException, URIException {
  +
           // validate and contruct the URI character sequence
           StringBuffer buff = new StringBuffer();
           if (scheme != null) {
  @@ -230,7 +242,7 @@
           if (path != null) {  // accept empty path
               if ((scheme != null || authority != null)
                       && !path.startsWith("/")) {
  -                throw new IllegalArgumentException("abs_path requested");
  +                throw new URIException("abs_path requested");
               }
               buff.append(path);
           }
  @@ -256,10 +268,13 @@
        * @param path the path string
        * @param query the query string
        * @param fragment the fragment string
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        */
       public URI(String scheme, String userinfo, String host, int port,
               String path, String query, String fragment)
  -        throws Exception {
  +        throws UnsupportedEncodingException, URIException {
  +
           this(scheme, (host == null) ? null :
                   ((userinfo != null) ? userinfo + '@' : "") + host +
                   ((port != -1) ? ":" + port : ""), path, query, fragment);
  @@ -273,9 +288,12 @@
        * @param host the host string
        * @param path the path string
        * @param fragment the fragment string
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        */
       public URI(String scheme, String host, String path, String fragment)
  -    throws Exception {
  +        throws UnsupportedEncodingException, URIException {
  +
           this(scheme, host, path, null, fragment);
       }
   
  @@ -328,10 +346,14 @@
        *
        * @param base the base URI
        * @param relative the relative URI
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        */
  -    public URI(URI base, URI relative) throws Exception {
  +    public URI(URI base, URI relative)
  +        throws UnsupportedEncodingException, URIException {
  +
           if (base._scheme == null) {
  -            throw new IllegalArgumentException("base URI required");
  +            throw new URIException("base URI required");
           }
           if (base._scheme != null) {
               this._scheme = base._scheme;
  @@ -347,6 +369,7 @@
           }
           if (relative._is_only_fragment) {
               this._fragment = relative._fragment;
  +            this._is_only_fragment = relative._is_only_fragment;
               this.setUriReference();
               return;
           }
  @@ -1327,22 +1350,34 @@
        *   original character sequence->octet sequence->URI character sequence
        * </pre></blockquote><p>
        *
  +     * Conversion from the local filesystem character set to UTF-8 will
  +     * normally involve a two step process. First convert the local character
  +     * set to the UCS; then convert the UCS to UTF-8.
  +     * The first step in the process can be performed by maintaining a mapping
  +     * table that includes the local character set code and the corresponding
  +     * UCS code.
  +     * The next step is to convert the UCS character code to the UTF-8 encoding.
  +     *
  +     * Mapping between vendor codepages can be done in a very similar manner
  +     * as described above.
  +     *
        * The only time escape encodings can allowedly be made is when a URI is
  -     * being created from its component parts.  The escape and validate method
  -     * might be performed in this method internally.
  +     * being created from its component parts.  The escape and validate methods
  +     * are internally performed within this method.
        *
        * @param original the original character sequence
        * @param allowed those characters that are allowed within a component
        * @return URI character sequence
  -     * @exception Exception 
  -     * if NullPointerException, null argument
  -     * if UnsupportedEncodingException, unsupported character encoding
  +     * @exception UnsupportedEncodingException unsupported character encoding
  +     * @exception URIException null component
        * @see escape
        */
  -    protected char[] encode(String original, BitSet allowed) throws Exception {
  +    protected char[] encode(String original, BitSet allowed)
  +        throws UnsupportedEncodingException, URIException {
  +
           // encode original to uri characters.
           if (original == null) {
  -            throw new NullPointerException("original");
  +            throw new URIException("original");
           }
           byte[] octet = original.getBytes(_documentCharset);
           return escape(octet, allowed);
  @@ -1358,17 +1393,25 @@
        *
        * A URI must be separated into its components before the escaped
        * characters within those components can be allowedly decoded.
  -     * The unescape method is performed in this method internally.
  +     *
  +     * Notice that there is a chance that URI characters that are non UTF-8
  +     * may be parsed as valid UTF-8.  A recent non-scientific analysis found
  +     * that EUC encoded Japanese words had a 2.7% false reading; SJIS had a
  +     * 0.0005% false reading; other encoding such as ASCII or KOI-8 have a 0%
  +     * false reading.
  +     *
  +     * The unescape method is internally performed within this method.
        *
        * @param octet the octet sequence
        * @return original character sequence
  -     * @exception Exception
  -     * if NullPointerException, null argument
  -     * if UnsupportedEncodingException, unsupported character encoding
  -     * if IllegalArgumentException, incomplete trailing escape pattern
  +     * @exception UnsupportedEncodingException unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern
  +     * @throws NullPointerException null argument
        * @see unescape
        */
  -    protected String decode(char[] uri) throws Exception {
  +    protected String decode(char[] uri)
  +        throws UnsupportedEncodingException, URIException {
  +
           // decode uri to original characters.
           return new String(unescape(uri), _documentCharset);
       }
  @@ -1388,17 +1431,18 @@
        * @param octet the octet sequence to be escaped
        * @param allowed those characters that are allowed within a component
        * @return URI character sequence
  -     * @exception Exception 
  -     * if NullPointerException, null argument
  -     * if UnsupportedEncodingException, unsupported character encoding
  +     * @exception UnsupportedEncodingException unsupported character encoding
  +     * @exception URIException
        */
  -    protected char[] escape(byte[] octet, BitSet allowed) throws Exception {
  +    protected char[] escape(byte[] octet, BitSet allowed)
  +        throws UnsupportedEncodingException, URIException {
  +
           // escape octet to uri characters.
           if (octet == null) {
  -            throw new NullPointerException("octet");
  +            throw new URIException("null octets");
           }
           if (allowed == null) {
  -            throw new NullPointerException("allowed characters");
  +            throw new URIException("null allowed characters");
           }
           String octets = new String(octet, _protocolCharset);
           char[] preuric = new char[octets.length()];
  @@ -1436,15 +1480,16 @@
        *
        * @param uri the URI character sequence
        * @return octet sequence
  -     * @exception Exception
  -     * if NullPointerException, null argument
  -     * if UnsupportedEncodingException, unsupported character encoding
  -     * if IllegalArgumentException, incomplete trailing escape pattern
  +     * @exception UnsupportedEncodingException unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern
  +     * @throws NullPointerException null argument
        */
  -    protected byte[] unescape(char[] uri) throws Exception {
  +    protected byte[] unescape(char[] uri)
  +        throws UnsupportedEncodingException, URIException {
  +
           // unescape uri characters to octets
           if (uri == null) {
  -            throw new NullPointerException("uri");
  +            throw new URIException("uri");
           }
           byte[] octet = new String(uri).getBytes(_protocolCharset);
           int oi = 0; // output index
  @@ -1454,7 +1499,7 @@
                   b = (byte) ((Character.digit((char) octet[ii++], 16) << 4) +
                   Character.digit((char) octet[ii++], 16));
                   if (b == -1) {
  -                    throw new IllegalArgumentException(
  +                    throw new URIException(
                               "incomplete trailing escape pattern");
                   }
               }
  @@ -1562,14 +1607,15 @@
        * @param original the original character sequence
        * @param escaped <code>true</code> if <code>original</code> is escaped
        * @return the original character sequence
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        */
       protected void parseUriReference(String original, boolean escaped)
  -    throws Exception {
  +        throws UnsupportedEncodingException, URIException {
  +
           // validate and contruct the URI character sequence
  -        
           if (original == null) {
  -            throw new IllegalArgumentException("URI-Reference required");
  +            throw new URIException("URI-Reference required");
           }
   
           /** @
  @@ -1619,7 +1665,7 @@
               if (validate(target, scheme)) {
                   _scheme = target;
               } else {
  -                throw new IllegalArgumentException("incorrect scheme");
  +                throw new URIException("incorrect scheme");
               }
               from = ++at;
           }
  @@ -1823,12 +1869,14 @@
        *
        * @param original the original character sequence of authority component
        * @param escaped <code>true</code> if <code>original</code> is escaped
  -     * @exception Exception
  -     * if NumberFormatException, port isn't integer
  -     * if IllegalArgumentException, incorrect Pv6reference or wrong host
  +     * @exception NumberFormatException port isn't integer
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException incorrect Pv6reference or wrong host
        */
       protected void parseAuthority(String original, boolean escaped)
  -    throws Exception {
  +        throws NumberFormatException, UnsupportedEncodingException,
  +               URIException {
  +
           // Reset flags
           _is_reg_name = _is_server =
           _is_hostname = _is_IPv4address = _is_IPv6reference = false;
  @@ -1845,7 +1893,7 @@
           if (next >= from) {
               next = original.indexOf(']', from);
               if (next == -1) {
  -                throw new IllegalArgumentException("IPv6reference");
  +                throw new URIException("IPv6reference");
               } else {
                   next++;
               }
  @@ -1910,7 +1958,7 @@
        *
        * @see getRawURI
        */
  -    protected void setUriReference() throws Exception {
  +    protected void setUriReference() {
           // set _uri
           StringBuffer buf = new StringBuffer();
           // ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
  @@ -2126,6 +2174,14 @@
       /**
        * Set the default charset of the protocol.
        *
  +     * The character set used to store files SHALL remain a local decision and
  +     * MAY depend on the capability of local operating systems. Prior to the
  +     * exchange of URIs they SHOULD be converted into a ISO/IEC 10646 format
  +     * and UTF-8 encoded. This approach, while allowing international exchange
  +     * of URIs, will still allow backward compatibility with older systems
  +     * because the code set positions for ASCII characters are identical to the
  +     * one byte sequence in UTF-8.
  +     *
        * An individual URI scheme may require a single charset, define a default
        * charset, or provide a way to indicate the charset used.
        *
  @@ -2142,6 +2198,12 @@
        * An individual URI scheme may require a single charset, define a default
        * charset, or provide a way to indicate the charset used.
        *
  +     * To work globally either requires support of a number of character sets
  +     * and to be able to convert between them, or the use of a single preferred
  +     * character set.
  +     * For support of global compatibility it is STRONGLY RECOMMENDED that
  +     * clients and servers use UTF-8 encoding when exchanging URIs.
  +     *
        * @return the charset string
        */
       public String getProtocolCharset() {
  @@ -2152,6 +2214,12 @@
       /**
        * Set the default charset of the document.
        *
  +     * Notice that it will be possible to contain mixed characters (e.g.
  +     * ftp://ChineseDirectoryName/KoreanFileName). To handle the Bi-directional
  +     * display of these character sets, the protocol charset could be simply
  +     * used again. Because it's not yet implemented that the insertion of BIDI
  +     * control characters at different points during composition is extracted.
  +     *
        * @param charset the default charset for the document
        */
       public void setDocumentCharset(String charset) {
  @@ -2184,6 +2252,7 @@
        * Get the scheme.
        *
        * @return the scheme
  +     * @throws NullPointerException undefined scheme
        */
       public String getScheme() {
           return new String(_scheme);
  @@ -2199,10 +2268,12 @@
        * </pre></blockquote><p>
        *
        * @param the authority
  -     * @exception Exception
  -     * UnsupportedEncodingException
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        */
  -    public void setAuthority(String authority) throws Exception {
  +    public void setAuthority(String authority)
  +        throws UnsupportedEncodingException, URIException {
  +
           parseAuthority(authority, false);
           setUriReference();
       }
  @@ -2232,10 +2303,13 @@
        * Get the authority.
        *
        * @return the authority
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        * @see decode
        */
  -    public String getAuthority() throws Exception {
  +    public String getAuthority()
  +        throws UnsupportedEncodingException, URIException {
  +
           return decode(_authority);
       }
   
  @@ -2267,11 +2341,14 @@
        * Get the userinfo.
        *
        * @return the userinfo
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        * @see decode
        * @see getAuthority
        */
  -    public String getUserinfo() throws Exception {
  +    public String getUserinfo()
  +        throws UnsupportedEncodingException, URIException {
  +
           return decode(_userinfo);
       }
   
  @@ -2298,11 +2375,14 @@
        * </pre></blockquote><p>
        *
        * @return the host
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        * @see decode
        * @see getAuthority
        */
  -    public String getHost() throws Exception {
  +    public String getHost()
  +        throws UnsupportedEncodingException, URIException {
  +
           return decode(_host);
       }
   
  @@ -2327,11 +2407,13 @@
        * Set the path.   The method couldn't be used by API programmers.
        *
        * @param path the path string
  -     * @exception Exception
  -     * if IllegalArgumentException, set incorrectly or fragment only
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException set incorrectly or fragment only
        * @see encode
        */
  -    protected void setPath(String path) throws Exception {
  +    protected void setPath(String path)
  +        throws UnsupportedEncodingException, URIException {
  +
           // set path
           if (_is_net_path || _is_abs_path) {
               _path = encode(path, allowed_abs_path);
  @@ -2348,7 +2430,7 @@
           } else if (_is_opaque_part) {
               _opaque = encode(path, allowed_opaque_part);
           } else {
  -            throw new IllegalArgumentException("incorrect path");
  +            throw new URIException("incorrect path");
           }
       }
   
  @@ -2361,6 +2443,7 @@
        * @return the resolved path
        */
       protected char[] resolvePath(char[] base_path, char[] rel_path) {
  +
           // REMINDME: paths are never null
           String base = new String(base_path);
           int at = base.lastIndexOf('/');
  @@ -2389,16 +2472,17 @@
        *
        * @param path the path
        * @return the current hierarchy level
  -     * @exception Exception
  -     * if IllegalArgumentException, no hierarchy level
  -     * if NullPointerException, null argument
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException no hierarchy level
        */
  -    protected char[] getRawCurrentHierPath(char[] path) throws Exception {
  +    protected char[] getRawCurrentHierPath(char[] path)
  +        throws UnsupportedEncodingException, URIException {
  +
           if (_is_opaque_part) {
  -            throw new IllegalArgumentException("no hierarchy level");
  +            throw new URIException("no hierarchy level");
           }
           if (path == null) {
  -            throw new NullPointerException("null argument");
  +            throw new URIException("emtpy path");
           }
           String buff = new String(path);
           int first = buff.indexOf('/');
  @@ -2415,9 +2499,12 @@
        * Get the raw-escaped current hierarchy level.
        *
        * @return the raw-escaped current hierarchy level
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException no hierarchy level
        */
  -    public char[] getRawCurrentHierPath() throws Exception {
  +    public char[] getRawCurrentHierPath()
  +        throws UnsupportedEncodingException, URIException {
  +
           return getRawCurrentHierPath(_path);
       }
    
  @@ -2426,9 +2513,12 @@
        * Get the escaped current hierarchy level.
        *
        * @return the escaped current hierarchy level
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException no hierarchy level
        */
  -    public String getEscapedCurrentHierPath() throws Exception {
  +    public String getEscapedCurrentHierPath()
  +        throws UnsupportedEncodingException, URIException {
  +
           return new String(getRawCurrentHierPath());
       }
    
  @@ -2437,10 +2527,13 @@
        * Get the current hierarchy level.
        *
        * @return the current hierarchy level
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        * @see decode
        */
  -    public String getCurrentHierPath() throws Exception {
  +    public String getCurrentHierPath()
  +        throws UnsupportedEncodingException, URIException {
  +
           return decode(getRawCurrentHierPath());
       }
   
  @@ -2449,9 +2542,12 @@
        * Get the level above the this hierarchy level.
        *
        * @return the raw above hierarchy level
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        */
  -    public char[] getRawAboveHierPath() throws Exception {
  +    public char[] getRawAboveHierPath()
  +        throws UnsupportedEncodingException, URIException {
  +
           return getRawCurrentHierPath(getRawCurrentHierPath());
       }
   
  @@ -2460,9 +2556,12 @@
        * Get the level above the this hierarchy level.
        *
        * @return the raw above hierarchy level
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        */
  -    public String getEscapedAboveHierPath() throws Exception {
  +    public String getEscapedAboveHierPath()
  +        throws UnsupportedEncodingException, URIException {
  +
           return new String(getRawAboveHierPath());
       }
   
  @@ -2471,10 +2570,13 @@
        * Get the level above the this hierarchy level.
        *
        * @return the above hierarchy level
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        * @see decode
        */
  -    public String getAboveHierPath() throws Exception {
  +    public String getAboveHierPath()
  +        throws UnsupportedEncodingException, URIException {
  +
           return decode(getRawAboveHierPath());
       }
   
  @@ -2484,6 +2586,7 @@
        * <p><blockquote><pre>
        *   path          = [ abs_path | opaque_part ]
        * </pre></blockquote><p>
  +     *
        * @return the raw-escaped path
        */
       public char[] getRawPath() {
  @@ -2512,10 +2615,13 @@
        *   path          = [ abs_path | opaque_part ]
        * </pre></blockquote><p>
        * @return the path string
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException
  +     * @exception URIException
        * @see decode
        */
  -    public String getPath() throws Exception {
  +    public String getPath()
  +        throws UnsupportedEncodingException, URIException {
  +
           return decode(getRawPath());
       }
   
  @@ -2526,6 +2632,7 @@
        * @return the raw-escaped basename
        */
       public char[] getRawName() {
  +
           if (_path == null || _path.length == 0) {
               return _path;
           }
  @@ -2558,10 +2665,13 @@
        * Get the basename of the path.
        *
        * @return the basename string
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern
        * @see decode
        */
  -    public String getName() throws Exception {
  +    public String getName()
  +        throws UnsupportedEncodingException, URIException {
  +
           char[] basename = getRawName();
           return (basename == null) ? null : decode(getRawName());
       }
  @@ -2572,11 +2682,14 @@
        * Get the raw-escaped path and query.
        *
        * @return the raw-escaped path and query
  -     * @exception NullPointerException path undefined
  +     * @exception URIException path undefined
        */
  -    public char[] getRawPathQuery() {
  +    public char[] getRawPathQuery()
  +        throws URIException {
  +
  +        // path is never empty
           if (_path == null) {
  -            throw new NullPointerException("path undefined");
  +            throw new URIException("path undefined");
           }
           int len = _path.length;
           if (_query != null) {
  @@ -2596,9 +2709,11 @@
        * Get the escaped query.
        *
        * @return the escaped path and query string
  -     * @exception NullPointerException path undefined
  +     * @exception URIException path undefined
        */
  -    public String getEscapedPathQuery() {
  +    public String getEscapedPathQuery()
  +        throws URIException {
  +
           return new String(getRawPathQuery());
       }
   
  @@ -2607,10 +2722,13 @@
        * Get the path and query.
        *
        * @return the path and query string.
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern
        * @see decode
        */
  -    public String getPathQuery() throws Exception {
  +    public String getPathQuery()
  +        throws UnsupportedEncodingException, URIException {
  +
           return decode(getRawPathQuery());
       }
   
  @@ -2619,11 +2737,15 @@
       /**
        * Set the query.
        *
  -     * @param the query string.
  -     * @exception Exception
  +     * @param query the query string.
  +     * @exception UnsupportedEncodingException unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern
  +     * @throws NullPointerException null query
        * @see encode
        */
  -    public void setQuery(String query) throws Exception {
  +    public void setQuery(String query)
  +        throws UnsupportedEncodingException, URIException {
  +
           _query = encode(query, allowed_query);
           setUriReference();
       }
  @@ -2643,6 +2765,7 @@
        * Get the escaped query.
        *
        * @return the escaped query string
  +     * @throws NullPointerException undefined query
        */
       public String getEscapedQuery() {
           return new String(_query);
  @@ -2653,10 +2776,14 @@
        * Get the query.
        *
        * @return the query string.
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern
  +     * @throws NullPointerException undefined query
        * @see decode
        */
  -    public String getQuery() throws Exception {
  +    public String getQuery()
  +        throws UnsupportedEncodingException, URIException {
  +
           return decode(_query);
       }
   
  @@ -2669,10 +2796,13 @@
        * and should be replaced by that URI when transformed into a request.
        *
        * @param the fragment string.
  -     * @exception Exception
  -     * UnsupportedEncodingException
  +     * @exception UnsupportedEncodingException unsupported character encoding
  +     * @exception URIException
  +     * @throws NullPointerException null fragment
        */
  -    public void setFragment(String fragment) throws Exception {
  +    public void setFragment(String fragment)
  +        throws UnsupportedEncodingException, URIException {
  +
           _fragment = encode(fragment, allowed_fragment);
           setUriReference();
       }
  @@ -2702,6 +2832,7 @@
        * Get the escaped fragment.
        *
        * @return the escaped fragment string
  +     * @throws NullPointerException undefined fragment
        */
       public String getEscapedFragment() {
           return new String(_fragment);
  @@ -2712,10 +2843,14 @@
        * Get the fragment.
        *
        * @return the fragment string
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern
  +     * @throws NullPointerException undefined fragment
        * @see decode
        */
  -    public String getFragment() throws Exception {
  +    public String getFragment()
  +        throws UnsupportedEncodingException, URIException {
  +
           return decode(_fragment);
       }
   
  @@ -2728,6 +2863,7 @@
        * @return the normalized path
        */
       protected char[] normalize(char[] path) {
  +
           if (path == null) {
               return null;
           }
  @@ -2814,6 +2950,7 @@
        * @return true if they're equal
        */
       protected boolean equals(char[] first, char[] second) {
  +
           if (first == null && second == null) {
               return true;
           }
  @@ -2839,6 +2976,7 @@
        * @return true if two URI objects are equal
        */
       public boolean equals(Object obj) {
  +
           // normalize and test each components
           if (obj == this) {
               return true;
  @@ -2883,7 +3021,8 @@
        * @param oos the object-output stream
        */
       protected void writeObject(java.io.ObjectOutputStream oos)
  -    throws IOException {
  +        throws IOException {
  +
           oos.defaultWriteObject();
       }
   
  @@ -2894,7 +3033,8 @@
        * @param ois the object-input stream
        */
       protected void readObject(java.io.ObjectInputStream ois)
  -    throws ClassNotFoundException, IOException {
  +        throws ClassNotFoundException, IOException {
  +
           ois.defaultReadObject();
       }
   
  @@ -2909,6 +3049,7 @@
        * @exception NullPointerException character encoding error or null object
        */
       public int compareTo(Object obj) {
  +
           URI another = (URI) obj;
           return toString().compareTo(another.toString());
       }
  @@ -2950,31 +3091,24 @@
        * It can be gotten the URI character sequence.
        *
        * @return the URI string
  -     * @exception Exception
  +     * @exception UnsupportedEncodingException unsupported character encoding
  +     * @exception URIException incomplete trailing escape pattern
        * @see decode
        */
  -    public String getURI() throws Exception {
  +    public String getURI()
  +        throws UnsupportedEncodingException, URIException {
  +
           return decode(_uri);
       }
   
   
       /**
  -     * Get the escaped URI string.  It doesn't throw any exception.
  -     * However, if there is an error, null is returned.
  +     * Get the escaped URI string.
        *
        * @return the escaped URI string
  -     * if null, error
        */
       public String toString() {
  -        String s = null;
  -        try {
  -            s = getURI();
  -        } catch (Throwable t) {
  -            if (debug > 0) {
  -                t.getMessage();
  -            }
  -        } 
  -        return s;
  +        return getEscapedURI();
       }
   
   }
  
  
  
  1.1                  jakarta-slide/src/util/org/apache/util/URIException.java
  
  Index: URIException.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-slide/src/util/org/apache/util/URIException.java,v 1.1 
2002/06/16 16:46:31 jericho Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/16 16:46:31 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 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", "Slide", 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 [EMAIL PROTECTED]
   *
   * 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.util;
  
  /**
   * The URI parsing and escape encoding exception.
   *
   * @author <a href="mailto:jericho at apache.org">Sung-Gu</a>
   * @version $Revision: 1.1 $ $Date: 2002/03/14 15:14:01 
   */
  
  public class URIException extends Exception {
  
      /**
       * The constructor.
       *
       * @param reason the reason
       */
      public URIException(String reason) {
          super(reason);
      }
  }
  
  
  

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

Reply via email to