if ( ( (DocumentException) e.getCause() ).getNestedException() instanceof SAXParseException ) { errorCode = "XMLError"; } else if ( ( (DocumentException) e.getCause() ).getNestedException() instanceof FileNotFoundException ) { errorCode = "FileNotFound"; } else if ( ( (DocumentException) e.getCause() ).getNestedException() instanceof IOException ) { if ( ( (DocumentException) e.getCause() ).getNestedException() instanceof UnknownHostException ) { errorCode = "UnknownHost"; } else {
public static Element getRootElement(InputStream stream) throws DocumentException { try { SAXReader saxReader = new SAXReader(); saxReader.setEntityResolver(new DTDEntityResolver()); saxReader.setMergeAdjacentText(true); return saxReader.read(stream).getRootElement(); } catch (DocumentException e) { Throwable nested = e.getNestedException(); if (nested!= null) { if (nested instanceof FileNotFoundException) { throw new RuntimeException("Can't find schema/DTD reference: " + nested.getMessage(), e); } else if (nested instanceof UnknownHostException) { throw new RuntimeException("Cannot connect to host from schema/DTD reference: " + nested.getMessage() + " - check that your schema/DTD reference is current", e); } } throw e; } }
doc = reader.read(configuration); } catch (DocumentException e) { if (e.getNestedException() instanceof java.io.FileNotFoundException) { System.out.println("FileNotFoundException for configuration file: " + configuration); throw (java.io.FileNotFoundException) e.getNestedException();