use of nl.nn.adapterframework.validation.XmlValidatorContentHandler in project iaf by ibissource.
the class XmlUtils method isWellFormed.
public static boolean isWellFormed(String input, String root) {
Set<List<String>> rootValidations = null;
if (StringUtils.isNotEmpty(root)) {
List<String> path = new ArrayList<String>();
path.add(root);
rootValidations = new HashSet<List<String>>();
rootValidations.add(path);
}
XmlValidatorContentHandler xmlHandler = new XmlValidatorContentHandler(null, rootValidations, null, true);
XmlValidatorErrorHandler xmlValidatorErrorHandler = new XmlValidatorErrorHandler(xmlHandler, "Is not well formed");
xmlHandler.setXmlValidatorErrorHandler(xmlValidatorErrorHandler);
try {
SAXSource saxSource = stringToSAXSource(input, true, false);
XMLReader xmlReader = saxSource.getXMLReader();
xmlReader.setContentHandler(xmlHandler);
// Prevent message in System.err: [Fatal Error] :-1:-1: Premature end of file.
xmlReader.setErrorHandler(xmlValidatorErrorHandler);
xmlReader.parse(saxSource.getInputSource());
} catch (Exception e) {
return false;
}
return true;
}
use of nl.nn.adapterframework.validation.XmlValidatorContentHandler in project iaf by ibissource.
the class XmlUtils method isWellFormed.
public static boolean isWellFormed(Message input, String root) {
RootValidations rootValidations = null;
if (StringUtils.isNotEmpty(root)) {
rootValidations = new RootValidations(root);
}
XmlValidatorContentHandler xmlHandler = new XmlValidatorContentHandler(null, rootValidations, null, true);
XmlValidatorErrorHandler xmlValidatorErrorHandler = new XmlValidatorErrorHandler(xmlHandler, "Is not well formed");
xmlHandler.setXmlValidatorErrorHandler(xmlValidatorErrorHandler);
try {
// set ErrorHandler to prevent message in System.err: [Fatal Error] :-1:-1: Premature end of file.
parseXml(input.asInputSource(), xmlHandler, xmlValidatorErrorHandler);
} catch (Exception e) {
return false;
}
return true;
}
Aggregations