public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
if(Log.isDebugEnabled(Log.XML_RESOLVER))
Log.debug(Log.XML_RESOLVER, "Jeeves XmlResolver: Before resolution: Type: "+type+" NamespaceURI :"+namespaceURI+" PublicId :"+publicId+" SystemId :"+systemId+" BaseURI:"+baseURI);
LSInput result = super.resolveResource(type, namespaceURI, publicId, systemId, baseURI);
if (result != null) { // some changes made so update
publicId = result.getPublicId();
systemId = result.getSystemId();
baseURI = result.getBaseURI();
}
if(Log.isDebugEnabled(Log.XML_RESOLVER))
Log.debug(Log.XML_RESOLVER, "Jeeves XmlResolver: After resolution: PublicId :"+publicId+" SystemId :"+systemId+" BaseURI:"+baseURI);
URL externalRef = null;
try {
if (publicId != null && publicId.startsWith("http://")) {
externalRef = new URL(publicId);
} else if (systemId != null && systemId.startsWith("http://")) {
externalRef = new URL(systemId);
} else if (systemId != null && baseURI != null) {
if (baseURI.startsWith("http://")) {
URL ref = new URL(baseURI);
String thePath = new File(ref.getPath()).getParent().replace('\\', '/');
externalRef = new URI(ref.getProtocol(), null, ref.getHost(), ref.getPort(), thePath + "/" + systemId, null, null).toURL();
}
}
} catch (MalformedURLException e) { // leave this to someone else?
e.printStackTrace();
return result;
} catch (URISyntaxException e) { // leave this to someone else?
e.printStackTrace();
return result;
}
if (externalRef != null) {
Element elResult = null;
try {
elResult = isXmlInCache(externalRef.toString());
} catch (CacheException e) {
Log.error(Log.XML_RESOLVER, "Request to cache for " + externalRef + " failed.");
e.printStackTrace();
}
if (elResult == null) { // use XMLRequest to get the XML
XmlRequest xml = new GeonetHttpRequestFactory().createXmlRequest(externalRef);
if (proxyParams.useProxy) {
xml.setUseProxy(true);
xml.setProxyHost(proxyParams.proxyHost);
xml.setProxyPort(proxyParams.proxyPort);
if (proxyParams.useProxyAuth) {
xml.setProxyCredentials(proxyParams.username, proxyParams.password);
}
}
elResult = null;
try {
elResult = xml.execute();
addXmlToCache(externalRef.toString(), elResult);
if(Log.isDebugEnabled(Log.XML_RESOLVER)) {
Log.debug(Log.XML_RESOLVER, "Retrieved: \n" + Xml.getString(elResult));
}
} catch (Exception e) {
Log.error(Log.XML_RESOLVER, "Request on " + externalRef + " failed." + e.getMessage());
}
}
if (result == null) {
result = new DOMInputImpl(publicId, systemId, baseURI);
}
if (elResult != null) {
result.setStringData(Xml.getString(elResult));
}
}
return result;
}