use of org.xml.sax.EntityResolver in project tinker by Tencent.
the class Configuration method readXmlConfig.
/**
* read args from xml
*/
void readXmlConfig(File xmlConfigFile) throws IOException, ParserConfigurationException, SAXException {
if (!xmlConfigFile.exists()) {
return;
}
System.out.printf("reading config file, %s\n", xmlConfigFile.getAbsolutePath());
BufferedInputStream input = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
input = new BufferedInputStream(new FileInputStream(xmlConfigFile));
InputSource source = new InputSource(input);
factory.setNamespaceAware(false);
factory.setValidating(false);
DocumentBuilder builder = factory.newDocumentBuilder();
// Block any external content resolving actions since we don't need them and a report
// says these actions may cause security problems.
builder.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
return new InputSource();
}
});
Document document = builder.parse(source);
NodeList issues = document.getElementsByTagName(TAG_ISSUE);
for (int i = 0, count = issues.getLength(); i < count; i++) {
Node node = issues.item(i);
Element element = (Element) node;
String id = element.getAttribute(ATTR_ID);
if (id.length() == 0) {
System.err.println("Invalid config file: Missing required issue id attribute");
continue;
}
if (id.equals(PROPERTY_ISSUE)) {
readPropertyFromXml(node);
} else if (id.equals(DEX_ISSUE)) {
readDexPatternsFromXml(node);
} else if (id.equals(SO_ISSUE)) {
readLibPatternsFromXml(node);
} else if (id.equals(RES_ISSUE)) {
readResPatternsFromXml(node);
} else if (id.equals(PACKAGE_CONFIG_ISSUE)) {
readPackageConfigFromXml(node);
} else if (id.equals(SIGN_ISSUE)) {
if (mUseSignAPk) {
readSignFromXml(node);
}
} else if (id.equals(ARKHOT_ISSUE)) {
readArkHotPropertyFromXml(node);
} else {
System.err.println("unknown issue " + id);
}
}
} finally {
IOHelper.closeQuietly(input);
}
}
use of org.xml.sax.EntityResolver in project Mycat-Server by MyCATApache.
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);
}
Aggregations