001    /*
002     * SimpleErrorHandler.java
003     *
004     * Created on January 8, 2004, 12:08 PM
005     */
006    
007    package cs101.xml;
008    
009    import org.xml.sax.SAXException;
010    import org.xml.sax.ErrorHandler;
011    import org.xml.sax.SAXParseException;
012    
013    /**
014     * A blindingly simple and completely unforgiving xml ErrorHandler. 
015     * It is only suitable for use when all errors and warnings have the
016     * same meaning. All methods in this class will do nothing but
017     * rethrow the supplied SAXParseException as a SAXException with a message
018     * indicating which method was called. While the message could be parsed
019     * to determine which type of error was produced, it is probably better
020     * to extend this class and overide the methods you want to distingush 
021     * or implement your own error handler.
022     *
023     * @author  Patrick G. Heck @, gus.heck@olin.edu
024     */
025    public class SimpleErrorHandler implements ErrorHandler {
026        
027        public static final String ERROR = "Parser Error!";
028        public static final String FATAL_ERROR = "Parser Fatal Error!";
029        public static final String WARNING = "Parser Warning!";
030        
031        /** Creates a new instance of SimpleErrorHandler */
032        public SimpleErrorHandler() {
033        }
034        
035        public void error(SAXParseException spe) throws SAXException {
036            throw new SAXException(ERROR, spe);
037        }
038        
039        public void fatalError(SAXParseException spe) throws SAXException {
040            throw new SAXException(FATAL_ERROR, spe);
041        }
042        
043        public void warning(SAXParseException spe) throws SAXException {
044            throw new SAXException(WARNING, spe);
045        }
046        
047    }