jericho 2002/11/03 09:15:05
Modified: httpclient/src/java/org/apache/commons/httpclient/util
URIUtil.java
httpclient/src/java/org/apache/commons/httpclient
URIException.java URI.java HttpURL.java
Log:
URI: add bitset for allowed_within_userinfo, within_userinfo
URI: add setXxxAuthority methods instead of setAuthority
HttpURL: add setXxxUserinfo, setXxxUser and setXxxPassword methods
ESLE: add javadoc messages.
Revision Changes Path
1.10 +16 -8
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java
Index: URIUtil.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- URIUtil.java 26 Oct 2002 16:25:34 -0000 1.9
+++ URIUtil.java 3 Nov 2002 17:15:05 -0000 1.10
@@ -384,8 +384,9 @@
/**
* Escape and encode a string regarded as within the query component of an
* URI with the default protocol charset.
- * Within a query component, the characters ";", "/", "?", ":", "@",
- * "&", "=", "+", ",", and "$" are reserved.
+ * When a query comprise the name and value pairs, it is used in order
+ * to encode each name and value string. The reserved special characters
+ * within a query component are being included in encoding the query.
*
* @param unescaped an unescaped string
* @return the escaped string
@@ -403,8 +404,9 @@
/**
* Escape and encode a string regarded as within the query component of an
* URI with a given charset.
- * Within a query component, the characters ";", "/", "?", ":", "@",
- * "&", "=", "+", ",", and "$" are reserved.
+ * When a query comprise the name and value pairs, it is used in order
+ * to encode each name and value string. The reserved special characters
+ * within a query component are being included in encoding the query.
*
* @param unescaped an unescaped string
* @param charset the charset
@@ -422,6 +424,9 @@
/**
* Escape and encode a string regarded as the query component of an URI with
* the default protocol charset.
+ * When a query string is not misunderstood the reserved special characters
+ * ("&", "=", "+", ",", and "$") within a query component, this method
+ * is recommended to use in encoding the whole query.
*
* @param unescaped an unescaped string
* @return the escaped string
@@ -437,6 +442,9 @@
/**
* Escape and encode a string regarded as the query component of an URI with
* a given charset.
+ * When a query string is not misunderstood the reserved special characters
+ * ("&", "=", "+", ",", and "$") within a query component, this method
+ * is recommended to use in encoding the whole query.
*
* @param unescaped an unescaped string
* @param charset the charset
1.3 +14 -5
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URIException.java
Index: URIException.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URIException.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- URIException.java 9 Oct 2002 12:46:16 -0000 1.2
+++ URIException.java 3 Nov 2002 17:15:05 -0000 1.3
@@ -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.14 +55 -15
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URI.java
Index: URI.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URI.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- URI.java 29 Oct 2002 17:00:46 -0000 1.13
+++ URI.java 3 Nov 2002 17:15:05 -0000 1.14
@@ -1046,6 +1046,21 @@
/**
+ * 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 ]
@@ -1355,6 +1370,17 @@
/**
+ * 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.
*/
@@ -2432,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();
}
@@ -2885,17 +2928,15 @@
* @throws NullPointerException null query
*/
public void setEscapedQuery(String escapedQuery) throws URIException {
- char[] querySequence = escapedQuery.toCharArray();
- if (!validate(querySequence, query))
- throw new URIException(URIException.ESCAPING,
- "escaped query not valid");
- _query = querySequence;
- setUriReference();
+ 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
@@ -2904,8 +2945,7 @@
* @see #encode
*/
public void setQuery(String query) throws URIException {
- _query = encode(query, allowed_query);
- setUriReference();
+ setRawQuery(encode(query, allowed_query));
}
1.5 +165 -5
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpURL.java
Index: HttpURL.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpURL.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- HttpURL.java 29 Oct 2002 13:53:54 -0000 1.4
+++ HttpURL.java 3 Nov 2002 17:15:05 -0000 1.5
@@ -419,6 +419,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();
+ setUriReference();
+ }
+
+
+ /**
+ * 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();
+ setUriReference();
+ }
+
+
+ /**
+ * 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
@@ -462,6 +572,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();
+ setUriReference();
+ }
+
+
+ /**
+ * 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
@@ -540,7 +700,7 @@
// -------------------------------------------------------------- The query
/**
- * Set the query.
+ * Set the query as the name and value pair.
*
* @param queryName the query string.
* @param queryValue the query string.
@@ -562,7 +722,7 @@
/**
- * Set the query as the name and value pair.
+ * 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.
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>