001: package net.xoetrope.builder.editor;
002:
003: import org.xml.sax.ErrorHandler;
004: import org.xml.sax.SAXException;
005: import org.xml.sax.SAXParseException;
006: import net.xoetrope.xml.jaxp.JaxpXmlParser;
007:
008: /**
009: * An error handler for the JAXP parser
010: * <p> Copyright (c) Xoetrope Ltd., 2002-2003</p>
011: * <p> $Revision: 1.1 $</p>
012: * <p> License: see License.txt</p>
013: */
014: public class XEditorXmlErrorHandler implements ErrorHandler {
015: public XEditorXmlErrorHandler() {
016: JaxpXmlParser.setErrorHandler(this );
017: }
018:
019: /**
020: * Receive notification of a warning.
021: *
022: * <p>SAX parsers will use this method to report conditions that
023: * are not errors or fatal errors as defined by the XML 1.0
024: * recommendation. The default behaviour is to take no action.</p>
025: *
026: * <p>The SAX parser must continue to provide normal parsing events
027: * after invoking this method: it should still be possible for the
028: * application to process the document through to the end.</p>
029: *
030: * <p>Filters may use this method to report other, non-XML warnings
031: * as well.</p>
032: *
033: * @param exception The warning information encapsulated in a
034: * SAX parse exception.
035: * @exception org.xml.sax.SAXException Any SAX exception, possibly
036: * wrapping another exception.
037: * @see org.xml.sax.SAXParseException
038: */
039: public void warning(SAXParseException exception)
040: throws SAXException {
041: System.err.println("Warning (" + exception.getLineNumber()
042: + "," + exception.getColumnNumber() + "): "
043: + exception.getMessage());
044: }
045:
046: /**
047: * Receive notification of a recoverable error.
048: *
049: * <p>This corresponds to the definition of "error" in section 1.2
050: * of the W3C XML 1.0 Recommendation. For example, a validating
051: * parser would use this callback to report the violation of a
052: * validity constraint. The default behaviour is to take no
053: * action.</p>
054: *
055: * <p>The SAX parser must continue to provide normal parsing events
056: * after invoking this method: it should still be possible for the
057: * application to process the document through to the end. If the
058: * application cannot do so, then the parser should report a fatal
059: * error even if the XML 1.0 recommendation does not require it to
060: * do so.</p>
061: *
062: * <p>Filters may use this method to report other, non-XML errors
063: * as well.</p>
064: *
065: * @param exception The error information encapsulated in a
066: * SAX parse exception.
067: * @exception org.xml.sax.SAXException Any SAX exception, possibly
068: * wrapping another exception.
069: * @see org.xml.sax.SAXParseException
070: */
071: public void error(SAXParseException exception) throws SAXException {
072: System.err.println("Error (" + exception.getLineNumber() + ","
073: + exception.getColumnNumber() + "): "
074: + exception.getMessage());
075: }
076:
077: /**
078: * Receive notification of a non-recoverable error.
079: *
080: * <p>This corresponds to the definition of "fatal error" in
081: * section 1.2 of the W3C XML 1.0 Recommendation. For example, a
082: * parser would use this callback to report the violation of a
083: * well-formedness constraint.</p>
084: *
085: * <p>The application must assume that the document is unusable
086: * after the parser has invoked this method, and should continue
087: * (if at all) only for the sake of collecting addition error
088: * messages: in fact, SAX parsers are free to stop reporting any
089: * other events once this method has been invoked.</p>
090: *
091: * @param exception The error information encapsulated in a
092: * SAX parse exception.
093: * @exception org.xml.sax.SAXException Any SAX exception, possibly
094: * wrapping another exception.
095: * @see org.xml.sax.SAXParseException
096: */
097: public void fatalError(SAXParseException exception)
098: throws SAXException {
099: System.err.println("Fatal Error (" + exception.getLineNumber()
100: + "," + exception.getColumnNumber() + "): "
101: + exception.getMessage());
102: }
103: }
|