Search in sources :

Example 11 with LocatorImpl

use of org.xml.sax.helpers.LocatorImpl in project robovm by robovm.

the class XMLReaderAdapterTest method testSetDocumentLocator.

public void testSetDocumentLocator() {
    // Ordinary case
    LocatorImpl locator = new LocatorImpl();
    adapter.setDocumentLocator(locator);
    assertEquals("setDocumentLocator", logger.getMethod());
    assertEquals(new Object[] { locator }, logger.getArgs());
    // null case (for the DocumentHandler itself!)
    adapter.setDocumentHandler(null);
    adapter.setDocumentLocator(locator);
}
Also used : LocatorImpl(org.xml.sax.helpers.LocatorImpl)

Example 12 with LocatorImpl

use of org.xml.sax.helpers.LocatorImpl in project robovm by robovm.

the class Locator2ImplTest method testLocatorImplLocator.

public void testLocatorImplLocator() {
    Locator2Impl inner = new Locator2Impl();
    inner.setPublicId(PUB);
    inner.setSystemId(SYS);
    inner.setLineNumber(ROW);
    inner.setColumnNumber(COL);
    inner.setEncoding(ENC);
    inner.setXMLVersion(XML);
    // Ordinary case
    Locator2Impl outer = new Locator2Impl(inner);
    assertEquals(PUB, outer.getPublicId());
    assertEquals(SYS, outer.getSystemId());
    assertEquals(ROW, outer.getLineNumber());
    assertEquals(COL, outer.getColumnNumber());
    assertEquals(ENC, outer.getEncoding());
    assertEquals(XML, outer.getXMLVersion());
    // Instance of old locator
    outer = new Locator2Impl(new LocatorImpl(inner));
    assertEquals(PUB, outer.getPublicId());
    assertEquals(SYS, outer.getSystemId());
    assertEquals(ROW, outer.getLineNumber());
    assertEquals(COL, outer.getColumnNumber());
    assertEquals(null, outer.getEncoding());
    assertEquals(null, outer.getXMLVersion());
    // No locator
    try {
        outer = new Locator2Impl(null);
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    // Expected
    }
}
Also used : LocatorImpl(org.xml.sax.helpers.LocatorImpl) Locator2Impl(org.xml.sax.ext.Locator2Impl)

Example 13 with LocatorImpl

use of org.xml.sax.helpers.LocatorImpl in project robovm by robovm.

the class DefaultHandlerTest method testFatalError.

public void testFatalError() {
    // Ordinary case
    try {
        h.fatalError(new SAXParseException("Foo", new LocatorImpl()));
        fail("SAXException expected");
    } catch (SAXException e) {
    // Expected
    }
    // No exception
    try {
        h.fatalError(null);
        fail("NullPointerException expected");
    } catch (SAXException e) {
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    // Expected
    }
}
Also used : SAXParseException(org.xml.sax.SAXParseException) LocatorImpl(org.xml.sax.helpers.LocatorImpl) SAXException(org.xml.sax.SAXException)

Example 14 with LocatorImpl

use of org.xml.sax.helpers.LocatorImpl in project robovm by robovm.

the class SAXParseExceptionTest method testSAXParseException_String_Locator_Exception.

public void testSAXParseException_String_Locator_Exception() {
    LocatorImpl l = new LocatorImpl();
    l.setPublicId(PUB);
    l.setSystemId(SYS);
    l.setLineNumber(ROW);
    l.setColumnNumber(COL);
    Exception c = new Exception();
    // Ordinary case
    SAXParseException e = new SAXParseException(ERR, l, 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, l, 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, 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, l, 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) LocatorImpl(org.xml.sax.helpers.LocatorImpl) SAXParseException(org.xml.sax.SAXParseException)

Example 15 with LocatorImpl

use of org.xml.sax.helpers.LocatorImpl 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)

Aggregations

LocatorImpl (org.xml.sax.helpers.LocatorImpl)26 SAXParseException (org.xml.sax.SAXParseException)9 SAXException (org.xml.sax.SAXException)7 SchemaLocationFilter (com.sun.xml.bind.marshaller.SchemaLocationFilter)5 MarshalException (javax.xml.bind.MarshalException)5 IOException (java.io.IOException)3 URL (java.net.URL)3 URLConnection (java.net.URLConnection)3 DocumentImpl (org.apache.harmony.xml.dom.DocumentImpl)3 KXmlParser (org.kxml2.io.KXmlParser)3 DocumentType (org.w3c.dom.DocumentType)3 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)3 Test (org.junit.Test)2 Locator (org.xml.sax.Locator)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Properties (java.util.Properties)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1