Code with Finding: |
class LookupState {
protected void parseURI ()
throws ProtocolException
{
int urilen = uri.length() ;
int start = 0 ;
int slash = -1 ;
Vector comps = new Vector(8) ;
int q = uri.indexOf ('?', start);
int f = uri.indexOf ('#', start);
int s = uri.indexOf (';', start); // rfc1630 reserved
int stop = -1;
if (q >= 0) {
if (f >= 0) {
if (s >= 0) {
stop = Math.min(q, Math.min(s, f));
} else {
stop = Math.min(q, f);
}
} else if (s >= 0) {
stop = Math.min(q, s);
} else {
stop = q;
}
} else {
if (f >= 0) {
if (s >= 0) {
stop = stop = Math.min(f, s);
} else {
stop = f;
}
} else if (s >= 0) {
stop = s;
} else {
stop = urilen;
}
}
this.uri = uri ;
loop:
while ( true ) {
slash = uri.indexOf ('/', start) ;
if ((slash >= stop) || (slash < 0)) {
break loop;
} else if ( slash == start ) {
start = slash + 1;
continue loop;
} else if ( slash > 0 ) {
String part = unescape(uri.substring (start, slash)) ;
comps.addElement (part) ;
start = slash + 1;
continue loop;
}
}
// Deal with any ? or # fragments:
// we shouldn't do too much job like this...
if ((q >= 0) || (f >= 0) || (s >= 0)) {
if (q > 0) {
if (f > 0) {
if (s > 0) {
// ?#;
if ((q < f) && (f < s)) {
// ?#;
if (q+1 < f)
this.query = uri.substring(q+1, f);
if (f+1 < s)
this.fragment = uri.substring(f+1, s);
if (s+1 < urilen)
this.type = uri.substring(s+1, urilen);
} else if ((f < q) && (q < s)) {
// #?;
if (f+1 < q)
this.query = uri.substring(f+1, q);
if (q+1 < s)
this.fragment = uri.substring(q+1, s);
if (s+1 < urilen)
this.type = uri.substring(s+1, urilen);
} else if ((f < s) && (s < q)) {
// #;?
if (f+1 < s)
this.query = uri.substring(f+1, s);
if (s+1 < q)
this.fragment = uri.substring(s+1, q);
if (q+1 < urilen)
this.type = uri.substring(q+1, urilen);
} else if ((q < s) && (s < f)) {
// ?;#
if (q+1 < s)
this.query = uri.substring(q+1, s);
if (s+1 < f)
this.fragment = uri.substring(s+1, f);
if (f+1 < urilen)
this.type = uri.substring(f+1, urilen);
} else if ((s < q) && (q < f)) {
// ;?#
if (s+1 < q)
this.query = uri.substring(s+1, q);
if (q+1 < f)
this.fragment = uri.substring(q+1, f);
if (f+1 < urilen)
this.type = uri.substring(f+1, urilen);
} else {
// ;#?
if (s+1 < q)
this.query = uri.substring(s+1, q);
if (q+1 < f)
this.fragment = uri.substring(q+1, f);
if (f+1 < urilen)
this.type = uri.substring(f+1, urilen);
}
} else {
// ?# only
if (f > q) {
// ?q#f
if (q+1 < f)
this.query = uri.substring(q+1, f);
if (f+1 < urilen)
this.fragment = uri.substring(f+1, urilen);
} else {
// #f?q
if (f+1 < q)
this.fragment = uri.substring(f+1, q);
if (q+1 < urilen)
this.query = uri.substring(q+1, urilen);
}
}
} else {
// NO #
if (s > 0) {
// ?; only
if (s > q) {
// ?q;t
if (q+1 < s)
this.query = uri.substring(q+1, s);
if (s+1 < urilen)
this.type = uri.substring(s+1, urilen);
} else {
// ;t?q
if (s+1 < q)
this.type = uri.substring(s+1, q);
if (q+1 < urilen)
this.query = uri.substring(q+1, urilen);
}
} else {
// ?q
if (q+1 < urilen)
this.query = uri.substring(q+1, urilen);
}
}
} else {
// NO ?
if (s > 0) {
if (f > 0) {
if (s > f) {
if (f+1 < s)
this.fragment = uri.substring(f+1, s);
if (s+1 < urilen)
this.type = uri.substring(s+1, urilen);
} else {
if (s+1 < f)
this.type = uri.substring(s+1, f);
if (f+1 < urilen)
this.fragment = uri.substring(f+1, urilen);
}
} else {
if (s+1 < urilen)
this.type = uri.substring(s+1, urilen);
}
} else {
if (f+1 < urilen)
this.fragment = uri.substring(f+1, urilen);
}
}
}
// Update query states:
if ( request != null ) {
if ( query != null )
request.setState("query", query);
if ( fragment != null )
request.setState("frag", fragment);
if ( type != null )
request.setState("type", type);
}
// Keep track of last frament, and wrap up the result:
if (start < stop)
comps.addElement(unescape(uri.substring(start, stop)));
if (--stop >= 0 )
is_directory = (uri.charAt(stop) == '/');
components = new String[comps.size()] ;
comps.copyInto (components) ;
index = 0 ;
}
}
|