in xmlresolver-1.2/src/main/java/org/apache/xml/resolver/Catalog.java [1722:1830]
protected String resolveLocalSystem(String systemId)
throws MalformedURLException, IOException {
String osname = System.getProperty("os.name");
boolean windows = (osname.indexOf("Windows") >= 0);
Enumeration en = catalogEntries.elements();
while (en.hasMoreElements()) {
CatalogEntry e = (CatalogEntry) en.nextElement();
if (e.getEntryType() == SYSTEM
&& (e.getEntryArg(0).equals(systemId)
|| (windows
&& e.getEntryArg(0).equalsIgnoreCase(systemId)))) {
return e.getEntryArg(1);
}
}
// If there's a REWRITE_SYSTEM entry in this catalog, use it
en = catalogEntries.elements();
String startString = null;
String prefix = null;
while (en.hasMoreElements()) {
CatalogEntry e = (CatalogEntry) en.nextElement();
if (e.getEntryType() == REWRITE_SYSTEM) {
String p = (String) e.getEntryArg(0);
if (p.length() <= systemId.length()
&& p.equals(systemId.substring(0, p.length()))) {
// Is this the longest prefix?
if (startString == null
|| p.length() > startString.length()) {
startString = p;
prefix = e.getEntryArg(1);
}
}
}
}
if (prefix != null) {
// return the systemId with the new prefix
return prefix + systemId.substring(startString.length());
}
// If there's a SYSTEM_SUFFIX entry in this catalog, use it
en = catalogEntries.elements();
String suffixString = null;
String suffixURI = null;
while (en.hasMoreElements()) {
CatalogEntry e = (CatalogEntry) en.nextElement();
if (e.getEntryType() == SYSTEM_SUFFIX) {
String p = (String) e.getEntryArg(0);
if (p.length() <= systemId.length()
&& systemId.endsWith(p)) {
// Is this the longest prefix?
if (suffixString == null
|| p.length() > suffixString.length()) {
suffixString = p;
suffixURI = e.getEntryArg(1);
}
}
}
}
if (suffixURI != null) {
// return the systemId for the suffix
return suffixURI;
}
// If there's a DELEGATE_SYSTEM entry in this catalog, use it
en = catalogEntries.elements();
Vector delCats = new Vector();
while (en.hasMoreElements()) {
CatalogEntry e = (CatalogEntry) en.nextElement();
if (e.getEntryType() == DELEGATE_SYSTEM) {
String p = (String) e.getEntryArg(0);
if (p.length() <= systemId.length()
&& p.equals(systemId.substring(0, p.length()))) {
// delegate this match to the other catalog
delCats.addElement(e.getEntryArg(1));
}
}
}
if (delCats.size() > 0) {
Enumeration enCats = delCats.elements();
if (catalogManager.debug.getDebug() > 1) {
catalogManager.debug.message(2, "Switching to delegated catalog(s):");
while (enCats.hasMoreElements()) {
String delegatedCatalog = (String) enCats.nextElement();
catalogManager.debug.message(2, "\t" + delegatedCatalog);
}
}
Catalog dcat = newCatalog();
enCats = delCats.elements();
while (enCats.hasMoreElements()) {
String delegatedCatalog = (String) enCats.nextElement();
dcat.parseCatalog(delegatedCatalog);
}
return dcat.resolveSystem(systemId);
}
return null;
}