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());
}
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());
}
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);
}
}
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"));
}
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);
}
}
Aggregations