int retcode = response.getHttpStatusCode();
if (retcode == HttpResponse.SC_INTERNAL_SERVER_ERROR) {
// Convert external "internal error" to gateway error:
retcode = HttpResponse.SC_BAD_GATEWAY;
}
throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
"Unable to retrieve template library xml. HTTP error " +
response.getHttpStatusCode(), retcode);
}
String content = response.getResponseAsString();
try {
String key = null;
Element element = null;
if (!context.getIgnoreCache()) {
key = HashUtil.checksum(CharsetUtil.getUtf8Bytes(content));
element = parsedXmlCache.getElement(key);
}
if (element == null) {
element = XmlUtil.parse(content);
if (key != null) {
parsedXmlCache.addElement(key, element);
}
}
return new XmlTemplateLibrary(uri, element, content);
} catch (XmlException e) {
throw new GadgetException(GadgetException.Code.MALFORMED_XML_DOCUMENT, e,
HttpResponse.SC_BAD_REQUEST);
}
}