01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: * (C) 2002, Refractions Reserach Inc.
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation;
10: * version 2.1 of the License.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: */
17: package org.geotools.graph.util;
18:
19: import java.io.Serializable;
20: import java.util.ArrayList;
21: import java.util.Iterator;
22:
23: import org.xml.sax.SAXException;
24: import org.xml.sax.SAXParseException;
25: import org.xml.sax.helpers.DefaultHandler;
26:
27: public class ParseErrorHandler extends DefaultHandler implements
28: Serializable {
29:
30: ArrayList m_parseErrors = null;
31:
32: public ParseErrorHandler() {
33: super ();
34: m_parseErrors = new ArrayList();
35: }
36:
37: public void error(SAXParseException e) throws SAXException {
38: super .error(e);
39: m_parseErrors.add(e);
40: }
41:
42: public void fatalError(SAXParseException e) throws SAXException {
43: super .fatalError(e);
44: m_parseErrors.add(e);
45: }
46:
47: public void reset() {
48: m_parseErrors.clear();
49: }
50:
51: public boolean noErrors() {
52: return (m_parseErrors.size() == 0);
53: }
54:
55: public void printErrors() {
56: for (Iterator itr = m_parseErrors.iterator(); itr.hasNext();) {
57: SAXParseException e = (SAXParseException) itr.next();
58: System.out.println(e.getMessage());
59: }
60: }
61:
62: public String toString() {
63: StringBuffer out = new StringBuffer();
64: for (Iterator itr = m_parseErrors.iterator(); itr.hasNext();) {
65: SAXParseException e = (SAXParseException) itr.next();
66: out.append(e.getMessage());
67: }
68:
69: return (out.toString());
70: }
71: }
|