Example usage for org.xml.sax SAXException initCause

List of usage examples for org.xml.sax SAXException initCause

Introduction

In this page you can find the example usage for org.xml.sax SAXException initCause.

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:com.microsoft.tfs.core.clients.workitem.internal.form.WIFormParseHandler.java

public static WIFormElement parse(final String xml) {
    final WIFormParseHandler handler = new WIFormParseHandler();

    try {// w w  w. j av  a  2  s .  c  o  m
        final SAXParser parser = SAXUtils.newSAXParser();
        parser.parse(new InputSource(new StringReader(xml)), handler);
    } catch (final SAXException ex) {
        ex.initCause(ex.getException());
        throw new RuntimeException(ex);
    } catch (final Exception ex) {
        throw new RuntimeException(ex);
    }

    return handler.root;
}

From source file:com.granule.json.utils.internal.JSONSAXHandler.java

/**
 * Internal method to end the JSON generation and to write out the resultant JSON text 
 * and reset the internal state of the hander.
 *///from ww w .  ja  va  2  s  .c  om
private void endJSON() throws SAXException {
    if (logger.isLoggable(Level.FINER))
        logger.entering(className, "endJSON()");

    try {
        this.head.writeObject(this.osWriter, 0, true, this.compact);
        this.head = null;
        this.current = null;
        this.previousObjects.clear();
    } catch (Exception ex) {
        SAXException saxEx = new SAXException(ex);
        saxEx.initCause(ex);
        throw saxEx;
    }

    if (logger.isLoggable(Level.FINER))
        logger.exiting(className, "endJSON()");
}

From source file:nl.nn.adapterframework.align.Json2Xml.java

public static String translate(JsonStructure json, URL schemaURL, boolean compactJsonArrays, String rootElement,
        boolean strictSyntax, boolean deepSearch, String targetNamespace, Map<String, Object> overrideValues)
        throws SAXException, IOException {

    // create the ValidatorHandler
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = sf.newSchema(schemaURL);
    ValidatorHandler validatorHandler = schema.newValidatorHandler();

    // create the XSModel
    XMLSchemaLoader xsLoader = new XMLSchemaLoader();
    XSModel xsModel = xsLoader.loadURI(schemaURL.toExternalForm());
    List<XSModel> schemaInformation = new LinkedList<XSModel>();
    schemaInformation.add(xsModel);/*from ww w.  j  av  a  2  s . c  o m*/

    // create the validator, setup the chain
    Json2Xml j2x = new Json2Xml(validatorHandler, schemaInformation, compactJsonArrays, rootElement,
            strictSyntax);
    if (overrideValues != null) {
        j2x.setOverrideValues(overrideValues);
    }
    if (targetNamespace != null) {
        //if (DEBUG) System.out.println("setting targetNamespace ["+targetNamespace+"]");
        j2x.setTargetNamespace(targetNamespace);
    }
    j2x.setDeepSearch(deepSearch);
    Source source = j2x.asSource(json);
    StringWriter writer = new StringWriter();
    StreamResult result = new StreamResult(writer);
    String xml = null;
    try {
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(source, result);
        writer.flush();
        xml = writer.toString();
    } catch (TransformerConfigurationException e) {
        SAXException se = new SAXException(e);
        se.initCause(e);
        throw se;
    } catch (TransformerException e) {
        SAXException se = new SAXException(e);
        se.initCause(e);
        throw se;
    }
    return xml;
}

From source file:uk.co.grahamcox.xml.XmlHandler.java

/**
 * Invoke the given callback on the handler
 * @param method the callback to invoke//from  w  w w.  j  a va  2s  .  c om
 * @param params the parameters of the callback
 * @throws SAXException if an error occurs
 */
private void invokeCallback(Method method, Object[] params) throws SAXException {
    try {
        method.invoke(handler, params);
    } catch (IllegalAccessException ex) {
        LOG.error("Illegal access calling method " + method, ex);
        throw new SAXException("Illegal access calling method " + method, ex);
    } catch (IllegalArgumentException ex) {
        LOG.error("Illegal argument calling method " + method, ex);
        throw new SAXException("Illegal argument calling method " + method, ex);
    } catch (InvocationTargetException ex) {
        LOG.error("Exception occurred calling method " + method, ex);
        SAXException toThrow = new SAXException("An error occurred in method " + method);
        toThrow.initCause(ex.getTargetException());
        throw toThrow;
    }
}