1. // SAX entity resolver.
  2. // No warranty; no copyright -- use this as you will.
  3. // $Id: EntityResolver.java,v 1.1 2001/05/20 03:12:56 curcuru Exp $
  4. package org.xml.sax;
  5. import java.io.IOException;
  6. /**
  7. * Basic interface for resolving entities.
  8. *
  9. * <blockquote>
  10. * <em>This module, both source code and documentation, is in the
  11. * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
  12. * </blockquote>
  13. *
  14. * <p>If a SAX application needs to implement customized handling
  15. * for external entities, it must implement this interface and
  16. * register an instance with the SAX driver using the
  17. * {@link org.xml.sax.XMLReader#setEntityResolver setEntityResolver}
  18. * method.</p>
  19. *
  20. * <p>The XML reader will then allow the application to intercept any
  21. * external entities (including the external DTD subset and external
  22. * parameter entities, if any) before including them.</p>
  23. *
  24. * <p>Many SAX applications will not need to implement this interface,
  25. * but it will be especially useful for applications that build
  26. * XML documents from databases or other specialised input sources,
  27. * or for applications that use URI types other than URLs.</p>
  28. *
  29. * <p>The following resolver would provide the application
  30. * with a special character stream for the entity with the system
  31. * identifier "http://www.myhost.com/today":</p>
  32. *
  33. * <pre>
  34. * import org.xml.sax.EntityResolver;
  35. * import org.xml.sax.InputSource;
  36. *
  37. * public class MyResolver implements EntityResolver {
  38. * public InputSource resolveEntity (String publicId, String systemId)
  39. * {
  40. * if (systemId.equals("http://www.myhost.com/today")) {
  41. * // return a special input source
  42. * MyReader reader = new MyReader();
  43. * return new InputSource(reader);
  44. * } else {
  45. * // use the default behaviour
  46. * return null;
  47. * }
  48. * }
  49. * }
  50. * </pre>
  51. *
  52. * <p>The application can also use this interface to redirect system
  53. * identifiers to local URIs or to look up replacements in a catalog
  54. * (possibly by using the public identifier).</p>
  55. *
  56. * @since SAX 1.0
  57. * @author David Megginson,
  58. * <a href="mailto:sax@megginson.com">sax@megginson.com</a>
  59. * @version 2.0r2pre
  60. * @see org.xml.sax.Parser#setEntityResolver
  61. * @see org.xml.sax.InputSource
  62. */
  63. public interface EntityResolver {
  64. /**
  65. * Allow the application to resolve external entities.
  66. *
  67. * <p>The Parser will call this method before opening any external
  68. * entity except the top-level document entity (including the
  69. * external DTD subset, external entities referenced within the
  70. * DTD, and external entities referenced within the document
  71. * element): the application may request that the parser resolve
  72. * the entity itself, that it use an alternative URI, or that it
  73. * use an entirely different input source.</p>
  74. *
  75. * <p>Application writers can use this method to redirect external
  76. * system identifiers to secure and/or local URIs, to look up
  77. * public identifiers in a catalogue, or to read an entity from a
  78. * database or other input source (including, for example, a dialog
  79. * box).</p>
  80. *
  81. * <p>If the system identifier is a URL, the SAX parser must
  82. * resolve it fully before reporting it to the application.</p>
  83. *
  84. * @param publicId The public identifier of the external entity
  85. * being referenced, or null if none was supplied.
  86. * @param systemId The system identifier of the external entity
  87. * being referenced.
  88. * @return An InputSource object describing the new input source,
  89. * or null to request that the parser open a regular
  90. * URI connection to the system identifier.
  91. * @exception org.xml.sax.SAXException Any SAX exception, possibly
  92. * wrapping another exception.
  93. * @exception java.io.IOException A Java-specific IO exception,
  94. * possibly the result of creating a new InputStream
  95. * or Reader for the InputSource.
  96. * @see org.xml.sax.InputSource
  97. */
  98. public abstract InputSource resolveEntity (String publicId,
  99. String systemId)
  100. throws SAXException, IOException;
  101. }
  102. // end of EntityResolver.java