use of org.xml.sax.ErrorHandler in project karaf by apache.
the class FeatureDetector method parse.
/**
* Parse a features XML.
*
* @param artifact the features XML to parse.
* @return the parsed document.
* @throws Exception in case of parsing failure.
*/
private Document parse(File artifact) throws Exception {
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler(new ErrorHandler() {
public void warning(SAXParseException exception) throws SAXException {
}
public void error(SAXParseException exception) throws SAXException {
}
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
});
return db.parse(artifact);
}
use of org.xml.sax.ErrorHandler in project tomcat by apache.
the class TestJspDocumentParser method testSchemaValidation.
@Test
public void testSchemaValidation() throws Exception {
getTomcatInstanceTestWebapp(false, true);
String path = "http://localhost:" + getPort() + "/test/valid.jspx";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
dbf.setFeature("http://apache.org/xml/features/validation/schema", true);
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler(new ErrorHandler() {
@Override
public void warning(SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void error(SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
});
Document document = db.parse(path);
Assert.assertEquals("urn:valid", document.getDocumentElement().getNamespaceURI());
Assert.assertEquals("root", document.getDocumentElement().getLocalName());
}
use of org.xml.sax.ErrorHandler in project gocd by gocd.
the class XmlSchema method validate_document_or_file.
IRubyObject validate_document_or_file(ThreadContext context, XmlDocument xmlDocument) {
RubyArray errors = (RubyArray) this.getInstanceVariable("@errors");
ErrorHandler errorHandler = new SchemaErrorHandler(context.getRuntime(), errors);
setErrorHandler(errorHandler);
try {
validate(xmlDocument.getDocument());
} catch (SAXException ex) {
XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
xmlSyntaxError.setException(ex);
errors.append(xmlSyntaxError);
} catch (IOException ex) {
throw context.getRuntime().newIOError(ex.getMessage());
}
return errors;
}
use of org.xml.sax.ErrorHandler in project facebook-recommender-demo by ManuelB.
the class WebXmlTest method testIsWebXmlValid.
@Test
public void testIsWebXmlValid() throws Exception {
// http://www.edankert.com/validate.html
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
factory.setNamespaceAware(true);
DocumentBuilder parser = factory.newDocumentBuilder();
// rethrow all exception so test fails if web.xml is invalid
parser.setErrorHandler(new ErrorHandler() {
@Override
public void warning(SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void error(SAXParseException exception) throws SAXException {
throw exception;
}
});
Document doc = parser.parse("src/main/webapp/WEB-INF/web.xml");
}
use of org.xml.sax.ErrorHandler 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