Search in sources :

Example 86 with SAXParseException

use of org.xml.sax.SAXParseException in project jPOS by jpos.

the class GenericPackagerTest method testGenericContentHandlerErrorThrowsSAXParseException.

@Test
public void testGenericContentHandlerErrorThrowsSAXParseException() throws Throwable {
    SAXParseException ex2 = new SAXParseException("testGenericContentHandlerParam1", "testGenericContentHandlerParam2", "testGenericContentHandlerParam3", 100, 1000);
    try {
        new GenericSubFieldPackager().new GenericContentHandler().error(ex2);
        fail("Expected SAXParseException to be thrown");
    } catch (SAXParseException ex) {
        assertEquals("ex.getMessage()", "testGenericContentHandlerParam1", ex.getMessage());
        assertEquals("ex.getPublicId()", "testGenericContentHandlerParam2", ex.getPublicId());
        assertEquals("ex.getSystemId()", "testGenericContentHandlerParam3", ex.getSystemId());
        assertEquals("ex.getLineNumber()", 100, ex.getLineNumber());
        assertEquals("ex.getColumnNumber()", 1000, ex.getColumnNumber());
        assertNull("ex.getException()", ex.getException());
    }
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Test(org.junit.Test)

Example 87 with SAXParseException

use of org.xml.sax.SAXParseException in project jPOS by jpos.

the class GenericPackagerTest method testGenericContentHandlerFatalErrorThrowsSAXParseException.

@Test
public void testGenericContentHandlerFatalErrorThrowsSAXParseException() throws Throwable {
    SAXParseException ex2 = new SAXParseException("testGenericContentHandlerParam1", new LocatorImpl());
    try {
        new GenericPackager().new GenericContentHandler().fatalError(ex2);
        fail("Expected SAXParseException to be thrown");
    } catch (SAXParseException ex) {
        assertEquals("ex.getMessage()", "testGenericContentHandlerParam1", ex.getMessage());
        assertNull("ex.getPublicId()", ex.getPublicId());
        assertNull("ex.getSystemId()", ex.getSystemId());
        assertEquals("ex.getLineNumber()", 0, ex.getLineNumber());
        assertEquals("ex.getColumnNumber()", 0, ex.getColumnNumber());
        assertNull("ex.getException()", ex.getException());
    }
}
Also used : SAXParseException(org.xml.sax.SAXParseException) LocatorImpl(org.xml.sax.helpers.LocatorImpl) Test(org.junit.Test)

Example 88 with SAXParseException

use of org.xml.sax.SAXParseException in project cxf by apache.

the class XMLTypeCreator method readAegisFile.

private Document readAegisFile(InputStream is, final String path) throws IOException {
    DocumentBuilder documentBuilder;
    try {
        documentBuilder = AEGIS_DOCUMENT_BUILDER_FACTORY.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        LOG.log(Level.SEVERE, "Unable to create a document builder, e");
        throw new RuntimeException("Unable to create a document builder, e");
    }
    org.w3c.dom.Document doc;
    documentBuilder.setErrorHandler(new ErrorHandler() {

        private String errorMessage(SAXParseException exception) {
            return MessageFormat.format("{0} at {1} line {2} column {3}.", new Object[] { exception.getMessage(), path, Integer.valueOf(exception.getLineNumber()), Integer.valueOf(exception.getColumnNumber()) });
        }

        private void throwDatabindingException(String message) {
            // DatabindingException is quirky. This dance is required to get the full message
            // to where it belongs.
            DatabindingException e = new DatabindingException(message);
            e.setMessage(message);
            throw e;
        }

        public void error(SAXParseException exception) throws SAXException {
            String message = errorMessage(exception);
            LOG.log(Level.SEVERE, message, exception);
            throwDatabindingException(message);
        }

        public void fatalError(SAXParseException exception) throws SAXException {
            String message = errorMessage(exception);
            LOG.log(Level.SEVERE, message, exception);
            throwDatabindingException(message);
        }

        public void warning(SAXParseException exception) throws SAXException {
            LOG.log(Level.INFO, errorMessage(exception), exception);
        }
    });
    try {
        doc = documentBuilder.parse(is);
    } catch (SAXException e) {
        // can't happen due to
        LOG.log(Level.SEVERE, "Error parsing Aegis file.", e);
        // above.
        return null;
    }
    return doc;
}
Also used : DatabindingException(org.apache.cxf.aegis.DatabindingException) ErrorHandler(org.xml.sax.ErrorHandler) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Document(org.w3c.dom.Document) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 89 with SAXParseException

use of org.xml.sax.SAXParseException in project cxf by apache.

the class ApplicationContextTest method testInvalid.

@Test
public void testInvalid() throws Exception {
    String s4 = getClass().getResource("/org/apache/cxf/transport/http_jetty/spring/invalid-beans.xml").toString();
    try {
        new TestApplicationContext(new String[] { S1, s4 }).close();
        fail("Expected XmlBeanDefinitionStoreException not thrown.");
    } catch (XmlBeanDefinitionStoreException ex) {
        assertTrue(ex.getCause() instanceof SAXParseException);
    }
}
Also used : SAXParseException(org.xml.sax.SAXParseException) XmlBeanDefinitionStoreException(org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException) TestApplicationContext(org.apache.cxf.test.TestApplicationContext) Test(org.junit.Test)

Example 90 with SAXParseException

use of org.xml.sax.SAXParseException in project cxf by apache.

the class ApplicationContextTest method testInvalid.

@Test
public void testInvalid() throws Exception {
    String s4 = getClass().getResource("/org/apache/cxf/transport/http_undertow/spring/invalid-beans.xml").toString();
    try {
        new TestApplicationContext(new String[] { S1, s4 }).close();
        fail("Expected XmlBeanDefinitionStoreException not thrown.");
    } catch (XmlBeanDefinitionStoreException ex) {
        assertTrue(ex.getCause() instanceof SAXParseException);
    }
}
Also used : SAXParseException(org.xml.sax.SAXParseException) XmlBeanDefinitionStoreException(org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException) TestApplicationContext(org.apache.cxf.test.TestApplicationContext) Test(org.junit.Test)

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