use of org.xml.sax.EntityResolver in project robovm by robovm.
the class XMLFilterImplTest method testGetSetEntityResolver.
public void testGetSetEntityResolver() {
EntityResolver resolver = new MockResolver();
parent.setEntityResolver(resolver);
assertEquals(resolver, parent.getEntityResolver());
parent.setEntityResolver(null);
assertEquals(null, parent.getEntityResolver());
}
use of org.xml.sax.EntityResolver in project cobar by alibaba.
the class ConfigUtil method getDocument.
public static Document getDocument(final InputStream dtd, InputStream xml) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(false);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) {
return new InputSource(dtd);
}
});
builder.setErrorHandler(new ErrorHandler() {
@Override
public void warning(SAXParseException e) {
}
@Override
public void error(SAXParseException e) throws SAXException {
throw e;
}
@Override
public void fatalError(SAXParseException e) throws SAXException {
throw e;
}
});
return builder.parse(xml);
}
use of org.xml.sax.EntityResolver in project Asqatasun by Asqatasun.
the class KbCsvMojo method getUrls.
private List<String> getUrls(String url) throws JDOMException, JaxenException, IOException {
SAXBuilder builder = new SAXBuilder();
EntityResolver resolver = new XhtmlEntityResolver();
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
builder.setEntityResolver(resolver);
Document document = builder.build(new URL(url));
XPath xpath = new JDOMXPath("//*[@id='resultat']//*[@href]/@href");
List<Attribute> results = xpath.selectNodes(document);
List<String> urls = new ArrayList<String>();
for (Attribute attr : results) {
urls.add(attr.getValue());
}
return urls;
}
use of org.xml.sax.EntityResolver in project tomee by apache.
the class SuperProperties method getDocumentBuilder.
private DocumentBuilder getDocumentBuilder() {
if (builder == null) {
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
try {
builder = factory.newDocumentBuilder();
} catch (final ParserConfigurationException e) {
throw new Error(e);
}
builder.setErrorHandler(new ErrorHandler() {
public void warning(final SAXParseException e) throws SAXException {
throw e;
}
public void error(final SAXParseException e) throws SAXException {
throw e;
}
public void fatalError(final SAXParseException e) throws SAXException {
throw e;
}
});
builder.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException, IOException {
if (systemId.equals(PROP_DTD_NAME)) {
final InputSource result = new InputSource(new StringReader(PROP_DTD));
result.setSystemId(PROP_DTD_NAME);
return result;
}
throw new SAXException("Invalid DOCTYPE declaration: " + systemId);
}
});
}
return builder;
}
Aggregations