Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/xml/sax/EntityResolver.java
48534 views
/*1* Copyright (c) 2000, 2005, 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*/2425// SAX entity resolver.26// http://www.saxproject.org27// No warranty; no copyright -- use this as you will.28// $Id: EntityResolver.java,v 1.2 2004/11/03 22:44:52 jsuttor Exp $2930package org.xml.sax;3132import java.io.IOException;333435/**36* Basic interface for resolving entities.37*38* <blockquote>39* <em>This module, both source code and documentation, is in the40* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>41* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>42* for further information.43* </blockquote>44*45* <p>If a SAX application needs to implement customized handling46* for external entities, it must implement this interface and47* register an instance with the SAX driver using the48* {@link org.xml.sax.XMLReader#setEntityResolver setEntityResolver}49* method.</p>50*51* <p>The XML reader will then allow the application to intercept any52* external entities (including the external DTD subset and external53* parameter entities, if any) before including them.</p>54*55* <p>Many SAX applications will not need to implement this interface,56* but it will be especially useful for applications that build57* XML documents from databases or other specialised input sources,58* or for applications that use URI types other than URLs.</p>59*60* <p>The following resolver would provide the application61* with a special character stream for the entity with the system62* identifier "http://www.myhost.com/today":</p>63*64* <pre>65* import org.xml.sax.EntityResolver;66* import org.xml.sax.InputSource;67*68* public class MyResolver implements EntityResolver {69* public InputSource resolveEntity (String publicId, String systemId)70* {71* if (systemId.equals("http://www.myhost.com/today")) {72* // return a special input source73* MyReader reader = new MyReader();74* return new InputSource(reader);75* } else {76* // use the default behaviour77* return null;78* }79* }80* }81* </pre>82*83* <p>The application can also use this interface to redirect system84* identifiers to local URIs or to look up replacements in a catalog85* (possibly by using the public identifier).</p>86*87* @since SAX 1.088* @author David Megginson89* @see org.xml.sax.XMLReader#setEntityResolver90* @see org.xml.sax.InputSource91*/92public interface EntityResolver {939495/**96* Allow the application to resolve external entities.97*98* <p>The parser will call this method before opening any external99* entity except the top-level document entity. Such entities include100* the external DTD subset and external parameter entities referenced101* within the DTD (in either case, only if the parser reads external102* parameter entities), and external general entities referenced103* within the document element (if the parser reads external general104* entities). The application may request that the parser locate105* the entity itself, that it use an alternative URI, or that it106* use data provided by the application (as a character or byte107* input stream).</p>108*109* <p>Application writers can use this method to redirect external110* system identifiers to secure and/or local URIs, to look up111* public identifiers in a catalogue, or to read an entity from a112* database or other input source (including, for example, a dialog113* box). Neither XML nor SAX specifies a preferred policy for using114* public or system IDs to resolve resources. However, SAX specifies115* how to interpret any InputSource returned by this method, and that116* if none is returned, then the system ID will be dereferenced as117* a URL. </p>118*119* <p>If the system identifier is a URL, the SAX parser must120* resolve it fully before reporting it to the application.</p>121*122* @param publicId The public identifier of the external entity123* being referenced, or null if none was supplied.124* @param systemId The system identifier of the external entity125* being referenced.126* @return An InputSource object describing the new input source,127* or null to request that the parser open a regular128* URI connection to the system identifier.129* @exception org.xml.sax.SAXException Any SAX exception, possibly130* wrapping another exception.131* @exception java.io.IOException A Java-specific IO exception,132* possibly the result of creating a new InputStream133* or Reader for the InputSource.134* @see org.xml.sax.InputSource135*/136public abstract InputSource resolveEntity (String publicId,137String systemId)138throws SAXException, IOException;139140}141142// end of EntityResolver.java143144145