Path: blob/master/src/java.xml/share/classes/org/xml/sax/Parser.java
40948 views
/*1* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package org.xml.sax;2627import java.io.IOException;28import java.util.Locale;293031/**32* Basic interface for SAX (Simple API for XML) parsers.33*34* <p>This was the main event supplier interface for SAX1; it has35* been replaced in SAX2 by {@link org.xml.sax.XMLReader XMLReader},36* which includes Namespace support and sophisticated configurability37* and extensibility.</p>38*39* <p>All SAX1 parsers must implement this basic interface: it allows40* applications to register handlers for different types of events41* and to initiate a parse from a URI, or a character stream.</p>42*43* <p>All SAX1 parsers must also implement a zero-argument constructor44* (though other constructors are also allowed).</p>45*46* <p>SAX1 parsers are reusable but not re-entrant: the application47* may reuse a parser object (possibly with a different input source)48* once the first parse has completed successfully, but it may not49* invoke the parse() methods recursively within a parse.</p>50*51* @deprecated This interface has been replaced by the SAX252* {@link org.xml.sax.XMLReader XMLReader}53* interface, which includes Namespace support.54* @since 1.4, SAX 1.055* @author David Megginson56* @see org.xml.sax.EntityResolver57* @see org.xml.sax.DTDHandler58* @see org.xml.sax.DocumentHandler59* @see org.xml.sax.ErrorHandler60* @see org.xml.sax.HandlerBase61* @see org.xml.sax.InputSource62*/63@Deprecated(since="1.5")64public interface Parser65{6667/**68* Allow an application to request a locale for errors and warnings.69*70* <p>SAX parsers are not required to provide localisation for errors71* and warnings; if they cannot support the requested locale,72* however, they must throw a SAX exception. Applications may73* not request a locale change in the middle of a parse.</p>74*75* @param locale A Java Locale object.76* @throws org.xml.sax.SAXException Throws an exception77* (using the previous or default locale) if the78* requested locale is not supported.79* @see org.xml.sax.SAXException80* @see org.xml.sax.SAXParseException81*/82public abstract void setLocale (Locale locale)83throws SAXException;848586/**87* Allow an application to register a custom entity resolver.88*89* <p>If the application does not register an entity resolver, the90* SAX parser will resolve system identifiers and open connections91* to entities itself (this is the default behaviour implemented in92* HandlerBase).</p>93*94* <p>Applications may register a new or different entity resolver95* in the middle of a parse, and the SAX parser must begin using96* the new resolver immediately.</p>97*98* @param resolver The object for resolving entities.99* @see EntityResolver100* @see HandlerBase101*/102public abstract void setEntityResolver (EntityResolver resolver);103104105/**106* Allow an application to register a DTD event handler.107*108* <p>If the application does not register a DTD handler, all DTD109* events reported by the SAX parser will be silently110* ignored (this is the default behaviour implemented by111* HandlerBase).</p>112*113* <p>Applications may register a new or different114* handler in the middle of a parse, and the SAX parser must115* begin using the new handler immediately.</p>116*117* @param handler The DTD handler.118* @see DTDHandler119* @see HandlerBase120*/121public abstract void setDTDHandler (DTDHandler handler);122123124/**125* Allow an application to register a document event handler.126*127* <p>If the application does not register a document handler, all128* document events reported by the SAX parser will be silently129* ignored (this is the default behaviour implemented by130* HandlerBase).</p>131*132* <p>Applications may register a new or different handler in the133* middle of a parse, and the SAX parser must begin using the new134* handler immediately.</p>135*136* @param handler The document handler.137* @see DocumentHandler138* @see HandlerBase139*/140public abstract void setDocumentHandler (DocumentHandler handler);141142143/**144* Allow an application to register an error event handler.145*146* <p>If the application does not register an error event handler,147* all error events reported by the SAX parser will be silently148* ignored, except for fatalError, which will throw a SAXException149* (this is the default behaviour implemented by HandlerBase).</p>150*151* <p>Applications may register a new or different handler in the152* middle of a parse, and the SAX parser must begin using the new153* handler immediately.</p>154*155* @param handler The error handler.156* @see ErrorHandler157* @see SAXException158* @see HandlerBase159*/160public abstract void setErrorHandler (ErrorHandler handler);161162163/**164* Parse an XML document.165*166* <p>The application can use this method to instruct the SAX parser167* to begin parsing an XML document from any valid input168* source (a character stream, a byte stream, or a URI).</p>169*170* <p>Applications may not invoke this method while a parse is in171* progress (they should create a new Parser instead for each172* additional XML document). Once a parse is complete, an173* application may reuse the same Parser object, possibly with a174* different input source.</p>175*176* @param source The input source for the top-level of the177* XML document.178* @throws org.xml.sax.SAXException Any SAX exception, possibly179* wrapping another exception.180* @throws java.io.IOException An IO exception from the parser,181* possibly from a byte stream or character stream182* supplied by the application.183* @see org.xml.sax.InputSource184* @see #parse(java.lang.String)185* @see #setEntityResolver186* @see #setDTDHandler187* @see #setDocumentHandler188* @see #setErrorHandler189*/190public abstract void parse (InputSource source)191throws SAXException, IOException;192193194/**195* Parse an XML document from a system identifier (URI).196*197* <p>This method is a shortcut for the common case of reading a198* document from a system identifier. It is the exact199* equivalent of the following:</p>200*201* <pre>202* parse(new InputSource(systemId));203* </pre>204*205* <p>If the system identifier is a URL, it must be fully resolved206* by the application before it is passed to the parser.</p>207*208* @param systemId The system identifier (URI).209* @throws org.xml.sax.SAXException Any SAX exception, possibly210* wrapping another exception.211* @throws java.io.IOException An IO exception from the parser,212* possibly from a byte stream or character stream213* supplied by the application.214* @see #parse(org.xml.sax.InputSource)215*/216public abstract void parse (String systemId)217throws SAXException, IOException;218219}220221// end of Parser.java222223224