Search in sources :

Example 76 with SAXParseException

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

the class SAXParseExceptionTest method testSAXParseException_String_String_String_int_int_Exception.

public void testSAXParseException_String_String_String_int_int_Exception() {
    Exception c = new Exception();
    // Ordinary case
    SAXParseException e = new SAXParseException(ERR, PUB, SYS, ROW, COL, c);
    assertEquals(ERR, e.getMessage());
    assertEquals(c, e.getException());
    assertEquals(PUB, e.getPublicId());
    assertEquals(SYS, e.getSystemId());
    assertEquals(ROW, e.getLineNumber());
    assertEquals(COL, e.getColumnNumber());
    // No message
    e = new SAXParseException(null, PUB, SYS, ROW, COL, c);
    assertNull(e.getMessage());
    assertEquals(c, e.getException());
    assertEquals(PUB, e.getPublicId());
    assertEquals(SYS, e.getSystemId());
    assertEquals(ROW, e.getLineNumber());
    assertEquals(COL, e.getColumnNumber());
    // No locator
    e = new SAXParseException(ERR, null, null, -1, -1, c);
    assertEquals(ERR, e.getMessage());
    assertEquals(c, e.getException());
    assertNull(e.getPublicId());
    assertNull(e.getSystemId());
    assertEquals(-1, e.getLineNumber());
    assertEquals(-1, e.getColumnNumber());
    // No cause
    e = new SAXParseException(ERR, PUB, SYS, ROW, COL, null);
    assertEquals(ERR, e.getMessage());
    assertNull(e.getException());
    assertEquals(PUB, e.getPublicId());
    assertEquals(SYS, e.getSystemId());
    assertEquals(ROW, e.getLineNumber());
    assertEquals(COL, e.getColumnNumber());
}
Also used : SAXParseException(org.xml.sax.SAXParseException) SAXParseException(org.xml.sax.SAXParseException)

Example 77 with SAXParseException

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

the class DocumentBuilderTest method testReset.

public void testReset() {
    // Make sure EntityResolver gets reset
    InputStream source = new ByteArrayInputStream("<a>&foo;</a>".getBytes());
    InputStream entity = new ByteArrayInputStream("bar".getBytes());
    MockResolver resolver = new MockResolver();
    resolver.addEntity("foo", "foo", new InputSource(entity));
    Document d;
    try {
        db = dbf.newDocumentBuilder();
        db.setEntityResolver(resolver);
        db.reset();
        d = db.parse(source);
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    Element root = (Element) d.getElementsByTagName("a").item(0);
    assertEquals("foo", ((EntityReference) root.getFirstChild()).getNodeName());
    // Make sure ErrorHandler gets reset
    source = new ByteArrayInputStream("</a>".getBytes());
    MethodLogger logger = new MethodLogger();
    ErrorHandler handler = new MockHandler(logger);
    try {
        db = dbf.newDocumentBuilder();
        db.setErrorHandler(handler);
        db.reset();
        d = db.parse(source);
    } catch (SAXParseException e) {
    // Expected
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    assertEquals(0, logger.size());
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SAXParseException(org.xml.sax.SAXParseException) Element(org.w3c.dom.Element) MockHandler(tests.api.org.xml.sax.support.MockHandler) MockResolver(tests.api.org.xml.sax.support.MockResolver) Document(org.w3c.dom.Document) MethodLogger(tests.api.org.xml.sax.support.MethodLogger) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Example 78 with SAXParseException

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

the class DocumentBuilderTest method testSetErrorHandler.

public void testSetErrorHandler() {
    // Ordinary case
    InputStream source = new ByteArrayInputStream("</a>".getBytes());
    MethodLogger logger = new MethodLogger();
    ErrorHandler handler = new MockHandler(logger);
    try {
        db = dbf.newDocumentBuilder();
        db.setErrorHandler(handler);
        db.parse(source);
    } catch (SAXParseException e) {
    // Expected, ErrorHandler does not mask exception
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    assertEquals("error", logger.getMethod());
    assertTrue(logger.getArgs()[0] instanceof SAXParseException);
    // null case
    source = new ByteArrayInputStream("</a>".getBytes());
    try {
        db = dbf.newDocumentBuilder();
        db.setErrorHandler(null);
        db.parse(source);
    } catch (SAXParseException e) {
    // Expected
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SAXParseException(org.xml.sax.SAXParseException) MockHandler(tests.api.org.xml.sax.support.MockHandler) MethodLogger(tests.api.org.xml.sax.support.MethodLogger) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Example 79 with SAXParseException

use of org.xml.sax.SAXParseException in project ddf by codice.

the class TestInputTransformerErrorHandler method testNormal.

@Test
public void testNormal() throws SAXException {
    inputTransformerErrorHandler = new InputTransformerErrorHandler().configure(new StringBuilder());
    saxParseException = new SAXParseException("Test", "publicId", "systemId", 0, 0);
    inputTransformerErrorHandler.warning(saxParseException);
    assertThat(inputTransformerErrorHandler.getParseWarningsErrors(), is("Warning: URI=systemId Line=0: Test"));
    inputTransformerErrorHandler.error(saxParseException);
    assertThat(inputTransformerErrorHandler.getParseWarningsErrors(), is("Error: URI=systemId Line=0: Test"));
    inputTransformerErrorHandler.warning(saxParseException);
    inputTransformerErrorHandler.error(saxParseException);
    assertThat(inputTransformerErrorHandler.getParseWarningsErrors(), is("Warning: URI=systemId Line=0: Test\nError: URI=systemId Line=0: Test"));
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Test(org.junit.Test)

Example 80 with SAXParseException

use of org.xml.sax.SAXParseException in project intellij-plugins by JetBrains.

the class FileConfigurator method load.

/**
     * @deprecated
     */
public static void load(final ConfigurationBuffer buffer, final Reader r, final String path, final String context, String rootElement) throws ConfigurationException {
    ThreadLocalToolkit.log(new LoadingConfiguration(path));
    Handler h = new Handler(buffer, path, context, rootElement, false);
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
        SAXParser parser = factory.newSAXParser();
        InputSource source = new InputSource(r);
        parser.parse(source, h);
    } catch (SAXConfigurationException e) {
        throw e.innerException;
    } catch (SAXParseException e) {
        throw new ConfigurationException.OtherThrowable(e, null, path, e.getLineNumber());
    } catch (Exception e) {
        throw new ConfigurationException.OtherThrowable(e, null, path, -1);
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXParseException(org.xml.sax.SAXParseException) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXParser(javax.xml.parsers.SAXParser) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

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