001 /*
002 * Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 // SAX entity resolver.
027 // http://www.saxproject.org
028 // No warranty; no copyright -- use this as you will.
029 // $Id: EntityResolver.java,v 1.2 2004/11/03 22:44:52 jsuttor Exp $
030 package org.xml.sax;
031
032 import java.io.IOException;
033
034 /**
035 * Basic interface for resolving entities.
036 *
037 * <blockquote>
038 * <em>This module, both source code and documentation, is in the
039 * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
040 * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
041 * for further information.
042 * </blockquote>
043 *
044 * <p>If a SAX application needs to implement customized handling
045 * for external entities, it must implement this interface and
046 * register an instance with the SAX driver using the
047 * {@link org.xml.sax.XMLReader#setEntityResolver setEntityResolver}
048 * method.</p>
049 *
050 * <p>The XML reader will then allow the application to intercept any
051 * external entities (including the external DTD subset and external
052 * parameter entities, if any) before including them.</p>
053 *
054 * <p>Many SAX applications will not need to implement this interface,
055 * but it will be especially useful for applications that build
056 * XML documents from databases or other specialised input sources,
057 * or for applications that use URI types other than URLs.</p>
058 *
059 * <p>The following resolver would provide the application
060 * with a special character stream for the entity with the system
061 * identifier "http://www.myhost.com/today":</p>
062 *
063 * <pre>
064 * import org.xml.sax.EntityResolver;
065 * import org.xml.sax.InputSource;
066 *
067 * public class MyResolver implements EntityResolver {
068 * public InputSource resolveEntity (String publicId, String systemId)
069 * {
070 * if (systemId.equals("http://www.myhost.com/today")) {
071 * // return a special input source
072 * MyReader reader = new MyReader();
073 * return new InputSource(reader);
074 * } else {
075 * // use the default behaviour
076 * return null;
077 * }
078 * }
079 * }
080 * </pre>
081 *
082 * <p>The application can also use this interface to redirect system
083 * identifiers to local URIs or to look up replacements in a catalog
084 * (possibly by using the public identifier).</p>
085 *
086 * @since SAX 1.0
087 * @author David Megginson
088 * @version 2.0.1 (sax2r2)
089 * @see org.xml.sax.XMLReader#setEntityResolver
090 * @see org.xml.sax.InputSource
091 */
092 public interface EntityResolver {
093
094 /**
095 * Allow the application to resolve external entities.
096 *
097 * <p>The parser will call this method before opening any external
098 * entity except the top-level document entity. Such entities include
099 * the external DTD subset and external parameter entities referenced
100 * within the DTD (in either case, only if the parser reads external
101 * parameter entities), and external general entities referenced
102 * within the document element (if the parser reads external general
103 * entities). The application may request that the parser locate
104 * the entity itself, that it use an alternative URI, or that it
105 * use data provided by the application (as a character or byte
106 * input stream).</p>
107 *
108 * <p>Application writers can use this method to redirect external
109 * system identifiers to secure and/or local URIs, to look up
110 * public identifiers in a catalogue, or to read an entity from a
111 * database or other input source (including, for example, a dialog
112 * box). Neither XML nor SAX specifies a preferred policy for using
113 * public or system IDs to resolve resources. However, SAX specifies
114 * how to interpret any InputSource returned by this method, and that
115 * if none is returned, then the system ID will be dereferenced as
116 * a URL. </p>
117 *
118 * <p>If the system identifier is a URL, the SAX parser must
119 * resolve it fully before reporting it to the application.</p>
120 *
121 * @param publicId The public identifier of the external entity
122 * being referenced, or null if none was supplied.
123 * @param systemId The system identifier of the external entity
124 * being referenced.
125 * @return An InputSource object describing the new input source,
126 * or null to request that the parser open a regular
127 * URI connection to the system identifier.
128 * @exception org.xml.sax.SAXException Any SAX exception, possibly
129 * wrapping another exception.
130 * @exception java.io.IOException A Java-specific IO exception,
131 * possibly the result of creating a new InputStream
132 * or Reader for the InputSource.
133 * @see org.xml.sax.InputSource
134 */
135 public abstract InputSource resolveEntity(String publicId,
136 String systemId) throws SAXException, IOException;
137
138 }
139
140 // end of EntityResolver.java
|