Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/xml/sax/ext/EntityResolver2.java
48576 views
/*1* Copyright (c) 2004, 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// EntityResolver2.java - Extended SAX entity resolver.26// http://www.saxproject.org27// No warranty; no copyright -- use this as you will.28// $Id: EntityResolver2.java,v 1.2 2004/11/03 22:49:08 jsuttor Exp $2930package org.xml.sax.ext;3132import java.io.IOException;3334import org.xml.sax.EntityResolver;35import org.xml.sax.InputSource;36import org.xml.sax.XMLReader;37import org.xml.sax.SAXException;383940/**41* Extended interface for mapping external entity references to input42* sources, or providing a missing external subset. The43* {@link XMLReader#setEntityResolver XMLReader.setEntityResolver()} method44* is used to provide implementations of this interface to parsers.45* When a parser uses the methods in this interface, the46* {@link EntityResolver2#resolveEntity EntityResolver2.resolveEntity()}47* method (in this interface) is used <em>instead of</em> the older (SAX 1.0)48* {@link EntityResolver#resolveEntity EntityResolver.resolveEntity()} method.49*50* <blockquote>51* <em>This module, both source code and documentation, is in the52* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>53* </blockquote>54*55* <p>If a SAX application requires the customized handling which this56* interface defines for external entities, it must ensure that it uses57* an XMLReader with the58* <em>http://xml.org/sax/features/use-entity-resolver2</em> feature flag59* set to <em>true</em> (which is its default value when the feature is60* recognized). If that flag is unrecognized, or its value is false,61* or the resolver does not implement this interface, then only the62* {@link EntityResolver} method will be used.63* </p>64*65* <p>That supports three categories of application that modify entity66* resolution. <em>Old Style</em> applications won't know about this interface;67* they will provide an EntityResolver.68* <em>Transitional Mode</em> provide an EntityResolver2 and automatically69* get the benefit of its methods in any systems (parsers or other tools)70* supporting it, due to polymorphism.71* Both <em>Old Style</em> and <em>Transitional Mode</em> applications will72* work with any SAX2 parser.73* <em>New style</em> applications will fail to run except on SAX2 parsers74* that support this particular feature.75* They will insist that feature flag have a value of "true", and the76* EntityResolver2 implementation they provide might throw an exception77* if the original SAX 1.0 style entity resolution method is invoked.78* </p>79*80* @see org.xml.sax.XMLReader#setEntityResolver81*82* @since SAX 2.0 (extensions 1.1 alpha)83* @author David Brownell84*/85public interface EntityResolver2 extends EntityResolver86{87/**88* Allows applications to provide an external subset for documents89* that don't explicitly define one. Documents with DOCTYPE declarations90* that omit an external subset can thus augment the declarations91* available for validation, entity processing, and attribute processing92* (normalization, defaulting, and reporting types including ID).93* This augmentation is reported94* through the {@link LexicalHandler#startDTD startDTD()} method as if95* the document text had originally included the external subset;96* this callback is made before any internal subset data or errors97* are reported.</p>98*99* <p>This method can also be used with documents that have no DOCTYPE100* declaration. When the root element is encountered,101* but no DOCTYPE declaration has been seen, this method is102* invoked. If it returns a value for the external subset, that root103* element is declared to be the root element, giving the effect of104* splicing a DOCTYPE declaration at the end the prolog of a document105* that could not otherwise be valid. The sequence of parser callbacks106* in that case logically resembles this:</p>107*108* <pre>109* ... comments and PIs from the prolog (as usual)110* startDTD ("rootName", source.getPublicId (), source.getSystemId ());111* startEntity ("[dtd]");112* ... declarations, comments, and PIs from the external subset113* endEntity ("[dtd]");114* endDTD ();115* ... then the rest of the document (as usual)116* startElement (..., "rootName", ...);117* </pre>118*119* <p>Note that the InputSource gets no further resolution.120* Implementations of this method may wish to invoke121* {@link #resolveEntity resolveEntity()} to gain benefits such as use122* of local caches of DTD entities. Also, this method will never be123* used by a (non-validating) processor that is not including external124* parameter entities. </p>125*126* <p>Uses for this method include facilitating data validation when127* interoperating with XML processors that would always require128* undesirable network accesses for external entities, or which for129* other reasons adopt a "no DTDs" policy.130* Non-validation motives include forcing documents to include DTDs so131* that attributes are handled consistently.132* For example, an XPath processor needs to know which attibutes have133* type "ID" before it can process a widely used type of reference.</p>134*135* <p><strong>Warning:</strong> Returning an external subset modifies136* the input document. By providing definitions for general entities,137* it can make a malformed document appear to be well formed.138* </p>139*140* @param name Identifies the document root element. This name comes141* from a DOCTYPE declaration (where available) or from the actual142* root element.143* @param baseURI The document's base URI, serving as an additional144* hint for selecting the external subset. This is always an absolute145* URI, unless it is null because the XMLReader was given an InputSource146* without one.147*148* @return An InputSource object describing the new external subset149* to be used by the parser, or null to indicate that no external150* subset is provided.151*152* @exception SAXException Any SAX exception, possibly wrapping153* another exception.154* @exception IOException Probably indicating a failure to create155* a new InputStream or Reader, or an illegal URL.156*/157public InputSource getExternalSubset (String name, String baseURI)158throws SAXException, IOException;159160/**161* Allows applications to map references to external entities into input162* sources, or tell the parser it should use conventional URI resolution.163* This method is only called for external entities which have been164* properly declared.165* This method provides more flexibility than the {@link EntityResolver}166* interface, supporting implementations of more complex catalogue167* schemes such as the one defined by the <a href=168"http://www.oasis-open.org/committees/entity/spec-2001-08-06.html"169>OASIS XML Catalogs</a> specification.</p>170*171* <p>Parsers configured to use this resolver method will call it172* to determine the input source to use for any external entity173* being included because of a reference in the XML text.174* That excludes the document entity, and any external entity returned175* by {@link #getExternalSubset getExternalSubset()}.176* When a (non-validating) processor is configured not to include177* a class of entities (parameter or general) through use of feature178* flags, this method is not invoked for such entities. </p>179*180* <p>Note that the entity naming scheme used here is the same one181* used in the {@link LexicalHandler}, or in the {@link182org.xml.sax.ContentHandler#skippedEntity183ContentHandler.skippedEntity()}184* method. </p>185*186* @param name Identifies the external entity being resolved.187* Either "[dtd]" for the external subset, or a name starting188* with "%" to indicate a parameter entity, or else the name of189* a general entity. This is never null when invoked by a SAX2190* parser.191* @param publicId The public identifier of the external entity being192* referenced (normalized as required by the XML specification), or193* null if none was supplied.194* @param baseURI The URI with respect to which relative systemIDs195* are interpreted. This is always an absolute URI, unless it is196* null (likely because the XMLReader was given an InputSource without197* one). This URI is defined by the XML specification to be the one198* associated with the "<" starting the relevant declaration.199* @param systemId The system identifier of the external entity200* being referenced; either a relative or absolute URI.201* This is never null when invoked by a SAX2 parser; only declared202* entities, and any external subset, are resolved by such parsers.203*204* @return An InputSource object describing the new input source to205* be used by the parser. Returning null directs the parser to206* resolve the system ID against the base URI and open a connection207* to resulting URI.208*209* @exception SAXException Any SAX exception, possibly wrapping210* another exception.211* @exception IOException Probably indicating a failure to create212* a new InputStream or Reader, or an illegal URL.213*/214public InputSource resolveEntity (215String name,216String publicId,217String baseURI,218String systemId219) throws SAXException, IOException;220}221222223