SAX error handler that collects warnings and errors for later processing.
| 29 | * SAX error handler that collects warnings and errors for later processing. |
| 30 | */ |
| 31 | public class XmlErrorHandler implements ErrorHandler { |
| 32 | |
| 33 | /** |
| 34 | * Default constructor. |
| 35 | */ |
| 36 | public XmlErrorHandler() { |
| 37 | } |
| 38 | |
| 39 | private static final StringManager sm = StringManager.getManager(Constants.PACKAGE_NAME); |
| 40 | |
| 41 | private final List<SAXParseException> errors = new ArrayList<>(); |
| 42 | |
| 43 | private final List<SAXParseException> warnings = new ArrayList<>(); |
| 44 | |
| 45 | @Override |
| 46 | public void error(SAXParseException exception) throws SAXException { |
| 47 | // Collect non-fatal errors |
| 48 | errors.add(exception); |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public void fatalError(SAXParseException exception) throws SAXException { |
| 53 | // Re-throw fatal errors |
| 54 | throw exception; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public void warning(SAXParseException exception) throws SAXException { |
| 59 | // Collect warnings |
| 60 | warnings.add(exception); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Returns the list of collected parsing errors. |
| 65 | * |
| 66 | * @return the list of errors |
| 67 | */ |
| 68 | public List<SAXParseException> getErrors() { |
| 69 | // Internal use only - don't worry about immutability |
| 70 | return errors; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Returns the list of collected parsing warnings. |
| 75 | * |
| 76 | * @return the list of warnings |
| 77 | */ |
| 78 | public List<SAXParseException> getWarnings() { |
| 79 | // Internal use only - don't worry about immutability |
| 80 | return warnings; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Logs all collected warnings and errors to the specified log. |
| 85 | * |
| 86 | * @param log the log to use |
| 87 | * @param source the source of the XML being parsed |
| 88 | */ |
nothing calls this directly
no test coverage detected