/** * 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 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 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(); } }