in axis-rt-core/src/main/java/org/apache/axis/types/URI.java [488:589]
private void initialize(URI p_base, String p_uriSpec, boolean allowNonAbsoluteURI)
throws MalformedURIException {
String uriSpec = p_uriSpec;
int uriSpecLen = (uriSpec != null) ? uriSpec.length() : 0;
if (p_base == null && uriSpecLen == 0) {
if (allowNonAbsoluteURI) {
m_path = "";
return;
}
throw new MalformedURIException("Cannot initialize URI with empty parameters.");
}
// just make a copy of the base if spec is empty
if (uriSpecLen == 0) {
initialize(p_base);
return;
}
int index = 0;
// Check for scheme, which must be before '/', '?' or '#'.
int colonIdx = uriSpec.indexOf(':');
if (colonIdx != -1) {
final int searchFrom = colonIdx - 1;
// search backwards starting from character before ':'.
int slashIdx = uriSpec.lastIndexOf('/', searchFrom);
int queryIdx = uriSpec.lastIndexOf('?', searchFrom);
int fragmentIdx = uriSpec.lastIndexOf('#', searchFrom);
if (colonIdx == 0 || slashIdx != -1 ||
queryIdx != -1 || fragmentIdx != -1) {
// A standalone base is a valid URI according to spec
if (colonIdx == 0 || (p_base == null && fragmentIdx != 0 && !allowNonAbsoluteURI)) {
throw new MalformedURIException("No scheme found in URI.");
}
}
else {
initializeScheme(uriSpec);
index = m_scheme.length()+1;
// Neither 'scheme:' or 'scheme:#fragment' are valid URIs.
if (colonIdx == uriSpecLen - 1 || uriSpec.charAt(colonIdx+1) == '#') {
throw new MalformedURIException("Scheme specific part cannot be empty.");
}
}
}
else if (p_base == null && uriSpec.indexOf('#') != 0 && !allowNonAbsoluteURI) {
throw new MalformedURIException("No scheme found in URI.");
}
// Two slashes means we may have authority, but definitely means we're either
// matching net_path or abs_path. These two productions are ambiguous in that
// every net_path (except those containing an IPv6Reference) is an abs_path.
// RFC 2396 resolves this ambiguity by applying a greedy left most matching rule.
// Try matching net_path first, and if that fails we don't have authority so
// then attempt to match abs_path.
//
// net_path = "//" authority [ abs_path ]
// abs_path = "/" path_segments
if (((index+1) < uriSpecLen) &&
(uriSpec.charAt(index) == '/' && uriSpec.charAt(index+1) == '/')) {
index += 2;
int startPos = index;
// Authority will be everything up to path, query or fragment
char testChar = '\0';
while (index < uriSpecLen) {
testChar = uriSpec.charAt(index);
if (testChar == '/' || testChar == '?' || testChar == '#') {
break;
}
index++;
}
// Attempt to parse authority. If the section is an empty string
// this is a valid server based authority, so set the host to this
// value.
if (index > startPos) {
// If we didn't find authority we need to back up. Attempt to
// match against abs_path next.
if (!initializeAuthority(uriSpec.substring(startPos, index))) {
index = startPos - 2;
}
}
else {
m_host = "";
}
}
initializePath(uriSpec, index);
// Resolve relative URI to base URI - see RFC 2396 Section 5.2
// In some cases, it might make more sense to throw an exception
// (when scheme is specified is the string spec and the base URI
// is also specified, for example), but we're just following the
// RFC specifications
if (p_base != null) {
absolutize(p_base);
}
}