Search in sources :

Example 91 with SAXParseException

use of org.xml.sax.SAXParseException in project gocd by gocd.

the class GoPluginDescriptorParser method initDigester.

private static Digester initDigester() throws SAXNotRecognizedException, SAXNotSupportedException {
    Digester digester = new Digester();
    digester.setValidating(true);
    digester.setErrorHandler(new ErrorHandler() {

        @Override
        public void warning(SAXParseException exception) throws SAXException {
            throw new SAXException("XML Schema validation of Plugin Descriptor(plugin.xml) failed", exception);
        }

        @Override
        public void error(SAXParseException exception) throws SAXException {
            throw new SAXException("XML Schema validation of Plugin Descriptor(plugin.xml) failed", exception);
        }

        @Override
        public void fatalError(SAXParseException exception) throws SAXException {
            throw new SAXException("XML Schema validation of Plugin Descriptor(plugin.xml) failed", exception);
        }
    });
    digester.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", XMLConstants.W3C_XML_SCHEMA_NS_URI);
    digester.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", GoPluginDescriptorParser.class.getResourceAsStream("/plugin-descriptor.xsd"));
    return digester;
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) SAXParseException(org.xml.sax.SAXParseException) Digester(org.apache.commons.digester.Digester) SAXException(org.xml.sax.SAXException)

Example 92 with SAXParseException

use of org.xml.sax.SAXParseException in project gocd by gocd.

the class XsdErrorTranslatorTest method shouldHumanizeErrorsDuringCommandSnippetValidationWhenInvalidTagFound.

@Test
public void shouldHumanizeErrorsDuringCommandSnippetValidationWhenInvalidTagFound() throws SAXException {
    translator.error(new SAXParseException("cvc-elt.1: Cannot find the declaration of element 'invalidTag'.", null));
    assertThat(translator.translate(), is("Invalid XML tag \"invalidTag\" found."));
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Test(org.junit.Test)

Example 93 with SAXParseException

use of org.xml.sax.SAXParseException in project gocd by gocd.

the class XsdErrorTranslatorTest method shouldDealWithPatternValidForAnonymousErrors.

@Test
public void shouldDealWithPatternValidForAnonymousErrors() throws SAXException {
    translator.error(new SAXParseException("cvc-pattern-valid: Value 'Ethan's Work (TA)' is not facet-valid with respect to pattern '[^\\s]+' for type '#AnonType_projectIdentifiermingleType'.", null));
    assertThat(translator.translate(), is("Project identifier in Mingle is invalid. \"Ethan's Work (TA)\" should conform to the pattern - [^\\s]+"));
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Test(org.junit.Test)

Example 94 with SAXParseException

use of org.xml.sax.SAXParseException in project gocd by gocd.

the class XsdErrorTranslatorTest method shouldReturnOriginalXsdErrorIfMappingNotDefined.

@Test
public void shouldReturnOriginalXsdErrorIfMappingNotDefined() throws Exception {
    translator.error(new SAXParseException("cvc-elt.1: Cannot find the declaration of element 'element'", null));
    assertThat(translator.translate(), is("Cannot find the declaration of element 'element'"));
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Test(org.junit.Test)

Example 95 with SAXParseException

use of org.xml.sax.SAXParseException in project drools by kiegroup.

the class PatternHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final String objectType = attrs.getValue("object-type");
    if (objectType == null || objectType.trim().equals("")) {
        throw new SAXParseException("<pattern> requires an 'object-type' attribute", parser.getLocator());
    }
    PatternDescr patternDescr = null;
    final String identifier = attrs.getValue("identifier");
    if (identifier == null || identifier.trim().equals("")) {
        patternDescr = new PatternDescr(objectType);
    } else {
        patternDescr = new PatternDescr(objectType, identifier);
    }
    return patternDescr;
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) SAXParseException(org.xml.sax.SAXParseException)

Aggregations

SAXParseException (org.xml.sax.SAXParseException)206 SAXException (org.xml.sax.SAXException)109 IOException (java.io.IOException)75 DocumentBuilder (javax.xml.parsers.DocumentBuilder)53 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)47 Document (org.w3c.dom.Document)47 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)42 InputSource (org.xml.sax.InputSource)39 ErrorHandler (org.xml.sax.ErrorHandler)34 Test (org.junit.Test)28 Element (org.w3c.dom.Element)24 InputStream (java.io.InputStream)20 ArrayList (java.util.ArrayList)18 NodeList (org.w3c.dom.NodeList)18 FileInputStream (java.io.FileInputStream)17 FileNotFoundException (java.io.FileNotFoundException)17 File (java.io.File)16 Node (org.w3c.dom.Node)13 StringReader (java.io.StringReader)12 URL (java.net.URL)11