You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Schwartz, Todd" <to...@intel.com> on 2001/02/27 22:56:05 UTC
Proposed patch: allow relative URIs
Hi, all.
Here is a patch that will allow Xerces to validate relative URIs as valid
uriReference values. The second part of the patch, in the
readers.DefaultHandler class, will handle the case where a relative URI is
specified as the system id -- it will force the URI to be resolved before
the system id target is retrieved.
Comments? Questions?
In org.apache.xerces.utils.URI:
===============================
private void initialize(URI p_base, String p_uriSpec) throws
MalformedURIException {
if (p_base == null &&
(p_uriSpec == null || p_uriSpec.trim().length() == 0)) {
throw new MalformedURIException(
"Cannot initialize URI with empty parameters.");
}
// just make a copy of the base if spec is empty
if (p_uriSpec == null || p_uriSpec.trim().length() == 0) {
initialize(p_base);
return;
}
String uriSpec = p_uriSpec.trim();
int uriSpecLen = uriSpec.length();
int index = 0;
// Check for scheme, which must be before `/'. Also handle names
with
// DOS drive letters ('D:'), so 1-character schemes are not allowed.
int colonIdx = uriSpec.indexOf(':');
+ if (colonIdx != -1)
+ {
if ((colonIdx < 2) || (colonIdx > uriSpec.indexOf('/'))) {
int fragmentIdx = uriSpec.indexOf('#');
// A standalone base is a valid URI according to spec
if (p_base == null && fragmentIdx != 0 ) {
throw new MalformedURIException("No scheme found in
URI.");
}
}
else {
initializeScheme(uriSpec);
index = m_scheme.length()+1;
}
+ }
...
In org.apache.xerces.readers.DefaultHandler:
============================================
private String expandSystemId(String systemId, String currentSystemId) {
String id = systemId;
// check for bad parameters id
if (id == null || id.length() == 0) {
return systemId;
}
// if id already expanded, return
try {
URI uri = new URI(id);
+ if (uri != null && uri.getScheme() != null) {
- if (uri != null) {
return systemId;
}
}
catch (URI.MalformedURIException e) {
// continue on...
}
...