001: // SAX entity resolver.
002: // No warranty; no copyright -- use this as you will.
003: // $Id$
004:
005: package org.xml.sax;
006:
007: import java.io.IOException;
008:
009: /**
010: * Basic interface for resolving entities.
011: *
012: * <blockquote>
013: * <em>This module, both source code and documentation, is in the
014: * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
015: * </blockquote>
016: *
017: * <p>If a SAX application needs to implement customized handling
018: * for external entities, it must implement this interface and
019: * register an instance with the SAX driver using the
020: * {@link org.xml.sax.XMLReader#setEntityResolver setEntityResolver}
021: * method.</p>
022: *
023: * <p>The XML reader will then allow the application to intercept any
024: * external entities (including the external DTD subset and external
025: * parameter entities, if any) before including them.</p>
026: *
027: * <p>Many SAX applications will not need to implement this interface,
028: * but it will be especially useful for applications that build
029: * XML documents from databases or other specialised input sources,
030: * or for applications that use URI types other than URLs.</p>
031: *
032: * <p>The following resolver would provide the application
033: * with a special character stream for the entity with the system
034: * identifier "http://www.myhost.com/today":</p>
035: *
036: * <pre>
037: * import org.xml.sax.EntityResolver;
038: * import org.xml.sax.InputSource;
039: *
040: * public class MyResolver implements EntityResolver {
041: * public InputSource resolveEntity (String publicId, String systemId)
042: * {
043: * if (systemId.equals("http://www.myhost.com/today")) {
044: * // return a special input source
045: * MyReader reader = new MyReader();
046: * return new InputSource(reader);
047: * } else {
048: * // use the default behaviour
049: * return null;
050: * }
051: * }
052: * }
053: * </pre>
054: *
055: * <p>The application can also use this interface to redirect system
056: * identifiers to local URIs or to look up replacements in a catalog
057: * (possibly by using the public identifier).</p>
058: *
059: * @since SAX 1.0
060: * @author David Megginson,
061: * <a href="mailto:sax@megginson.com">sax@megginson.com</a>
062: * @version 2.0
063: * @see org.xml.sax.Parser#setEntityResolver
064: * @see org.xml.sax.InputSource
065: */
066: public interface EntityResolver {
067:
068: /**
069: * Allow the application to resolve external entities.
070: *
071: * <p>The Parser will call this method before opening any external
072: * entity except the top-level document entity (including the
073: * external DTD subset, external entities referenced within the
074: * DTD, and external entities referenced within the document
075: * element): the application may request that the parser resolve
076: * the entity itself, that it use an alternative URI, or that it
077: * use an entirely different input source.</p>
078: *
079: * <p>Application writers can use this method to redirect external
080: * system identifiers to secure and/or local URIs, to look up
081: * public identifiers in a catalogue, or to read an entity from a
082: * database or other input source (including, for example, a dialog
083: * box).</p>
084: *
085: * <p>If the system identifier is a URL, the SAX parser must
086: * resolve it fully before reporting it to the application.</p>
087: *
088: * @param publicId The public identifier of the external entity
089: * being referenced, or null if none was supplied.
090: * @param systemId The system identifier of the external entity
091: * being referenced.
092: * @return An InputSource object describing the new input source,
093: * or null to request that the parser open a regular
094: * URI connection to the system identifier.
095: * @exception org.xml.sax.SAXException Any SAX exception, possibly
096: * wrapping another exception.
097: * @exception java.io.IOException A Java-specific IO exception,
098: * possibly the result of creating a new InputStream
099: * or Reader for the InputSource.
100: * @see org.xml.sax.InputSource
101: */
102: public abstract InputSource resolveEntity(String publicId,
103: String systemId) throws SAXException, IOException;
104:
105: }
106:
107: // end of EntityResolver.java
|