You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by je...@apache.org on 2003/01/05 09:01:49 UTC
cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient URI.java
jericho 2003/01/05 00:01:49
Modified: httpclient/src/java/org/apache/commons/httpclient URI.java
Log:
- 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
(Use the removeFragmentIdentifer method)
- Add the setXxxURIReference methods
Revision Changes Path
1.18 +126 -48 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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- URI.java 4 Jan 2003 17:44:04 -0000 1.17
+++ URI.java 5 Jan 2003 08:01:49 -0000 1.18
@@ -228,7 +228,7 @@
_is_opaque_part = true;
_fragment = fragment.toCharArray();
- setUriReference();
+ setURI();
}
@@ -448,7 +448,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) {
@@ -504,7 +504,7 @@
if (relative._fragment != null) {
this._fragment = relative._fragment;
}
- this.setUriReference();
+ this.setURI();
}
// --------------------------------------------------- Instance Variables
@@ -855,7 +855,7 @@
* URI absolute path.
* <p><blockquote><pre>
* abs_path = "/" path_segments
- * </pre><blockquote><p>
+ * </pre></blockquote><p>
*/
protected static final BitSet abs_path = new BitSet(256);
// Static initializer for abs_path
@@ -1490,7 +1490,6 @@
static {
allowed_within_query.or(allowed_query);
allowed_within_query.andNot(reserved); // excluded 'reserved'
- allowed_within_query.clear('#'); // avoid confict with the fragment
}
@@ -1619,8 +1618,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);
@@ -1654,8 +1653,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 {
@@ -1971,7 +1970,7 @@
}
// set this URI.
- setUriReference();
+ setURI();
}
@@ -2161,7 +2160,7 @@
*
* @see #getRawURI
*/
- protected void setUriReference() {
+ protected void setURI() {
// set _uri
StringBuffer buf = new StringBuffer();
// ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
@@ -2197,11 +2196,7 @@
buf.append('?');
buf.append(_query);
}
- if (_fragment != null) { // has_fragment
- buf.append('#');
- buf.append(_fragment);
- }
-
+ // ignore the fragment identifier
_uri = buf.toString().toCharArray();
}
@@ -2476,7 +2471,7 @@
*/
public void setRawAuthority(char[] escapedAuthority) throws URIException {
parseAuthority(new String(escapedAuthority), true);
- setUriReference();
+ setURI();
}
@@ -2492,7 +2487,7 @@
throws URIException {
parseAuthority(escapedAuthority, true);
- setUriReference();
+ setURI();
}
@@ -2857,8 +2852,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 {
@@ -2905,8 +2900,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 {
@@ -2921,14 +2916,20 @@
*
* @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;
+ }
+ // remove the fragment identifier
+ escapedQuery = removeFragmentIdentifier(escapedQuery);
if (!validate(escapedQuery, query))
throw new URIException(URIException.ESCAPING,
"escaped query not valid");
_query = escapedQuery;
- setUriReference();
+ setURI();
}
@@ -2937,26 +2938,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
* ("&", "=", "+", ",", 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));
}
@@ -2985,8 +3000,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 {
@@ -3000,14 +3015,17 @@
*
* @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();
+ setURI();
}
@@ -3016,15 +3034,18 @@
*
* @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();
}
@@ -3033,12 +3054,14 @@
*
* @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();
}
@@ -3076,8 +3099,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 {
@@ -3087,6 +3110,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
@@ -3331,7 +3371,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;
@@ -3342,7 +3382,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);
@@ -3352,13 +3392,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);
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>