}
private Document parseXmlInput(String input) throws DiscoveryException
{
if (input == null)
throw new DiscoveryException("Cannot read XML message",
OpenIDException.XRDS_DOWNLOAD_ERROR);
if (DEBUG)
_log.debug("Parsing XRDS input: " + input);
try
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
dbf.setAttribute(JAXP_SCHEMA_SOURCE, new Object[] {
Discovery.class.getResourceAsStream(XRD_SCHEMA),
Discovery.class.getResourceAsStream(XRDS_SCHEMA),
});
DocumentBuilder builder = dbf.newDocumentBuilder();
builder.setErrorHandler(new ErrorHandler() {
public void error(SAXParseException exception) throws SAXException {
throw exception;
}
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
public void warning(SAXParseException exception) throws SAXException {
throw exception;
}
});
return builder.parse(new ByteArrayInputStream(input.getBytes()));
}
catch (ParserConfigurationException e)
{
throw new DiscoveryException("Parser configuration error",
OpenIDException.XRDS_PARSING_ERROR, e);
}
catch (SAXException e)
{
throw new DiscoveryException("Error parsing XML document",
OpenIDException.XRDS_PARSING_ERROR, e);
}
catch (IOException e)
{
throw new DiscoveryException("Error reading XRDS document",
OpenIDException.XRDS_DOWNLOAD_ERROR, e);
}
}