@Test public void should_return_null_when_dtd_not_specified() throws Exception { DtdResolver dtdResolver = new DtdResolver(); String dtdFile = dtdResolver.resolveDtdLocation("datasets/xml/users-without-dtd.xml"); assertThat(dtdFile).isNull(); }
public String resolveDtdLocation(final String xmlFile) { final InputStream xmlStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(xmlFile); try { final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(new StringReader("")); } }); final Document document = builder.parse(xmlStream); if (document.getDoctype() == null) { return null; } return document.getDoctype().getSystemId(); } catch (Exception e) { throw new RuntimeException("Unable to resolve dtd for " + xmlFile, e); } }
DtdResolver { public String resolveDtdLocation(final String xmlFile) { final InputStream xmlStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(xmlFile); try { final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(new StringReader("")); } }); final Document document = builder.parse(xmlStream); if (document.getDoctype() == null) { return null; } return document.getDoctype().getSystemId(); } catch (Exception e) { throw new RuntimeException("Unable to resolve dtd for " + xmlFile, e); } } }
DtdResolver { public String resolveDtdLocation(final String xmlFile) { final InputStream xmlStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(xmlFile); try { final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(new StringReader("")); } }); final Document document = builder.parse(xmlStream); if (document.getDoctype() == null) { return null; } return document.getDoctype().getSystemId(); } catch (Exception e) { throw new RuntimeException("Unable to resolve dtd for " + xmlFile, e); } }  }
DtdResolver { public String resolveDtdLocation(final String xmlFile) { final InputStream xmlStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(xmlFile); try { final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(new StringReader("")); } }); final Document document = builder.parse(xmlStream); if (document.getDoctype() == null) { return null; } return document.getDoctype().getSystemId(); } catch (Exception e) { throw new RuntimeException("Unable to resolve dtd for " + xmlFile, e); } }  String resolveDtdLocation(final String xmlFile); String resolveDtdLocationFullPath(final String xml); }
DtdResolver { public String resolveDtdLocation(final String xmlFile) { final InputStream xmlStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(xmlFile); try { final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(new StringReader("")); } }); final Document document = builder.parse(xmlStream); if (document.getDoctype() == null) { return null; } return document.getDoctype().getSystemId(); } catch (Exception e) { throw new RuntimeException("Unable to resolve dtd for " + xmlFile, e); } }  String resolveDtdLocation(final String xmlFile); String resolveDtdLocationFullPath(final String xml);  }