Java Code Examples for org.xml.sax.SAXException#getCause()

The following examples show how to use org.xml.sax.SAXException#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KnowledgeBuilderImpl.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
/**
 * Load a rule package from XML source.
 *
 * @param reader
 * @throws DroolsParserException
 * @throws IOException
 */
public void addPackageFromXml(final Reader reader) throws DroolsParserException,
        IOException {
    this.resource = new ReaderResource(reader, ResourceType.XDRL);
    final XmlPackageReader xmlReader = new XmlPackageReader(this.configuration.getSemanticModules());
    xmlReader.getParser().setClassLoader(this.rootClassLoader);

    try {
        xmlReader.read(reader);
    } catch (final SAXException e) {
        throw new DroolsParserException(e.toString(),
                                        e.getCause());
    }

    addPackage(xmlReader.getPackageDescr());
    this.resource = null;
}
 
Example 2
Source File: BaseOFXReader.java    From ofx4j with Apache License 2.0 6 votes vote down vote up
/**
 * Parse an OFX version 2 stream from the first OFX element (defined by the {@link #getFirstElementStart() first element characters}).
 *
 * @param reader The reader.
 */
protected void parseV2FromFirstElement(Reader reader) throws IOException, OFXParseException {
  try {
    XMLReader xmlReader = XMLReaderFactory.createXMLReader();
    xmlReader.setFeature("http://xml.org/sax/features/namespaces", false);
    xmlReader.setContentHandler(new OFXV2ContentHandler(getContentHandler()));
    xmlReader.parse(new InputSource(reader));
  }
  catch (SAXException e) {
    if (e.getCause() instanceof OFXParseException) {
      throw (OFXParseException) e.getCause();
    }
    
    throw new OFXParseException(e);
  }
}
 
Example 3
Source File: ErrorDetail.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Translates <code>SAXException</code>.
 * 
 * @param e
 *            a SAX exception to translate
 */

private void translate( SAXException e )
{
	type = DesignFileException.DESIGN_EXCEPTION_INVALID_XML;

	exceptionName = e.getClass( ).getName( );
	message = e.getMessage( );

	description.append( " " ); //$NON-NLS-1$
	description.append( e.getClass( ).getName( ) );
	description.append( " (" ); //$NON-NLS-1$
	description.append( "message : " ); //$NON-NLS-1$
	description.append( e.getMessage( ) );
	description.append( ")" ); //$NON-NLS-1$

	if ( e.getCause( ) != null && e.getCause( ) instanceof RuntimeException )
	{
		translateCausedException( e.getCause( ) );
	}
}
 
Example 4
Source File: SaxExceptionTest.java    From iaf with Apache License 2.0 6 votes vote down vote up
public void inspectSAXException(SAXException e, String expectedInMessage, Locator locator) {
//		System.out.println("SAXException getMessage() ["+e.getMessage()+"]");
//		System.out.println("SAXException toString() ["+e.toString()+"]");
		//e.printStackTrace();
		assertThat("SaxException toString() must show itself",e.toString(),StringContains.containsString(e.getClass().getSimpleName()));
		assertThat("SaxException toString() must only show itself, not also its cause",e.toString(),not(StringContains.containsString("java.io.IOException")));
		if (StringUtils.isNotEmpty(expectedInMessage)) {
			assertThat(e.getMessage(),StringContains.containsString(expectedInMessage));
		}
		assertThat(e,instanceOf(SAXException.class));
		if (locator!=null) {
			assertThat("location info must be shown", e.getMessage(),StringContains.containsString(EXPECTED_LOCATION_MESSAGE_PART));
		}
		Throwable cause2 = e.getCause();
		assertNotNull("SaxException should have proper cause",cause2);
		assertThat(cause2, IsInstanceOf.instanceOf(IOException.class));
		Throwable cause1 = cause2.getCause();
		assertThat(cause1, IsInstanceOf.instanceOf(NullPointerException.class));
		StackTraceElement[] causeTrace=cause1.getStackTrace();
		assertNotNull(causeTrace);
		assertEquals("throwNullPointer", causeTrace[0].getMethodName());
	}
 
Example 5
Source File: KnowledgeBuilderImpl.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
PackageDescr xmlToPackageDescr(Resource resource) throws DroolsParserException,
        IOException {
    final XmlPackageReader xmlReader = new XmlPackageReader(this.configuration.getSemanticModules());
    xmlReader.getParser().setClassLoader(this.rootClassLoader);

    try (Reader reader = resource.getReader()) {
        xmlReader.read(reader);
    } catch (final SAXException e) {
        throw new DroolsParserException(e.toString(),
                                        e.getCause());
    }
    return xmlReader.getPackageDescr();
}