Search in sources :

Example 86 with TransformerException

use of javax.xml.transform.TransformerException in project robovm by robovm.

the class XPathException method printStackTrace.

/**
   * Print the the trace of methods from where the error
   * originated.  This will trace all nested exception
   * objects, as well as this object.
   * @param s The writer where the dump will be sent to.
   */
public void printStackTrace(java.io.PrintWriter s) {
    if (s == null)
        s = new java.io.PrintWriter(System.err);
    try {
        super.printStackTrace(s);
    } catch (Exception e) {
    }
    boolean isJdk14OrHigher = false;
    try {
        Throwable.class.getMethod("getCause", (Class<?>) null);
        isJdk14OrHigher = true;
    } catch (NoSuchMethodException nsme) {
    // do nothing
    }
    // The following code is only required when using jdk 1.3 or lower               
    if (!isJdk14OrHigher) {
        Throwable exception = m_exception;
        for (int i = 0; (i < 10) && (null != exception); i++) {
            s.println("---------");
            try {
                exception.printStackTrace(s);
            } catch (Exception e) {
                s.println("Could not print stack trace...");
            }
            if (exception instanceof TransformerException) {
                TransformerException se = (TransformerException) exception;
                Throwable prev = exception;
                exception = se.getException();
                if (prev == exception) {
                    exception = null;
                    break;
                }
            } else {
                exception = null;
            }
        }
    }
}
Also used : TransformerException(javax.xml.transform.TransformerException) TransformerException(javax.xml.transform.TransformerException)

Example 87 with TransformerException

use of javax.xml.transform.TransformerException in project robovm by robovm.

the class XPathException method printStackTrace.

/**
   * Print the the trace of methods from where the error
   * originated.  This will trace all nested exception
   * objects, as well as this object.
   * @param s The stream where the dump will be sent to.
   */
public void printStackTrace(java.io.PrintStream s) {
    if (s == null)
        s = System.err;
    try {
        super.printStackTrace(s);
    } catch (Exception e) {
    }
    Throwable exception = m_exception;
    for (int i = 0; (i < 10) && (null != exception); i++) {
        s.println("---------");
        exception.printStackTrace(s);
        if (exception instanceof TransformerException) {
            TransformerException se = (TransformerException) exception;
            Throwable prev = exception;
            exception = se.getException();
            if (prev == exception)
                break;
        } else {
            exception = null;
        }
    }
}
Also used : TransformerException(javax.xml.transform.TransformerException) TransformerException(javax.xml.transform.TransformerException)

Example 88 with TransformerException

use of javax.xml.transform.TransformerException in project robovm by robovm.

the class Expression method error.

/**
   * Tell the user of an error, and probably throw an
   * exception.
   *
   * @param xctxt The XPath runtime context.
   * @param msg An error msgkey that corresponds to one of the constants found
   *            in {@link org.apache.xpath.res.XPATHErrorResources}, which is
   *            a key for a format string.
   * @param args An array of arguments represented in the format string, which
   *             may be null.
   *
   * @throws TransformerException if the current ErrorListoner determines to
   *                              throw an exception.
   *
   * @throws javax.xml.transform.TransformerException
   */
public void error(XPathContext xctxt, String msg, Object[] args) throws javax.xml.transform.TransformerException {
    java.lang.String fmsg = XSLMessages.createXPATHMessage(msg, args);
    if (null != xctxt) {
        ErrorListener eh = xctxt.getErrorListener();
        TransformerException te = new TransformerException(fmsg, this);
        eh.fatalError(te);
    }
}
Also used : ErrorListener(javax.xml.transform.ErrorListener) TransformerException(javax.xml.transform.TransformerException)

Example 89 with TransformerException

use of javax.xml.transform.TransformerException in project robovm by robovm.

the class Expression method warn.

/**
   * Warn the user of an problem.
   *
   * @param xctxt The XPath runtime context.
   * @param msg An error msgkey that corresponds to one of the conststants found
   *            in {@link org.apache.xpath.res.XPATHErrorResources}, which is
   *            a key for a format string.
   * @param args An array of arguments represented in the format string, which
   *             may be null.
   *
   * @throws TransformerException if the current ErrorListoner determines to
   *                              throw an exception.
   *
   * @throws javax.xml.transform.TransformerException
   */
public void warn(XPathContext xctxt, String msg, Object[] args) throws javax.xml.transform.TransformerException {
    java.lang.String fmsg = XSLMessages.createXPATHWarning(msg, args);
    if (null != xctxt) {
        ErrorListener eh = xctxt.getErrorListener();
        // TO DO: Need to get stylesheet Locator from here.
        eh.warning(new TransformerException(fmsg, xctxt.getSAXLocator()));
    }
}
Also used : ErrorListener(javax.xml.transform.ErrorListener) TransformerException(javax.xml.transform.TransformerException)

Example 90 with TransformerException

use of javax.xml.transform.TransformerException in project logger by orhanobut.

the class LoggerPrinter method xml.

@Override
public void xml(@Nullable String xml) {
    if (Utils.isEmpty(xml)) {
        d("Empty/Null xml content");
        return;
    }
    try {
        Source xmlInput = new StreamSource(new StringReader(xml));
        StreamResult xmlOutput = new StreamResult(new StringWriter());
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.transform(xmlInput, xmlOutput);
        d(xmlOutput.getWriter().toString().replaceFirst(">", ">\n"));
    } catch (TransformerException e) {
        e("Invalid xml");
    }
}
Also used : Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) StringWriter(java.io.StringWriter) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) TransformerException(javax.xml.transform.TransformerException)

Aggregations

TransformerException (javax.xml.transform.TransformerException)786 Transformer (javax.xml.transform.Transformer)351 StreamResult (javax.xml.transform.stream.StreamResult)345 DOMSource (javax.xml.transform.dom.DOMSource)298 IOException (java.io.IOException)266 TransformerFactory (javax.xml.transform.TransformerFactory)175 Document (org.w3c.dom.Document)155 StringWriter (java.io.StringWriter)152 SAXException (org.xml.sax.SAXException)152 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)150 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)127 Source (javax.xml.transform.Source)96 StreamSource (javax.xml.transform.stream.StreamSource)90 Element (org.w3c.dom.Element)87 DocumentBuilder (javax.xml.parsers.DocumentBuilder)77 File (java.io.File)70 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)63 Node (org.w3c.dom.Node)62 ByteArrayOutputStream (java.io.ByteArrayOutputStream)58 ErrorListener (javax.xml.transform.ErrorListener)55