1 /* 2 * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package org.xml.sax; 27 28 29 /** 30 * Basic interface for SAX error handlers. 31 * 32 * <p>If a SAX application needs to implement customized error 33 * handling, it must implement this interface and then register an 34 * instance with the XML reader using the 35 * {@link org.xml.sax.XMLReader#setErrorHandler setErrorHandler} 36 * method. The parser will then report all errors and warnings 37 * through this interface.</p> 38 * 39 * <p><strong>WARNING:</strong> If an application does <em>not</em> 40 * register an ErrorHandler, XML parsing errors will go unreported, 41 * except that <em>SAXParseException</em>s will be thrown for fatal errors. 42 * In order to detect validity errors, an ErrorHandler that does something 43 * with {@link #error error()} calls must be registered.</p> 44 * 45 * <p>For XML processing errors, a SAX driver must use this interface 46 * in preference to throwing an exception: it is up to the application 47 * to decide whether to throw an exception for different types of 48 * errors and warnings. Note, however, that there is no requirement that 49 * the parser continue to report additional errors after a call to 50 * {@link #fatalError fatalError}. In other words, a SAX driver class 51 * may throw an exception after reporting any fatalError. 52 * Also parsers may throw appropriate exceptions for non-XML errors. 53 * For example, {@link XMLReader#parse XMLReader.parse()} would throw 54 * an IOException for errors accessing entities or the document.</p> 55 * 56 * @since 1.4, SAX 1.0 57 * @author David Megginson 58 * @see org.xml.sax.XMLReader#setErrorHandler 59 * @see org.xml.sax.SAXParseException 60 */ 61 public interface ErrorHandler { 62 63 64 /** 65 * Receive notification of a warning. 66 * 67 * <p>SAX parsers will use this method to report conditions that 68 * are not errors or fatal errors as defined by the XML 69 * recommendation. The default behaviour is to take no 70 * action.</p> 71 * 72 * <p>The SAX parser must continue to provide normal parsing events 73 * after invoking this method: it should still be possible for the 74 * application to process the document through to the end.</p> 75 * 76 * <p>Filters may use this method to report other, non-XML warnings 77 * as well.</p> 78 * 79 * @param exception The warning information encapsulated in a 80 * SAX parse exception. 81 * @exception org.xml.sax.SAXException Any SAX exception, possibly 82 * wrapping another exception. 83 * @see org.xml.sax.SAXParseException 84 */ 85 public abstract void warning (SAXParseException exception) 86 throws SAXException; 87 88 89 /** 90 * Receive notification of a recoverable error. 91 * 92 * <p>This corresponds to the definition of "error" in section 1.2 93 * of the W3C XML 1.0 Recommendation. For example, a validating 94 * parser would use this callback to report the violation of a 95 * validity constraint. The default behaviour is to take no 96 * action.</p> 97 * 98 * <p>The SAX parser must continue to provide normal parsing 99 * events after invoking this method: it should still be possible 100 * for the application to process the document through to the end. 101 * If the application cannot do so, then the parser should report 102 * a fatal error even if the XML recommendation does not require 103 * it to do so.</p> 104 * 105 * <p>Filters may use this method to report other, non-XML errors 106 * as well.</p> 107 * 108 * @param exception The error information encapsulated in a 109 * SAX parse exception. 110 * @exception org.xml.sax.SAXException Any SAX exception, possibly 111 * wrapping another exception. 112 * @see org.xml.sax.SAXParseException 113 */ 114 public abstract void error (SAXParseException exception) 115 throws SAXException; 116 117 118 /** 119 * Receive notification of a non-recoverable, fatal error. 120 * 121 * <p> 122 * As defined in section 1.2 of the W3C XML 1.0 Recommendation, fatal errors 123 * are those that would make it impossible for a parser to continue normal 124 * processing. These include violation of a well-formedness constraint, 125 * invalid encoding, and forbidden structural errors as described in the 126 * W3C XML 1.0 Recommendation. 127 * 128 * @apiNote An application must assume that the parser can no longer perform 129 * normal processing after reporting a fatal error and may stop by throwing 130 * a {@link SAXException} without calling {@link ContentHandler#endDocument()}. 131 * In addition, the parser cannot be expected to be able to return accurate 132 * information about the logical structure on the rest of the document even 133 * if it may be able to resume parsing. 134 * 135 * @implNote After invoking this method, the parser may stop processing by 136 * throwing a {@link SAXException}, or implement a feature that can direct 137 * it to continue after a fatal error. In the later case, it may report 138 * events on the rest of the document without any guarantee of correctness. 139 * 140 * @param exception The error information encapsulated in a 141 * {@link SAXParseException}. 142 * @throws SAXException if the application chooses to discontinue the parsing 143 */ 144 public abstract void fatalError (SAXParseException exception) 145 throws SAXException; 146 147 } 148 149 // end of ErrorHandler.java