01: package org.geoserver.util;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05: import java.util.logging.Level;
06: import java.util.logging.Logger;
07:
08: import org.xml.sax.SAXException;
09: import org.xml.sax.SAXParseException;
10: import org.xml.sax.helpers.DefaultHandler;
11:
12: /**
13: * A simple sax error handle which hold on to errors and warnings
14: * when parsing an xml document.
15: * <p>
16: * If constructed with an instance of {@link java.util.logging.Logger}
17: * errors will be logged.
18: * </p>
19: * @author Justin Deoliveira, The Open Planning Project
20: *
21: */
22: public class ErrorHandler extends DefaultHandler {
23:
24: /**
25: * Logger and level
26: */
27: Logger logger;
28: Level level;
29:
30: public List errors = new ArrayList();
31:
32: public ErrorHandler() {
33:
34: }
35:
36: public ErrorHandler(Logger logger, Level level) {
37: this .logger = logger;
38: this .level = level;
39: }
40:
41: public void error(SAXParseException e) throws SAXException {
42: e(e);
43: super .error(e);
44: }
45:
46: public void fatalError(SAXParseException e) throws SAXException {
47: e(e);
48: super .fatalError(e);
49: }
50:
51: public void warning(SAXParseException e) throws SAXException {
52: //ignore
53: }
54:
55: void e(SAXParseException e) {
56: if (logger != null) {
57: logger.log(level, e.getLocalizedMessage());
58: }
59:
60: errors.add(e);
61: }
62:
63: }
|