/** * 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. */ public static void toXML(Throwable ex, XMLWriter xml, boolean wrap) throws IOException { if (ex instanceof SAXParseException) { asSAXParseExceptionXML((SAXParseException)ex, xml, wrap); } else if (ex instanceof TransformerException) { asTransformerExceptionXML((TransformerException)ex, xml, wrap); } else if (ex instanceof Exception) { asExceptionXML((Exception)ex, xml, wrap); } else if (ex instanceof Error) { asErrorXML((Error)ex, xml, wrap); } }
/** * Returns a clean message for the specified throwable. * * <p>This method can be used to provide more user-friendly messages by removing the exception * class prefix to the message if the message is identical to that of the exception causing it. * * @param ex the throwable. * * @return a clean message. */ public static String cleanMessage(Throwable ex) { Throwable cause = ex.getCause(); String message = ex.getMessage(); if (message == null) { message = "No message"; } if (cause == null) return message; if (!message.equals(cause.getClass().getName()+": "+cause.getMessage())) return message; else return cleanMessage(cause); }
/** * 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(); } }
/** * 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); }
xml.closeElement(); xml.element("title", toTitle(id)); xml.element("message", Errors.cleanMessage(ex)); Errors.toXML(actual, xml);
xml.attribute("system-id", toWebPath(systemId));
/** * Returns the specified exception as XML. * * <p>The XML for a {@link SAXParseException} is: * <pre>{@code <exception class="[class]" type="SAXParseException"> * <message>[message]</message> * <stack-trace>[exception]</stack-trace> * <cause>[cause exception as XML (if any)]</cause> * <location line="[line]" column="[column]" public-id=[public-id]" system-id="[system-id]"/> * </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(SAXParseException ex, XMLWriter xml) throws IOException { asSAXParseExceptionXML(ex, xml, true); }
/** * Returns the specified exception as XML. * * <p>The XML for a {@link TransformerException} is: * <pre>{@code <exception class="[class]" type="[TransformerException|TransformerConfigException]"> * <message>[message]</message> * <stack-trace>[exception]</stack-trace> * <cause>[cause exception as XML (if any)]</cause> * <location line="[line]" column="[column]" public-id=[public-id]" system-id="[system-id]"/> * </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(TransformerException ex, XMLWriter xml) throws IOException { asTransformerExceptionXML(ex, xml, true); }
/** * 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(); } }
/** * 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(); }
xml.attribute("system-id", toWebPath(systemId));
Errors.toXML(throwable, xml, true);
Errors.toXML(error, xml, false); xml.closeElement(); } else {
Errors.toXML(exception, xml, true);