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