use of org.xml.sax.ErrorHandler in project jena by apache.
the class ARPHandlers method setErrorHandler.
/**
* Sets the error handler, for both XML and RDF parse errors. XML errors are
* reported by Xerces, as instances of SAXParseException; the RDF errors are
* reported from ARP as instances of ParseException. Code that needs to
* distingusih between them may look like:
*
* <pre>
* void error( SAXParseException e ) throws SAXException {
* if ( e instanceof com.hp.hpl.jena.rdf.arp.ParseException ) {
* ...
* } else {
* ...
* }
* }
* </pre>
*
* <p>
* See the ARP documentation for ErrorHandler for details of the
* ErrorHandler semantics (in particular how to upgrade a warning to an
* error, and an error to a.errorError).
* </p>
* <p>
* The Xerces/SAX documentation for ErrorHandler is available on the web.
* </p>
*
* @param eh
* The error handler to use.
* @return The previous error handler.
*/
public ErrorHandler setErrorHandler(ErrorHandler eh) {
ErrorHandler old = errorHandler;
errorHandler = eh;
return old;
}
use of org.xml.sax.ErrorHandler in project jena by apache.
the class TestPropEltErrorMsg method runTest.
@Override
protected void runTest() {
Attributes noAtts = new Atts();
final StringBuffer buf = new StringBuffer();
XMLHandler arp = new XMLHandler();
arp.getHandlers().setErrorHandler(new ErrorHandler() {
@Override
public void warning(SAXParseException exception) {
buf.append(exception.getMessage());
buf.append("\n");
}
@Override
public void error(SAXParseException e) {
warning(e);
}
@Override
public void fatalError(SAXParseException e) {
warning(e);
}
});
try {
arp.initParse("http://example.org/", "");
arp.startElement(RDF.getURI(), "RDF", "rdf:RDF", noAtts);
arp.startElement(RDF.getURI(), "Description", "rdf:Description", noAtts);
arp.startElement(RDF.getURI(), "value", "rdf:value", testAtts);
} catch (SAXException e) {
}
// System.err.println("===");
// System.err.println("\""+getName()+"\",");
// System.err.println("---");
String contents = buf.toString();
// System.err.println("\""+(contents.length()>7?contents.substring(7).replace("\n","\\n"):"")+"\",");
assertEquals("test data muddled", rslts[n * 2], getName());
assertTrue("error message has changed.", contents.endsWith(rslts[n * 2 + 1]));
contents = null;
}
use of org.xml.sax.ErrorHandler 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