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/11/03 18:42:08 UTC
cvs commit: jakarta-slide/src/util/org/apache/util URIException.java URI.java
jericho 2002/11/03 09:42:08
Modified: src/util/org/apache/util URIException.java URI.java
Log:
URI: support URI constructors being placed within double-quotes or angle
brackets like "http://test.com/" and <http://test.com/>
URI: add the setXxxQuery and setXxxFragment methods to support escaped
query and fragment... mostly for developer serviceableness.
URI: add bitset for allowed_within_userinfo, within_userinfo
URI: add setXxxAuthority methods instead of setAuthority
URI: fix a bug of offset range computation for validate method
URI: fix to set query without path
ESLE: add javadoc messages.
Revision Changes Path
1.5 +13 -4 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- URIException.java 9 Oct 2002 12:47:19 -0000 1.4
+++ URIException.java 3 Nov 2002 17:42:08 -0000 1.5
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 the Apache Software Foundation. All rights
+ * Copyright (c) 2002 the Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -127,20 +127,29 @@
*/
public static final int UNKNOWN = 0;
+
/**
* The URI parsing error.
*/
public static final int PARSING = 1;
+
/**
* The unsupported character encoding.
*/
public static final int UNSUPPORTED_ENCODING = 2;
+
/**
- * The URI escape or unescape error.
+ * The URI escape encoding and decoding error.
*/
public static final int ESCAPING = 3;
+
+
+ /**
+ * The DNS punycode encoding or decoding error.
+ */
+ public static final int PUNYCODE = 4;
// ------------------------------------------------------------- properties
1.22 +280 -88 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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- URI.java 9 Oct 2002 12:49:19 -0000 1.21
+++ URI.java 3 Nov 2002 17:42:08 -0000 1.22
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 the Apache Software Foundation. All rights
+ * Copyright (c) 2002 the Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -143,10 +143,9 @@
* - String getXXX() // method
* </pre><p>
*
- * @author <a href="mailto:jericho@apache.org">Sung-Gu</a>
+ * @author <a href="mailto:jericho at apache.org">Sung-Gu</a>
* @version $Revision$ $Date: 2002/03/14 15:14:01
*/
-
public class URI implements Cloneable, Comparable, Serializable {
@@ -157,7 +156,9 @@
/**
* Construct a URI as an escaped form of a character array.
- *
+ * An URI can be placed within double-quotes or angle brackets like
+ * "http://test.com/" and <http://test.com/>
+ *
* @param escaped the URI character sequence
* @exception URIException
* @throws NullPointerException if <code>escaped</code> is <code>null</code>
@@ -172,6 +173,8 @@
* <p><blockquote><pre>
* URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
* </pre></blockquote><p>
+ * An URI can be placed within double-quotes or angle brackets like
+ * "http://test.com/" and <http://test.com/>
*
* @param original the string to be represented to URI character sequence
* It is one of absoluteURI and relativeURI.
@@ -189,7 +192,8 @@
* absoluteURI = scheme ":" ( hier_part | opaque_part )
* opaque_part = uric_no_slash *uric
* </pre></blockquote><p>
- * It's for absolute URI = <scheme>:<scheme-specific-part>#<fragment>
+ * It's for absolute URI = <scheme>:<scheme-specific-part>#
+ * <fragment>.
*
* @param scheme the scheme string
* @param scheme_specific_part scheme_specific_part
@@ -224,8 +228,9 @@
* relativeURI = ( net_path | abs_path | rel_path ) [ "?" query ]
* hier_part = ( net_path | abs_path ) [ "?" query ]
* </pre></blockquote><p>
- * It's for absolute URI = <scheme>:<path>?<query>#<fragment> and
- * relative URI = <path>?<query>#<fragment>
+ * It's for absolute URI = <scheme>:<path>?<query>#<
+ * fragment> and relative URI = <path>?<query>#<fragment
+ * >.
*
* @param scheme the scheme string
* @param authority the authority string
@@ -585,12 +590,6 @@
*/
protected static char[] rootPath = { '/' };
-
- /**
- * The debug.
- */
- protected static int debug = 0;
-
// ---------------------- Generous characters for each component validation
/**
@@ -606,6 +605,7 @@
/**
+ * BitSet for digit.
* <p><blockquote><pre>
* digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
* "8" | "9"
@@ -614,13 +614,14 @@
protected static final BitSet digit = new BitSet(256);
// Static initializer for digit
static {
- for(int i='0';i<='9';i++) {
+ for(int i = '0'; i <= '9'; i++) {
digit.set(i);
}
}
/**
+ * BitSet for alpha.
* <p><blockquote><pre>
* alpha = lowalpha | upalpha
* </pre></blockquote><p>
@@ -628,16 +629,17 @@
protected static final BitSet alpha = new BitSet(256);
// Static initializer for alpha
static {
- for (int i = 'a'; i <= 'z';i++) {
+ for (int i = 'a'; i <= 'z'; i++) {
alpha.set(i);
}
- for (int i = 'A'; i <= 'Z';i++) {
+ for (int i = 'A'; i <= 'Z'; i++) {
alpha.set(i);
}
}
/**
+ * BitSet for alphanum (join of alpha & digit).
* <p><blockquote><pre>
* alphanum = alpha | digit
* </pre></blockquote><p>
@@ -651,6 +653,7 @@
/**
+ * BitSet for hex.
* <p><blockquote><pre>
* hex = digit | "A" | "B" | "C" | "D" | "E" | "F" |
* "a" | "b" | "c" | "d" | "e" | "f"
@@ -660,16 +663,17 @@
// Static initializer for hex
static {
hex.or(digit);
- for(int i='a';i<='f';i++) {
+ for(int i = 'a'; i <= 'f'; i++) {
hex.set(i);
}
- for(int i='A';i<='F';i++) {
+ for(int i = 'A'; i <= 'F'; i++) {
hex.set(i);
}
}
/**
+ * BitSet for escaped.
* <p><blockquote><pre>
* escaped = "%" hex hex
* </pre></blockquote><p>
@@ -683,6 +687,7 @@
/**
+ * BitSet for mark.
* <p><blockquote><pre>
* mark = "-" | "_" | "." | "!" | "~" | "*" | "'" |
* "(" | ")"
@@ -719,8 +724,9 @@
/**
+ * BitSet for reserved.
* <p><blockquote><pre>
- * reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
+ * reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
* "$" | ","
* </pre></blockquote><p>
*/
@@ -741,6 +747,7 @@
/**
+ * BitSet for uric.
* <p><blockquote><pre>
* uric = reserved | unreserved | escaped
* </pre></blockquote><p>
@@ -755,6 +762,7 @@
/**
+ * BitSet for fragment (alias for uric).
* <p><blockquote><pre>
* fragment = *uric
* </pre></blockquote><p>
@@ -763,6 +771,7 @@
/**
+ * BitSet for query (alias for uric).
* <p><blockquote><pre>
* query = *uric
* </pre></blockquote><p>
@@ -771,9 +780,10 @@
/**
+ * BitSet for pchar.
* <p><blockquote><pre>
* pchar = unreserved | escaped |
- * ":" | "@" | "&" | "=" | "+" | "$" | ","
+ * ":" | "@" | "&" | "=" | "+" | "$" | ","
* </pre></blockquote><p>
*/
protected static final BitSet pchar = new BitSet(256);
@@ -792,6 +802,7 @@
/**
+ * BitSet for param (alias for pchar).
* <p><blockquote><pre>
* param = *pchar
* </pre></blockquote><p>
@@ -800,6 +811,7 @@
/**
+ * BitSet for segment.
* <p><blockquote><pre>
* segment = *pchar *( ";" param )
* </pre></blockquote><p>
@@ -814,6 +826,7 @@
/**
+ * BitSet for path segments.
* <p><blockquote><pre>
* path_segments = segment *( "/" segment )
* </pre></blockquote><p>
@@ -827,6 +840,7 @@
/**
+ * URI absolute path.
* <p><blockquote><pre>
* abs_path = "/" path_segments
* </pre></blockquote><p>
@@ -840,9 +854,10 @@
/**
+ * URI bitset for encoding typical non-slash characters.
* <p><blockquote><pre>
* uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" |
- * "&" | "=" | "+" | "$" | ","
+ * "&" | "=" | "+" | "$" | ","
* </pre></blockquote><p>
*/
protected static final BitSet uric_no_slash = new BitSet(256);
@@ -863,6 +878,7 @@
/**
+ * URI bitset that combines uric_no_slash and uric.
* <p><blockquote><pre>
* opaque_part = uric_no_slash *uric
* </pre></blockquote><p>
@@ -876,6 +892,7 @@
/**
+ * URI bitset that combines absolute path and opaque part.
* <p><blockquote><pre>
* path = [ abs_path | opaque_part ]
* </pre></blockquote><p>
@@ -889,12 +906,13 @@
/**
- * port
+ * Port, a logical alias for digit.
*/
protected static final BitSet port = digit;
/**
+ * Bitset that combines digit and dot fo IPv$address.
* <p><blockquote><pre>
* IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*digit
* </pre></blockquote><p>
@@ -908,7 +926,7 @@
/**
- * RFC 2373
+ * RFC 2373.
* <p><blockquote><pre>
* IPv6address = hexpart [ ":" IPv4address ]
* </pre></blockquote><p>
@@ -923,7 +941,7 @@
/**
- * RFC 2732, 2373
+ * RFC 2732, 2373.
* <p><blockquote><pre>
* IPv6reference = "[" IPv6address "]"
* </pre></blockquote><p>
@@ -938,6 +956,7 @@
/**
+ * BitSet for toplabel.
* <p><blockquote><pre>
* toplabel = alpha | alpha *( alphanum | "-" ) alphanum
* </pre></blockquote><p>
@@ -951,6 +970,7 @@
/**
+ * BitSet for domainlabel.
* <p><blockquote><pre>
* domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
* </pre></blockquote><p>
@@ -959,6 +979,7 @@
/**
+ * BitSet for hostname.
* <p><blockquote><pre>
* hostname = *( domainlabel "." ) toplabel [ "." ]
* </pre></blockquote><p>
@@ -973,6 +994,7 @@
/**
+ * BitSet for host.
* <p><blockquote><pre>
* host = hostname | IPv4address | IPv6reference
* </pre></blockquote><p>
@@ -987,6 +1009,7 @@
/**
+ * BitSet for hostport.
* <p><blockquote><pre>
* hostport = host [ ":" port ]
* </pre></blockquote><p>
@@ -1001,9 +1024,10 @@
/**
+ * Bitset for userinfo.
* <p><blockquote><pre>
* userinfo = *( unreserved | escaped |
- * ";" | ":" | "&" | "=" | "+" | "$" | "," )
+ * ";" | ":" | "&" | "=" | "+" | "$" | "," )
* </pre></blockquote><p>
*/
protected static final BitSet userinfo = new BitSet(256);
@@ -1022,6 +1046,22 @@
/**
+ * BitSet for within the userinfo component like user and password.
+ */
+ public static final BitSet within_userinfo = new BitSet(256);
+ // Static initializer for within_userinfo
+ static {
+ within_userinfo.or(userinfo);
+ within_userinfo.clear(';'); // reserved within authority
+ within_userinfo.clear(':');
+ within_userinfo.clear('@');
+ within_userinfo.clear('?');
+ within_userinfo.clear('/');
+ }
+
+
+ /**
+ * Bitset for server.
* <p><blockquote><pre>
* server = [ [ userinfo "@" ] hostport ]
* </pre></blockquote><p>
@@ -1036,9 +1076,10 @@
/**
+ * BitSet for reg_name.
* <p><blockquote><pre>
* reg_name = 1*( unreserved | escaped | "$" | "," |
- * ";" | ":" | "@" | "&" | "=" | "+" )
+ * ";" | ":" | "@" | "&" | "=" | "+" )
* </pre></blockquote><p>
*/
protected static final BitSet reg_name = new BitSet(256);
@@ -1058,6 +1099,7 @@
/**
+ * BitSet for authority.
* <p><blockquote><pre>
* authority = server | reg_name
* </pre></blockquote><p>
@@ -1071,6 +1113,7 @@
/**
+ * BitSet for scheme.
* <p><blockquote><pre>
* scheme = alpha *( alpha | digit | "+" | "-" | "." )
* </pre></blockquote><p>
@@ -1087,9 +1130,10 @@
/**
+ * BitSet for rel_segment.
* <p><blockquote><pre>
* rel_segment = 1*( unreserved | escaped |
- * ";" | "@" | "&" | "=" | "+" | "$" | "," )
+ * ";" | "@" | "&" | "=" | "+" | "$" | "," )
* </pre></blockquote><p>
*/
protected static final BitSet rel_segment = new BitSet(256);
@@ -1108,6 +1152,7 @@
/**
+ * BitSet for rel_path.
* <p><blockquote><pre>
* rel_path = rel_segment [ abs_path ]
* </pre></blockquote><p>
@@ -1121,6 +1166,7 @@
/**
+ * BitSet for net_path.
* <p><blockquote><pre>
* net_path = "//" authority [ abs_path ]
* </pre></blockquote><p>
@@ -1135,6 +1181,7 @@
/**
+ * BitSet for hier_part.
* <p><blockquote><pre>
* hier_part = ( net_path | abs_path ) [ "?" query ]
* </pre></blockquote><p>
@@ -1150,6 +1197,7 @@
/**
+ * BitSet for relativeURI.
* <p><blockquote><pre>
* relativeURI = ( net_path | abs_path | rel_path ) [ "?" query ]
* </pre></blockquote><p>
@@ -1166,6 +1214,7 @@
/**
+ * BitSet for absoluteURI.
* <p><blockquote><pre>
* absoluteURI = scheme ":" ( hier_part | opaque_part )
* </pre></blockquote><p>
@@ -1181,6 +1230,7 @@
/**
+ * BitSet for URI-reference.
* <p><blockquote><pre>
* URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
* </pre></blockquote><p>
@@ -1198,7 +1248,7 @@
// Excluded US-ASCII Characters are like control, space, delims and unwise
/**
- * control
+ * BitSet for control.
*/
public static final BitSet control = new BitSet(256);
// Static initializer for control
@@ -1210,7 +1260,7 @@
}
/**
- * space
+ * BitSet for space.
*/
public static final BitSet space = new BitSet(256);
// Static initializer for space
@@ -1220,7 +1270,7 @@
/**
- * delims
+ * BitSet for delims.
*/
public static final BitSet delims = new BitSet(256);
// Static initializer for delims
@@ -1234,7 +1284,7 @@
/**
- * unwise
+ * BitSet for unwise.
*/
public static final BitSet unwise = new BitSet(256);
// Static initializer for unwise
@@ -1251,7 +1301,7 @@
/**
- * disallowed rel_path before escaping
+ * Disallowed rel_path before escaping.
*/
public static final BitSet disallowed_rel_path = new BitSet(256);
// Static initializer for disallowed_rel_path
@@ -1262,7 +1312,7 @@
/**
- * disallowed opaque_part before escaping
+ * Disallowed opaque_part before escaping.
*/
public static final BitSet disallowed_opaque_part = new BitSet(256);
// Static initializer for disallowed_opaque_part
@@ -1271,10 +1321,10 @@
disallowed_opaque_part.andNot(opaque_part);
}
- // ------------------------------- Characters allowed within each component
+ // ----------------------- Characters allowed within and for each component
/**
- * Those characters that are allowed within the authority component.
+ * Those characters that are allowed for the authority component.
*/
public static final BitSet allowed_authority = new BitSet(256);
// Static initializer for allowed_authority
@@ -1285,7 +1335,7 @@
/**
- * Those characters that are allowed within the opaque_part.
+ * Those characters that are allowed for the opaque_part.
*/
public static final BitSet allowed_opaque_part = new BitSet(256);
// Static initializer for allowed_opaque_part
@@ -1296,7 +1346,7 @@
/**
- * Those characters that are allowed within the reg_name.
+ * Those characters that are allowed for the reg_name.
*/
public static final BitSet allowed_reg_name = new BitSet(256);
// Static initializer for allowed_reg_name
@@ -1308,7 +1358,7 @@
/**
- * Those characters that are allowed within the userinfo component.
+ * Those characters that are allowed for the userinfo component.
*/
public static final BitSet allowed_userinfo = new BitSet(256);
// Static initializer for allowed_userinfo
@@ -1320,8 +1370,19 @@
/**
- * Those characters that are allowed within the IPv6reference component.
- * '[', ']' in IPv6reference should be excluded.
+ * Those characters that are allowed for within the userinfo component.
+ */
+ public static final BitSet allowed_within_userinfo = new BitSet(256);
+ // Static initializer for allowed_within_userinfo
+ static {
+ allowed_within_userinfo.or(within_userinfo);
+ allowed_within_userinfo.clear('%');
+ }
+
+
+ /**
+ * Those characters that are allowed for the IPv6reference component.
+ * The characters '[', ']' in IPv6reference should be excluded.
*/
public static final BitSet allowed_IPv6reference = new BitSet(256);
// Static initializer for allowed_IPv6reference
@@ -1334,8 +1395,8 @@
/**
- * Those characters that are allowed within the host component.
- * '[', ']' in IPv6reference should be excluded.
+ * Those characters that are allowed for the host component.
+ * The characters '[', ']' in IPv6reference should be excluded.
*/
public static final BitSet allowed_host = new BitSet(256);
// Static initializer for allowed_host
@@ -1346,7 +1407,23 @@
/**
- * Those characters that are allowed within the abs_path.
+ * Those characters that are allowed for the authority component.
+ */
+ public static final BitSet allowed_within_authority = new BitSet(256);
+ // Static initializer for allowed_within_authority
+ static {
+ allowed_within_authority.or(server);
+ allowed_within_authority.or(reg_name);
+ allowed_within_authority.clear(';');
+ allowed_within_authority.clear(':');
+ allowed_within_authority.clear('@');
+ allowed_within_authority.clear('?');
+ allowed_within_authority.clear('/');
+ }
+
+
+ /**
+ * Those characters that are allowed for the abs_path.
*/
public static final BitSet allowed_abs_path = new BitSet(256);
// Static initializer for allowed_abs_path
@@ -1358,7 +1435,7 @@
/**
- * Those characters that are allowed within the rel_path.
+ * Those characters that are allowed for the rel_path.
*/
public static final BitSet allowed_rel_path = new BitSet(256);
// Static initializer for allowed_rel_path
@@ -1369,7 +1446,21 @@
/**
- * Those characters that are allowed within the query component.
+ * Those characters that are allowed within the path.
+ */
+ public static final BitSet allowed_within_path = new BitSet(256);
+ // Static initializer for allowed_within_path
+ static {
+ allowed_within_path.or(abs_path);
+ allowed_within_path.clear('/');
+ allowed_within_path.clear(';');
+ allowed_within_path.clear('=');
+ allowed_within_path.clear('?');
+ }
+
+
+ /**
+ * Those characters that are allowed for the query component.
*/
public static final BitSet allowed_query = new BitSet(256);
// Static initializer for allowed_query
@@ -1380,7 +1471,19 @@
/**
- * Those characters that are allowed within the fragment component.
+ * Those characters that are allowed within the query component.
+ */
+ public static final BitSet allowed_within_query = new BitSet(256);
+ // Static initializer for allowed_within_query
+ static {
+ allowed_within_query.or(allowed_query);
+ allowed_within_query.andNot(reserved); // excluded 'reserved'
+ allowed_within_query.clear('#'); // avoid confict with the fragment
+ }
+
+
+ /**
+ * Those characters that are allowed for the fragment component.
*/
public static final BitSet allowed_fragment = new BitSet(256);
// Static initializer for allowed_fragment
@@ -1428,6 +1531,8 @@
/**
+ * Encodes URI string.
+ *
* This is a two mapping, one from original characters to octets, and
* subsequently a second from octets to URI characters:
* <p><blockquote><pre>
@@ -1511,6 +1616,8 @@
/**
+ * Decodes URI encoded string.
+ *
* This is a two mapping, one from URI characters to octets, and
* subsequently a second from octets to original characters:
* <p><blockquote><pre>
@@ -1632,6 +1739,7 @@
* if -1, it means the length of the component
* @param generous those characters that are allowed within a component
* @return if true, it's the correct URI character sequence
+ * @throws NullPointerException null component
*/
protected boolean validate(char[] component, int soffset, int eoffset,
BitSet generous) {
@@ -1639,9 +1747,8 @@
if (eoffset == -1) {
eoffset = component.length -1;
}
- for (int i = soffset; i < eoffset; i++) {
- if (!generous.get(component[i]))
- return false;
+ for (int i = soffset; i <= eoffset; i++) {
+ if (!generous.get(component[i])) return false;
}
return true;
}
@@ -1659,14 +1766,14 @@
* 12 3 4 5 6 7 8 9
* </pre></blockquote><p>
* For example, matching the above expression to
- * http://jakarta.apache.org/slide/ietf/uri/#Related
+ * http://jakarta.apache.org/ietf/uri/#Related
* results in the following subexpression matches:
* <p><blockquote><pre>
* $1 = http:
* scheme = $2 = http
* $3 = //jakarta.apache.org
* authority = $4 = jakarta.apache.org
- * path = $5 = /slide/ietf/uri/
+ * path = $5 = /ietf/uri/
* $6 = <undefined>
* query = $7 = <undefined>
* $8 = #Related
@@ -1682,7 +1789,7 @@
throws URIException {
// validate and contruct the URI character sequence
- if (original == null) {
+ if (original == null || original.length() == 0) {
throw new URIException("URI-Reference required");
}
@@ -1690,6 +1797,26 @@
* ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
*/
String tmp = original.trim();
+
+ /**
+ * The length of the string sequence of characters.
+ * It may not be equal to the length of the byte array.
+ */
+ int length = tmp.length();
+
+ /**
+ * Remove the delimiters like angle brackets around an URI.
+ */
+ char[] firstDelimiter = { tmp.charAt(0) };
+ if (validate(firstDelimiter, delims)) {
+ if (length >= 2) {
+ char[] lastDelimiter = { tmp.charAt(length - 1) };
+ if (validate(lastDelimiter, delims)) {
+ tmp = tmp.substring(1, length - 1);
+ length = length - 2;
+ }
+ }
+ }
/**
* The starting index
@@ -1716,12 +1843,7 @@
if (at == -1) at = 0;
/**
- * The length of the sequence of characters.
- * It may not be equal to the length of the byte array.
- */
- int length = tmp.length();
-
- /**
+ * Parse the scheme.
* <p><blockquote><pre>
* scheme = $2 = http
* @
@@ -1739,6 +1861,7 @@
}
/**
+ * Parse the authority component.
* <p><blockquote><pre>
* authority = $4 = jakarta.apache.org
* @@
@@ -1769,8 +1892,9 @@
}
/**
+ * Parse the path component.
* <p><blockquote><pre>
- * path = $5 = /slide/ietf/uri/
+ * path = $5 = /ietf/uri/
* @@@@@@
* ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
* </pre></blockquote><p>
@@ -1804,6 +1928,7 @@
}
/**
+ * Parse the query component.
* <p><blockquote><pre>
* query = $7 = <undefined>
* @@@@@@@@@
@@ -1821,6 +1946,7 @@
}
/**
+ * Parse the fragment component.
* <p><blockquote><pre>
* fragment = $9 = Related
* @@@@@@@@
@@ -2054,10 +2180,10 @@
if (_path.length != 0) {
buf.append(_path);
}
- if (_query != null) { // has_query
- buf.append('?');
- buf.append(_query);
- }
+ }
+ if (_query != null) { // has_query
+ buf.append('?');
+ buf.append(_query);
}
if (_fragment != null) { // has_fragment
buf.append('#');
@@ -2332,11 +2458,28 @@
* authority = server | reg_name
* </pre></blockquote><p>
*
- * @param the authority
+ * @param escapedAuthority the raw escaped authority
+ * @exception URIException
+ * @throws NullPointerException null authority
+ */
+ public void setRawAuthority(char[] escapedAuthority) throws URIException {
+ parseAuthority(new String(escapedAuthority), true);
+ setUriReference();
+ }
+
+
+ /**
+ * Set the authority. It can be one type of server, hostport, hostname,
+ * IPv4address, IPv6reference and reg_name.
+ * Note that there is no setAuthority method by the escape encoding reason.
+ *
+ * @param escapedAuthority the escaped authority string
* @exception URIException
*/
- public void setAuthority(String authority) throws URIException {
- parseAuthority(authority, false);
+ public void setEscapedAuthority(String escapedAuthority)
+ throws URIException {
+
+ parseAuthority(escapedAuthority, true);
setUriReference();
}
@@ -2762,7 +2905,38 @@
// -------------------------------------------------------------- The query
/**
+ * Set the raw-escaped query.
+ *
+ * @param escapedQuery the raw-escaped query
+ * @exception URIException escaped query not valid
+ * @throws NullPointerException null query
+ */
+ public void setRawQuery(char[] escapedQuery) throws URIException {
+ if (!validate(escapedQuery, query))
+ throw new URIException(URIException.ESCAPING,
+ "escaped query not valid");
+ _query = escapedQuery;
+ setUriReference();
+ }
+
+
+ /**
+ * Set the escaped query string.
+ *
+ * @param escapedQuery the escaped query string
+ * @exception URIException escaped query not valid
+ * @throws NullPointerException null query
+ */
+ public void setEscapedQuery(String escapedQuery) throws URIException {
+ setRawQuery(escapedQuery.toCharArray());
+ }
+
+
+ /**
* Set the query.
+ * When a query string is not misunderstood the reserved special characters
+ * ("&", "=", "+", ",", and "$") within a query component, it is
+ * recommended to use in encoding the whole query with this method.
*
* @param query the query string.
* @exception URIException incomplete trailing escape pattern
@@ -2771,8 +2945,7 @@
* @see #encode
*/
public void setQuery(String query) throws URIException {
- _query = encode(query, allowed_query);
- setUriReference();
+ setRawQuery(encode(query, allowed_query));
}
@@ -2811,10 +2984,40 @@
// ----------------------------------------------------------- The fragment
/**
+ * Set the raw-escaped fragment.
+ *
+ * @param escapedFragment the raw-escaped fragment
+ * @exception URIException escaped fragment not valid
+ * @throws NullPointerException null fragment
+ */
+ public void setRawFragment(char[] escapedFragment) throws URIException {
+ if (!validate(escapedFragment, fragment))
+ throw new URIException(URIException.ESCAPING,
+ "escaped fragment not valid");
+ _fragment = escapedFragment;
+ setUriReference();
+ }
+
+
+ /**
+ * Set the escaped fragment string.
+ *
+ * @param escapedFragment the escaped fragment string
+ * @exception URIException escaped fragment not valid
+ * @throws NullPointerException null fragment
+ */
+ public void setEscapedFragment(String escapedFragment) throws URIException {
+ char[] fragmentSequence = escapedFragment.toCharArray();
+ if (!validate(fragmentSequence, fragment))
+ throw new URIException(URIException.ESCAPING,
+ "escaped fragment not valid");
+ _fragment = fragmentSequence;
+ setUriReference();
+ }
+
+
+ /**
* Set the fragment.
- * <p>
- * An empty URI reference represents the base URI of the current document
- * and should be replaced by that URI when transformed into a request.
*
* @param the fragment string.
* @exception URIException
@@ -2947,16 +3150,6 @@
/**
- * Set debug mode
- *
- * @param level the level of debug mode
- */
- public void setDebug(int level) {
- debug = level;
- }
-
-
- /**
* Test if the first array is equal to the second array.
*
* @param first the first character array
@@ -3161,7 +3354,7 @@
* Get the escaped URI string.
* <p>
* On the document, the URI-reference form is only used without the userinfo
- * component like http://jakarta.apache.org/slide by the security reason.
+ * component like http://jakarta.apache.org/ by the security reason.
* But the URI-reference form with the userinfo component could be parsed.
* <p>
* In other words, this URI and any its subclasses must not expose the
@@ -3186,8 +3379,7 @@
* a given locale. Supports all locales recognized in JDK 1.1.
* <p>
* The distribution of this class is Servlets.com. It was originally
- * written by Jason Hunter [jhunter@acm.org] and used by the Jakarta Slide
- * project with permission.
+ * written by Jason Hunter [jhunter at acm.org] and used by with permission.
*/
public static class LocaleToCharsetMap {
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>