jericho 2002/10/26 10:27:37
Modified: httpclient/src/java/org/apache/commons/httpclient
HttpURL.java
Log:
- Add the query setter for the specific protocols such as the HTTP URL and HTTPS URL.
Revision Changes Path
1.3 +55 -3
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HttpURL.java 9 Oct 2002 12:48:43 -0000 1.2
+++ HttpURL.java 26 Oct 2002 17:27:36 -0000 1.3
@@ -537,6 +537,58 @@
return (path == null || path.length == 0) ? rootPath : path;
}
+ // -------------------------------------------------------------- The query
+
+ /**
+ * Set the query.
+ *
+ * @param queryName the query string.
+ * @param queryValue the query string.
+ * @exception URIException incomplete trailing escape pattern
+ * Or unsupported character encoding
+ * @throws NullPointerException null query
+ * @see #encode
+ */
+ public void setQuery(String queryName, String queryValue)
+ throws URIException {
+
+ StringBuffer buff = new StringBuffer();
+ buff.append(encode(queryName, allowed_within_query));
+ buff.append('=');
+ buff.append(encode(queryValue, allowed_within_query));
+ _query = buff.toString().toCharArray();
+ setUriReference();
+ }
+
+
+ /**
+ * Set the array of the query.
+ *
+ * @param queryName the array of the query string.
+ * @param queryValue the array of the query string.
+ * @exception URIException incomplete trailing escape pattern,
+ * unsupported character encoding or wrong array size
+ * @throws NullPointerException null query
+ * @see #encode
+ */
+ public void setQuery(String[] queryName, String[] queryValue)
+ throws URIException {
+
+ int length = queryName.length;
+ if (length != queryValue.length)
+ throw new URIException("wrong array size of query");
+
+ StringBuffer buff = new StringBuffer();
+ for (int i = 0; i < length; i++) {
+ buff.append(encode(queryName[i], allowed_within_query));
+ buff.append('=');
+ buff.append(encode(queryValue[i], allowed_within_query));
+ if (i + 1 < length) buff.append('&');
+ }
+ _query = buff.toString().toCharArray();
+ setUriReference();
+ }
+
// ---------------------------------------------------------------- Utility
/**
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>