Example usage for javax.xml.transform TransformerException getCause

List of usage examples for javax.xml.transform TransformerException getCause

Introduction

In this page you can find the example usage for javax.xml.transform TransformerException getCause.

Prototype

@Override
public Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.apache.xml.security.utils.CachedXPathFuncHereAPI.java

/**
 *   Evaluate XPath string to an XObject.
 *   XPath namespace prefixes are resolved from the namespaceNode.
 *   The implementation of this is a little slow, since it creates
 *   a number of objects each time it is called.  This could be optimized
 *   to keep the same objects around, but then thread-safety issues would arise.
 *
 *   @param contextNode The node to start searching from.
 *   @param xpathnode/*from w  w  w.  j a va  2  s  .c o m*/
 *   @param str
 *   @param prefixResolver Will be called if the parser encounters namespace
 *                         prefixes, to resolve the prefixes to URLs.
 *   @return An XObject, which can be used to obtain a string, number, nodelist, etc, 
 *   should never be null.
 *   @see org.apache.xpath.objects.XObject
 *   @see org.apache.xpath.objects.XNull
 *   @see org.apache.xpath.objects.XBoolean
 *   @see org.apache.xpath.objects.XNumber
 *   @see org.apache.xpath.objects.XString
 *   @see org.apache.xpath.objects.XRTreeFrag
 *
 * @throws TransformerException
 */
public XObject eval(Node contextNode, Node xpathnode, String str, PrefixResolver prefixResolver)
        throws TransformerException {
    if (!str.equals(xpathStr)) {
        if (str.indexOf("here()") > 0) {
            context.reset();
            dtmManager = context.getDTMManager();
        }
        try {
            xpath = createXPath(str, prefixResolver);
        } catch (TransformerException ex) {
            //Try to see if it is a problem with the classloader.
            Throwable th = ex.getCause();
            if (th instanceof ClassNotFoundException && th.getMessage().indexOf("FuncHere") > 0) {
                throw new RuntimeException(I18n.translate("endorsed.jdk1.4.0")/*,*/ + ex);
            }
            throw ex;
        }
        xpathStr = str;
    }

    // Execute the XPath, and have it return the result
    if (this.funcHereContext == null) {
        this.funcHereContext = new FuncHereContext(xpathnode, this.dtmManager);
    }

    int ctxtNode = this.funcHereContext.getDTMHandleFromNode(contextNode);

    return xpath.execute(this.funcHereContext, ctxtNode, prefixResolver);
}

From source file:org.geoserver.security.iride.util.xml.transform.ErrorHandlerUtils.java

/**
 * Get a string identifying the location of an error.
 *
 * @param err the exception containing the location information
 * @return a message string describing the location
 *//*from  www  .  j  av a 2s . com*/
private static String getLocationMessage(TransformerException err) {
    TransformerException e = err;

    SourceLocator loc = e.getLocator();
    while (loc == null) {
        if (e.getException() instanceof TransformerException) {
            e = (TransformerException) e.getException();
            loc = e.getLocator();
        } else if (e.getCause() instanceof TransformerException) {
            e = (TransformerException) e.getCause();
            loc = e.getLocator();
        } else {
            return "";
        }
    }

    return getLocationMessageText(loc);
}

From source file:org.jbpm.bpel.xml.util.XmlUtil.java

public static void writeFile(Node node, File file) throws IOException {
    try {//  w ww  .j  av  a 2  s. c  o  m
        // prepare identity transformer
        Transformer xmlWriter = XmlUtil.getTransformerFactory().newTransformer();

        // prepare output stream
        OutputStream fileSink = new BufferedOutputStream(new FileOutputStream(file));
        try {
            xmlWriter.transform(new DOMSource(node), new StreamResult(fileSink));
        } finally {
            fileSink.close();
        }
    } catch (TransformerException e) {
        Throwable cause = e.getCause();
        if (cause instanceof IOException)
            throw (IOException) cause;
        // should not happen
        throw new AssertionError(e);
    }
}