use of org.xml.sax.ErrorHandler in project keycloak by keycloak.
the class JAXBUtil method getSchemaFactory.
private static SchemaFactory getSchemaFactory() {
SchemaFactory scFact = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
// Always install the resolver unless the system property is set
if (SecurityActions.getSystemProperty("org.picketlink.identity.federation.jaxb.ls", null) == null)
scFact.setResourceResolver(new IDFedLSInputResolver());
scFact.setErrorHandler(new ErrorHandler() {
public void error(SAXParseException exception) throws SAXException {
StringBuilder builder = new StringBuilder();
builder.append("Line Number=").append(exception.getLineNumber());
builder.append(" Col Number=").append(exception.getColumnNumber());
builder.append(" Public ID=").append(exception.getPublicId());
builder.append(" System ID=").append(exception.getSystemId());
builder.append(" exc=").append(exception.getLocalizedMessage());
logger.trace("SAX Error:" + builder.toString());
}
public void fatalError(SAXParseException exception) throws SAXException {
StringBuilder builder = new StringBuilder();
builder.append("Line Number=").append(exception.getLineNumber());
builder.append(" Col Number=").append(exception.getColumnNumber());
builder.append(" Public ID=").append(exception.getPublicId());
builder.append(" System ID=").append(exception.getSystemId());
builder.append(" exc=").append(exception.getLocalizedMessage());
logger.error("SAX Fatal Error:" + builder.toString());
}
public void warning(SAXParseException exception) throws SAXException {
StringBuilder builder = new StringBuilder();
builder.append("Line Number=").append(exception.getLineNumber());
builder.append(" Col Number=").append(exception.getColumnNumber());
builder.append(" Public ID=").append(exception.getPublicId());
builder.append(" System ID=").append(exception.getSystemId());
builder.append(" exc=").append(exception.getLocalizedMessage());
logger.trace("SAX Warn:" + builder.toString());
}
});
return scFact;
}
use of org.xml.sax.ErrorHandler in project jphp by jphp-compiler.
the class WrapXmlProcessor method __construct.
@Signature(@Arg(value = "flags", optional = @Optional("0")))
public Memory __construct(final Environment env, Memory... args) throws ParserConfigurationException, TransformerConfigurationException {
transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
builderFactory = DocumentBuilderFactory.newInstance();
builder = builderFactory.newDocumentBuilder();
builder.setErrorHandler(new ErrorHandler() {
@Override
public void warning(SAXParseException exception) throws SAXException {
if (onWarning != null) {
onWarning.callAny(new JavaException(env, exception));
}
}
@Override
public void error(SAXParseException exception) throws SAXException {
if (onError != null) {
onError.callAny(new JavaException(env, exception));
}
}
@Override
public void fatalError(SAXParseException exception) throws SAXException {
if (onFatalError != null) {
onFatalError.callAny(new JavaException(env, exception));
} else {
throw exception;
}
}
});
return Memory.NULL;
}
use of org.xml.sax.ErrorHandler in project wso2-synapse by wso2.
the class SyslogMessageBuilderTest method test.
private SyslogMessage test(String message) throws Exception {
MessageContext msgContext = new MessageContext();
ByteArrayInputStream in = new ByteArrayInputStream(message.getBytes("us-ascii"));
OMElement element = new SyslogMessageBuilder().processDocument(in, null, msgContext);
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new StreamSource(SyslogMessageBuilderTest.class.getResource("schema.xsd").toExternalForm()));
Validator validator = schema.newValidator();
validator.setErrorHandler(new ErrorHandler() {
public void error(SAXParseException exception) throws SAXException {
throw exception;
}
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
public void warning(SAXParseException exception) throws SAXException {
throw exception;
}
});
validator.validate(new OMSource(element));
String pidString = element.getAttributeValue(new QName(SyslogConstants.PID));
return new SyslogMessage(element.getAttributeValue(new QName(SyslogConstants.FACILITY)), element.getAttributeValue(new QName(SyslogConstants.SEVERITY)), element.getAttributeValue(new QName(SyslogConstants.TAG)), pidString == null ? -1 : Integer.parseInt(pidString), element.getText());
}
use of org.xml.sax.ErrorHandler in project knox by apache.
the class TopologyValidator method validateTopology.
public boolean validateTopology() {
errors = new LinkedList<>();
try {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
URL schemaUrl = getClass().getResource("/conf/topology-v1.xsd");
Schema s = schemaFactory.newSchema(schemaUrl);
Validator validator = s.newValidator();
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
final List<SAXParseException> exceptions = new LinkedList<>();
validator.setErrorHandler(new ErrorHandler() {
@Override
public void warning(SAXParseException exception) {
exceptions.add(exception);
}
@Override
public void fatalError(SAXParseException exception) {
exceptions.add(exception);
}
@Override
public void error(SAXParseException exception) {
exceptions.add(exception);
}
});
File xml = new File(filePath);
validator.validate(new StreamSource(xml));
if (!exceptions.isEmpty()) {
for (SAXParseException e : exceptions) {
errors.add("Line: " + e.getLineNumber() + " -- " + e.getMessage());
}
return false;
} else {
return true;
}
} catch (IOException e) {
errors.add("Error reading topology file");
errors.add(e.getMessage());
return false;
} catch (SAXException e) {
errors.add("There was a fatal error in parsing the xml file.");
errors.add(e.getMessage());
return false;
} catch (NullPointerException n) {
errors.add("Error retrieving schema from ClassLoader");
return false;
}
}
Aggregations