/** * Writes the XML for the given exception. * * <p>If there is a more specialised method for this exception defined in this class, this * method will automatically use the more specific method. * * <p>The default XML for a generic exception is: * <p>The XML return will be: * <pre>{@code <exception class="[class]"> * <message>[message]</message> * <stack-trace>[exception]</stack-trace> * <cause>[cause exception as XML (if any)]</cause> * </exception> * }</pre> * * @param ex The exception to turn to XML. * @param xml The XML writer. * * @throws IOException Only if thrown by the XML writer. */ public static void toXML(Exception ex, XMLWriter xml) throws IOException { toXML(ex, xml, true); }
/** * Returns the source locator as XML. * * <p>Does nothing if the locator is <code>null</code>. * * @param xml the XML writer. * * @throws IOException If thrown by the XML writer. */ @Override public void toXML(XMLWriter xml) throws IOException { xml.openElement("collected"); xml.attribute("level", this._level.toString()); Errors.toXML(this._error, xml, false); xml.closeElement(); }
/** * Returns the specified exception as XML * * @param ex The exception to turn to XML. * @param xml The XML writer. * @param wrap Whether to wrap the XML into an element. * * @throws IOException Only if thrown by the XML writer. */ private static void asSAXParseExceptionXML(SAXParseException ex, XMLWriter xml, boolean wrap) throws IOException { if (wrap) { xml.openElement("exception"); } xml.attribute("type", "SAXParseException"); asExceptionXML(ex, xml, false); // Add the locator toXML(toLocator(ex), xml); if (wrap) { xml.closeElement(); } }
/** * Returns the XML for a generic exception. * * @param ex The exception to turn to XML. * @param xml The XML writer. * @param wrap Whether to wrap the XML into an element. * * @throws IOException Only if thrown by the XML writer. */ private static void asExceptionXML(Exception ex, XMLWriter xml, boolean wrap) throws IOException { if (wrap) { xml.openElement("exception"); } xml.attribute("class", ex.getClass().getName()); xml.element("message", cleanMessage(ex)); xml.element("stack-trace", Errors.getStackTrace(ex, true)); Throwable cause = ex.getCause(); if (cause != null) { xml.openElement("cause"); toXML(cause, xml, false); xml.closeElement(); } if (wrap) { xml.closeElement(); } }
/** * Returns the specified exception as XML * * @param ex The exception to turn to XML. * @param xml The XML writer. * @param wrap Whether to wrap the XML into an element. * * @throws IOException Only if thrown by the XML writer. */ private static void asTransformerExceptionXML(TransformerException ex, XMLWriter xml, boolean wrap) throws IOException { if (wrap) { xml.openElement("exception"); } boolean isConfig = ex instanceof TransformerConfigurationException; xml.attribute("type", isConfig? "TransformerConfigurationException" : "TransformerException"); asExceptionXML(ex, xml, false); // Add the Source locator toXML(ex.getLocator(), xml); if (wrap) { xml.closeElement(); } }
/** * Returns the XML for a generic error. * * @param ex The error to turn to XML. * @param xml The XML writer. * @param wrap Whether to wrap the XML into an element. * * @throws IOException Only if thrown by the XML writer. */ private static void asErrorXML(Error ex, XMLWriter xml, boolean wrap) throws IOException { if (wrap) { xml.openElement("error"); } xml.attribute("class", ex.getClass().getName()); xml.element("message", cleanMessage(ex)); xml.element("stack-trace", Errors.getStackTrace(ex, true)); Throwable cause = ex.getCause(); if (cause != null) { xml.openElement("cause"); toXML(cause, xml, false); xml.closeElement(); } if (wrap) { xml.closeElement(); } }
Errors.toXML(throwable, xml, true);
Errors.toXML(actual, xml);
Errors.toXML(error, xml, false); xml.closeElement(); } else {
Errors.toXML(exception, xml, true);