Search in sources :

Example 1 with XmlValidatorContentHandler

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;
}
Also used : XmlValidatorContentHandler(nl.nn.adapterframework.validation.XmlValidatorContentHandler) SAXSource(javax.xml.transform.sax.SAXSource) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NodeList(org.w3c.dom.NodeList) XmlValidatorErrorHandler(nl.nn.adapterframework.validation.XmlValidatorErrorHandler) XMLReader(org.xml.sax.XMLReader) XPathExpressionException(javax.xml.xpath.XPathExpressionException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TransformerException(javax.xml.transform.TransformerException) DocumentException(org.dom4j.DocumentException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with XmlValidatorContentHandler

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;
}
Also used : XmlValidatorContentHandler(nl.nn.adapterframework.validation.XmlValidatorContentHandler) RootValidations(nl.nn.adapterframework.validation.RootValidations) XmlValidatorErrorHandler(nl.nn.adapterframework.validation.XmlValidatorErrorHandler) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SOAPException(javax.xml.soap.SOAPException) SaxException(nl.nn.adapterframework.xml.SaxException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 XmlValidatorContentHandler (nl.nn.adapterframework.validation.XmlValidatorContentHandler)2 XmlValidatorErrorHandler (nl.nn.adapterframework.validation.XmlValidatorErrorHandler)2 SAXException (org.xml.sax.SAXException)2 SAXParseException (org.xml.sax.SAXParseException)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 SOAPException (javax.xml.soap.SOAPException)1 SAXSource (javax.xml.transform.sax.SAXSource)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 RootValidations (nl.nn.adapterframework.validation.RootValidations)1 SaxException (nl.nn.adapterframework.xml.SaxException)1 DocumentException (org.dom4j.DocumentException)1