Home | History | Annotate | Download | only in sax
      1 // SAX parser interface.
      2 // http://www.saxproject.org
      3 // No warranty; no copyright -- use this as you will.
      4 // $Id: Parser.java,v 1.6 2002/01/30 21:13:47 dbrownell Exp $
      5 
      6 package org.xml.sax;
      7 
      8 import java.io.IOException;
      9 import java.util.Locale;
     10 
     11 
     12 /**
     13  * Basic interface for SAX (Simple API for XML) parsers.
     14  *
     15  * <blockquote>
     16  * <em>This module, both source code and documentation, is in the
     17  * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
     18  * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
     19  * for further information.
     20  * </blockquote>
     21  *
     22  * <p>This was the main event supplier interface for SAX1; it has
     23  * been replaced in SAX2 by {@link org.xml.sax.XMLReader XMLReader},
     24  * which includes Namespace support and sophisticated configurability
     25  * and extensibility.</p>
     26  *
     27  * <p>All SAX1 parsers must implement this basic interface: it allows
     28  * applications to register handlers for different types of events
     29  * and to initiate a parse from a URI, or a character stream.</p>
     30  *
     31  * <p>All SAX1 parsers must also implement a zero-argument constructor
     32  * (though other constructors are also allowed).</p>
     33  *
     34  * <p>SAX1 parsers are reusable but not re-entrant: the application
     35  * may reuse a parser object (possibly with a different input source)
     36  * once the first parse has completed successfully, but it may not
     37  * invoke the parse() methods recursively within a parse.</p>
     38  *
     39  * @deprecated This interface has been replaced by the SAX2
     40  *             {@link org.xml.sax.XMLReader XMLReader}
     41  *             interface, which includes Namespace support.
     42  * @since SAX 1.0
     43  * @author David Megginson
     44  * @version 2.0.1 (sax2r2)
     45  * @see org.xml.sax.EntityResolver
     46  * @see org.xml.sax.DTDHandler
     47  * @see org.xml.sax.DocumentHandler
     48  * @see org.xml.sax.ErrorHandler
     49  * @see org.xml.sax.HandlerBase
     50  * @see org.xml.sax.InputSource
     51  */
     52 @Deprecated
     53 public interface Parser
     54 {
     55 
     56     /**
     57      * Allow an application to request a locale for errors and warnings.
     58      *
     59      * <p>SAX parsers are not required to provide localisation for errors
     60      * and warnings; if they cannot support the requested locale,
     61      * however, they must throw a SAX exception.  Applications may
     62      * not request a locale change in the middle of a parse.</p>
     63      *
     64      * @param locale A Java Locale object.
     65      * @exception org.xml.sax.SAXException Throws an exception
     66      *            (using the previous or default locale) if the
     67      *            requested locale is not supported.
     68      * @see org.xml.sax.SAXException
     69      * @see org.xml.sax.SAXParseException
     70      */
     71     public abstract void setLocale (Locale locale)
     72     throws SAXException;
     73 
     74 
     75     /**
     76      * Allow an application to register a custom entity resolver.
     77      *
     78      * <p>If the application does not register an entity resolver, the
     79      * SAX parser will resolve system identifiers and open connections
     80      * to entities itself (this is the default behaviour implemented in
     81      * HandlerBase).</p>
     82      *
     83      * <p>Applications may register a new or different entity resolver
     84      * in the middle of a parse, and the SAX parser must begin using
     85      * the new resolver immediately.</p>
     86      *
     87      * @param resolver The object for resolving entities.
     88      * @see EntityResolver
     89      * @see HandlerBase
     90      */
     91     public abstract void setEntityResolver (EntityResolver resolver);
     92 
     93 
     94     /**
     95      * Allow an application to register a DTD event handler.
     96      *
     97      * <p>If the application does not register a DTD handler, all DTD
     98      * events reported by the SAX parser will be silently
     99      * ignored (this is the default behaviour implemented by
    100      * HandlerBase).</p>
    101      *
    102      * <p>Applications may register a new or different
    103      * handler in the middle of a parse, and the SAX parser must
    104      * begin using the new handler immediately.</p>
    105      *
    106      * @param handler The DTD handler.
    107      * @see DTDHandler
    108      * @see HandlerBase
    109      */
    110     public abstract void setDTDHandler (DTDHandler handler);
    111 
    112 
    113     /**
    114      * Allow an application to register a document event handler.
    115      *
    116      * <p>If the application does not register a document handler, all
    117      * document events reported by the SAX parser will be silently
    118      * ignored (this is the default behaviour implemented by
    119      * HandlerBase).</p>
    120      *
    121      * <p>Applications may register a new or different handler in the
    122      * middle of a parse, and the SAX parser must begin using the new
    123      * handler immediately.</p>
    124      *
    125      * @param handler The document handler.
    126      * @see DocumentHandler
    127      * @see HandlerBase
    128      */
    129     public abstract void setDocumentHandler (DocumentHandler handler);
    130 
    131 
    132     /**
    133      * Allow an application to register an error event handler.
    134      *
    135      * <p>If the application does not register an error event handler,
    136      * all error events reported by the SAX parser will be silently
    137      * ignored, except for fatalError, which will throw a SAXException
    138      * (this is the default behaviour implemented by HandlerBase).</p>
    139      *
    140      * <p>Applications may register a new or different handler in the
    141      * middle of a parse, and the SAX parser must begin using the new
    142      * handler immediately.</p>
    143      *
    144      * @param handler The error handler.
    145      * @see ErrorHandler
    146      * @see SAXException
    147      * @see HandlerBase
    148      */
    149     public abstract void setErrorHandler (ErrorHandler handler);
    150 
    151 
    152     /**
    153      * Parse an XML document.
    154      *
    155      * <p>The application can use this method to instruct the SAX parser
    156      * to begin parsing an XML document from any valid input
    157      * source (a character stream, a byte stream, or a URI).</p>
    158      *
    159      * <p>Applications may not invoke this method while a parse is in
    160      * progress (they should create a new Parser instead for each
    161      * additional XML document).  Once a parse is complete, an
    162      * application may reuse the same Parser object, possibly with a
    163      * different input source.</p>
    164      *
    165      * @param source The input source for the top-level of the
    166      *        XML document.
    167      * @exception org.xml.sax.SAXException Any SAX exception, possibly
    168      *            wrapping another exception.
    169      * @exception java.io.IOException An IO exception from the parser,
    170      *            possibly from a byte stream or character stream
    171      *            supplied by the application.
    172      * @see org.xml.sax.InputSource
    173      * @see #parse(java.lang.String)
    174      * @see #setEntityResolver
    175      * @see #setDTDHandler
    176      * @see #setDocumentHandler
    177      * @see #setErrorHandler
    178      */
    179     public abstract void parse (InputSource source)
    180     throws SAXException, IOException;
    181 
    182 
    183     /**
    184      * Parse an XML document from a system identifier (URI).
    185      *
    186      * <p>This method is a shortcut for the common case of reading a
    187      * document from a system identifier.  It is the exact
    188      * equivalent of the following:</p>
    189      *
    190      * <pre>
    191      * parse(new InputSource(systemId));
    192      * </pre>
    193      *
    194      * <p>If the system identifier is a URL, it must be fully resolved
    195      * by the application before it is passed to the parser.</p>
    196      *
    197      * @param systemId The system identifier (URI).
    198      * @exception org.xml.sax.SAXException Any SAX exception, possibly
    199      *            wrapping another exception.
    200      * @exception java.io.IOException An IO exception from the parser,
    201      *            possibly from a byte stream or character stream
    202      *            supplied by the application.
    203      * @see #parse(org.xml.sax.InputSource)
    204      */
    205     public abstract void parse (String systemId)
    206     throws SAXException, IOException;
    207 
    208 }
    209 
    210 // end of Parser.java
    211