jericho 2002/08/17 08:33:37
Modified: src/util/org/apache/util URI.java
Log:
- Fix to parse the port number value correctly... (never notice it? :( )
- Let us not distinguish the empty and undefined components.
(That makes to develop difficult... like using '\0' characters... )
So a null component may be regarded as an empty component...
In case we need it, let us think about it later for the use.
- Remove the possiblity throwing NullPointerExceptions to use methods...
Except for constructors... It may be correct....
Revision Changes Path
1.13 +50 -86 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- URI.java 17 Aug 2002 08:54:12 -0000 1.12
+++ URI.java 17 Aug 2002 15:33:37 -0000 1.13
@@ -1699,7 +1699,7 @@
_is_opaque_part = true;
} else {
// the path component may be empty
- _path = new char[] {'\0'};
+ _path = null;
}
}
setPath(tmp.substring(from, next));
@@ -1848,6 +1848,7 @@
_is_reg_name = _is_server =
_is_hostname = _is_IPv4address = _is_IPv6reference = false;
+ boolean has_port = true;
int from = 0;
int next = original.indexOf('@');
if (next != -1) { // neither -1 and 0
@@ -1873,6 +1874,7 @@
next = original.indexOf(':', from);
if (next == -1) {
next = original.length();
+ has_port = false;
}
// REMINDME: it doesn't need the pre-validation
_host = original.substring(from, next).toCharArray();
@@ -1895,8 +1897,8 @@
_authority = (escaped) ? original.toString().toCharArray() :
encode(original.toString(), allowed_reg_name);
} else {
- next = original.indexOf('/', from);
- if (next > 0 && original.charAt(next) == ':') { // not empty
+ if (original.length()-1 > next && has_port &&
+ original.charAt(next) == ':') { // not empty
from = next + 1;
try {
_port = Integer.parseInt(original.substring(from));
@@ -2224,10 +2226,10 @@
* Get the scheme.
*
* @return the scheme
- * @throws NullPointerException undefined scheme
+ * null if undefined scheme
*/
public String getScheme() {
- return new String(_scheme);
+ return (_scheme == null) ? null : new String(_scheme);
}
// ---------------------------------------------------------- The authority
@@ -2263,43 +2265,8 @@
*
* @return the escaped authority
*/
- public String getEscapedAuthority() {
- return new String(_authority);
- }
-
-
- /**
- * Get the authority.
- *
- * @return the authority
- * @exception URIException
- * @see #decode
- */
- public String getAuthority() throws URIException {
- return decode(_authority);
- }
-
- // ----------------------------------------------------------- The userinfo
-
- /**
- * Get the raw-escaped userinfo.
- *
- * @return the raw-escaped userinfo
- * @see #getAuthority
- */
- public char[] getRawUserinfo() {
- return _userinfo;
- }
-
-
- /**
- * Get the escaped userinfo.
- *
- * @return the escaped userinfo
- * @see #getAuthority
- */
public String getEscapedUserinfo() {
- return new String(_userinfo);
+ return (_userinfo == null) ? null : new String(_userinfo);
}
@@ -2312,7 +2279,7 @@
* @see #getAuthority
*/
public String getUserinfo() throws URIException {
- return decode(_userinfo);
+ return (_userinfo == null) ? null : decode(_userinfo);
}
// --------------------------------------------------------------- The host
@@ -2403,7 +2370,7 @@
protected char[] resolvePath(char[] base_path, char[] rel_path) {
// REMINDME: paths are never null
- String base = new String(base_path);
+ String base = (base_path == null) ? "" : new String(base_path);
int at = base.lastIndexOf('/');
if (at != -1) {
base_path = base.substring(0, at + 1).toCharArray();
@@ -2458,7 +2425,7 @@
* @exception URIException no hierarchy level
*/
public char[] getRawCurrentHierPath() throws URIException {
- return getRawCurrentHierPath(_path);
+ return (_path == null) ? null : getRawCurrentHierPath(_path);
}
@@ -2469,7 +2436,8 @@
* @exception URIException no hierarchy level
*/
public String getEscapedCurrentHierPath() throws URIException {
- return new String(getRawCurrentHierPath());
+ char[] path = getRawCurrentHierPath();
+ return (path == null) ? null : new String(path);
}
@@ -2481,7 +2449,8 @@
* @see #decode
*/
public String getCurrentHierPath() throws URIException {
- return decode(getRawCurrentHierPath());
+ char[] path = getRawCurrentHierPath();
+ return (path == null) ? null : decode(path);
}
@@ -2492,7 +2461,8 @@
* @exception URIException
*/
public char[] getRawAboveHierPath() throws URIException {
- return getRawCurrentHierPath(getRawCurrentHierPath());
+ char[] path = getRawCurrentHierPath();
+ return (path == null) ? null : getRawCurrentHierPath(path);
}
@@ -2503,7 +2473,8 @@
* @exception URIException
*/
public String getEscapedAboveHierPath() throws URIException {
- return new String(getRawAboveHierPath());
+ char[] path = getRawAboveHierPath();
+ return (path == null) ? null : new String(path);
}
@@ -2515,7 +2486,8 @@
* @see #decode
*/
public String getAboveHierPath() throws URIException {
- return decode(getRawAboveHierPath());
+ char[] path = getRawAboveHierPath();
+ return (path == null) ? null : decode(path);
}
@@ -2543,7 +2515,8 @@
* @return the escaped path string
*/
public String getEscapedPath() {
- return new String(_is_opaque_part ? _opaque :_path);
+ char[] path = getRawPath();
+ return (path == null) ? null : new String(path);
}
@@ -2557,7 +2530,8 @@
* @see #decode
*/
public String getPath() throws URIException {
- return decode(getRawPath());
+ char[] path = getRawPath();
+ return (path == null) ? null : decode(path);
}
@@ -2567,10 +2541,8 @@
* @return the raw-escaped basename
*/
public char[] getRawName() {
+ if (_path == null) return null;
- if (_path == null || _path.length == 0) {
- return _path;
- }
int at = 0;
for (int i = _path.length - 1; i >= 0 ; i--) {
if (_path[i] == '/') {
@@ -2615,20 +2587,16 @@
* Get the raw-escaped path and query.
*
* @return the raw-escaped path and query
- * @exception URIException path undefined
*/
- public char[] getRawPathQuery() throws URIException {
+ public char[] getRawPathQuery() {
- // path is never empty
- if (_path == null) {
- throw new URIException(URIException.PARSING, "path undefined");
+ if (_path == null && _query == null) {
+ return null;
}
- int len = _path.length;
- if (_query != null) {
- len += 1 + _query.length;
+ StringBuffer buff = new StringBuffer();
+ if (_path != null) {
+ buff.append(_path);
}
- StringBuffer buff = new StringBuffer(len);
- buff.append(_path);
if (_query != null) {
buff.append('?');
buff.append(_query);
@@ -2641,10 +2609,10 @@
* Get the escaped query.
*
* @return the escaped path and query string
- * @exception URIException path undefined
*/
- public String getEscapedPathQuery() throws URIException {
- return new String(getRawPathQuery());
+ public String getEscapedPathQuery() {
+ char[] rawPathQuery = getRawPathQuery();
+ return (rawPathQuery == null) ? null : new String(rawPathQuery);
}
@@ -2657,7 +2625,8 @@
* @see #decode
*/
public String getPathQuery() throws URIException {
- return decode(getRawPathQuery());
+ char[] rawPathQuery = getRawPathQuery();
+ return (rawPathQuery == null) ? null : decode(rawPathQuery);
}
// -------------------------------------------------------------- The query
@@ -2691,10 +2660,9 @@
* Get the escaped query.
*
* @return the escaped query string
- * @throws NullPointerException undefined query
*/
public String getEscapedQuery() {
- return new String(_query);
+ return (_query == null) ? null : new String(_query);
}
@@ -2704,11 +2672,10 @@
* @return the query string.
* @exception URIException incomplete trailing escape pattern
* Or unsupported character encoding
- * @throws NullPointerException undefined query
* @see #decode
*/
public String getQuery() throws URIException {
- return decode(_query);
+ return (_query == null) ? null : decode(_query);
}
// ----------------------------------------------------------- The fragment
@@ -2754,10 +2721,9 @@
* Get the escaped fragment.
*
* @return the escaped fragment string
- * @throws NullPointerException undefined fragment
*/
public String getEscapedFragment() {
- return new String(_fragment);
+ return (_fragment == null) ? null : new String(_fragment);
}
@@ -2767,11 +2733,10 @@
* @return the fragment string
* @exception URIException incomplete trailing escape pattern
* Or unsupported character encoding
- * @throws NullPointerException undefined fragment
* @see #decode
*/
public String getFragment() throws URIException {
- return decode(_fragment);
+ return (_fragment == null) ? null : decode(_fragment);
}
// ------------------------------------------------------------- Utilities
@@ -2784,9 +2749,8 @@
*/
protected char[] normalize(char[] path) {
- if (path == null) {
- return null;
- }
+ if (path == null) return null;
+
String normalized = new String(path);
boolean endsWithSlash = true;
// precondition
@@ -2967,7 +2931,7 @@
* @return 0, if it's same,
* -1, if failed, first being compared with in the authority component
* @exception ClassCastException not URI argument
- * @exception NullPointerException character encoding error or null object
+ * @throws NullPointerException null object
*/
public int compareTo(Object obj) {
@@ -3047,7 +3011,7 @@
* @return the URI string
*/
public String getEscapedURI() {
- return new String(_uri);
+ return (_uri == null) ? null : new String(_uri);
}
@@ -3060,7 +3024,7 @@
* @see #decode
*/
public String getURI() throws URIException {
- return decode(_uri);
+ return (_uri == null) ? null : decode(_uri);
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>