001: /* Copyright 2000 - 2001 Quadcap Software. All rights reserved.
002: *
003: * This software is distributed under the Quadcap Free Software License.
004: * This software may be used or modified for any purpose, personal or
005: * commercial. Open Source redistributions are permitted. Commercial
006: * redistribution of larger works derived from, or works which bundle
007: * this software requires a "Commercial Redistribution License"; see
008: * http://www.quadcap.com/purchase.
009: *
010: * Redistributions qualify as "Open Source" under one of the following terms:
011: *
012: * Redistributions are made at no charge beyond the reasonable cost of
013: * materials and delivery.
014: *
015: * Redistributions are accompanied by a copy of the Source Code or by an
016: * irrevocable offer to provide a copy of the Source Code for up to three
017: * years at the cost of materials and delivery. Such redistributions
018: * must allow further use, modification, and redistribution of the Source
019: * Code under substantially the same terms as this license.
020: *
021: * Redistributions of source code must retain the copyright notices as they
022: * appear in each source code file, these license terms, and the
023: * disclaimer/limitation of liability set forth as paragraph 6 below.
024: *
025: * Redistributions in binary form must reproduce this Copyright Notice,
026: * these license terms, and the disclaimer/limitation of liability set
027: * forth as paragraph 6 below, in the documentation and/or other materials
028: * provided with the distribution.
029: *
030: * The Software is provided on an "AS IS" basis. No warranty is
031: * provided that the Software is free of defects, or fit for a
032: * particular purpose.
033: *
034: * Limitation of Liability. Quadcap Software shall not be liable
035: * for any damages suffered by the Licensee or any third party resulting
036: * from use of the Software.
037: */
038:
039: // SAX parser interface.
040: // No warranty; no copyright -- use this as you will.
041: // $Id: Parser.java,v 1.3 2001/01/06 06:11:02 stan Exp $
042: package org.xml.sax;
043:
044: import java.io.IOException;
045: import java.util.Locale;
046:
047: /**
048: * Basic interface for SAX (Simple API for XML) parsers.
049: *
050: * <p>All SAX parsers must implement this basic interface: it allows
051: * applications to register handlers for different types of events
052: * and to initiate a parse from a URI, or a character stream.</p>
053: *
054: * <p>All SAX parsers must also implement a zero-argument constructor
055: * (though other constructors are also allowed).</p>
056: *
057: * <p>SAX parsers are reusable but not re-entrant: the application
058: * may reuse a parser object (possibly with a different input source)
059: * once the first parse has completed successfully, but it may not
060: * invoke the parse() methods recursively within a parse.</p>
061: *
062: * @author David Megginson (ak117@freenet.carleton.ca)
063: * @version 1.0
064: * @see org.xml.sax.EntityResolver
065: * @see org.xml.sax.DTDHandler
066: * @see org.xml.sax.DocumentHandler
067: * @see org.xml.sax.ErrorHandler
068: * @see org.xml.sax.HandlerBase
069: * @see org.xml.sax.InputSource
070: */
071: public interface Parser {
072:
073: /**
074: * Allow an application to request a locale for errors and warnings.
075: *
076: * <p>SAX parsers are not required to provide localisation for errors
077: * and warnings; if they cannot support the requested locale,
078: * however, they must throw a SAX exception. Applications may
079: * not request a locale change in the middle of a parse.</p>
080: *
081: * @param locale A Java Locale object.
082: * @exception org.xml.sax.SAXException Throws an exception
083: * (using the previous or default locale) if the
084: * requested locale is not supported.
085: * @see org.xml.sax.SAXException
086: * @see org.xml.sax.SAXParseException
087: */
088: public abstract void setLocale(Locale locale) throws SAXException;
089:
090: /**
091: * Allow an application to register a custom entity resolver.
092: *
093: * <p>If the application does not register an entity resolver, the
094: * SAX parser will resolve system identifiers and open connections
095: * to entities itself (this is the default behaviour implemented in
096: * HandlerBase).</p>
097: *
098: * <p>Applications may register a new or different entity resolver
099: * in the middle of a parse, and the SAX parser must begin using
100: * the new resolver immediately.</p>
101: *
102: * @param resolver The object for resolving entities.
103: * @see EntityResolver
104: * @see HandlerBase
105: */
106: public abstract void setEntityResolver(EntityResolver resolver);
107:
108: /**
109: * Allow an application to register a DTD event handler.
110: *
111: * <p>If the application does not register a DTD handler, all DTD
112: * events reported by the SAX parser will be silently
113: * ignored (this is the default behaviour implemented by
114: * HandlerBase).</p>
115: *
116: * <p>Applications may register a new or different
117: * handler in the middle of a parse, and the SAX parser must
118: * begin using the new handler immediately.</p>
119: *
120: * @param handler The DTD handler.
121: * @see DTDHandler
122: * @see HandlerBase
123: */
124: public abstract void setDTDHandler(DTDHandler handler);
125:
126: /**
127: * Allow an application to register a document event handler.
128: *
129: * <p>If the application does not register a document handler, all
130: * document events reported by the SAX parser will be silently
131: * ignored (this is the default behaviour implemented by
132: * HandlerBase).</p>
133: *
134: * <p>Applications may register a new or different handler in the
135: * middle of a parse, and the SAX parser must begin using the new
136: * handler immediately.</p>
137: *
138: * @param handler The document handler.
139: * @see DocumentHandler
140: * @see HandlerBase
141: */
142: public abstract void setDocumentHandler(DocumentHandler handler);
143:
144: /**
145: * Allow an application to register an error event handler.
146: *
147: * <p>If the application does not register an error event handler,
148: * all error events reported by the SAX parser will be silently
149: * ignored, except for fatalError, which will throw a SAXException
150: * (this is the default behaviour implemented by HandlerBase).</p>
151: *
152: * <p>Applications may register a new or different handler in the
153: * middle of a parse, and the SAX parser must begin using the new
154: * handler immediately.</p>
155: *
156: * @param handler The error handler.
157: * @see ErrorHandler
158: * @see SAXException
159: * @see HandlerBase
160: */
161: public abstract void setErrorHandler(ErrorHandler handler);
162:
163: /**
164: * Parse an XML document.
165: *
166: * <p>The application can use this method to instruct the SAX parser
167: * to begin parsing an XML document from any valid input
168: * source (a character stream, a byte stream, or a URI).</p>
169: *
170: * <p>Applications may not invoke this method while a parse is in
171: * progress (they should create a new Parser instead for each
172: * additional XML document). Once a parse is complete, an
173: * application may reuse the same Parser object, possibly with a
174: * different input source.</p>
175: *
176: * @param source The input source for the top-level of the
177: * XML document.
178: * @exception org.xml.sax.SAXException Any SAX exception, possibly
179: * wrapping another exception.
180: * @exception java.io.IOException An IO exception from the parser,
181: * possibly from a byte stream or character stream
182: * supplied by the application.
183: * @see org.xml.sax.InputSource
184: * @see #parse(java.lang.String)
185: * @see #setEntityResolver
186: * @see #setDTDHandler
187: * @see #setDocumentHandler
188: * @see #setErrorHandler
189: */
190: public abstract void parse(InputSource source) throws SAXException,
191: IOException;
192:
193: /**
194: * Parse an XML document from a system identifier (URI).
195: *
196: * <p>This method is a shortcut for the common case of reading a
197: * document from a system identifier. It is the exact
198: * equivalent of the following:</p>
199: *
200: * <pre>
201: * parse(new InputSource(systemId));
202: * </pre>
203: *
204: * <p>If the system identifier is a URL, it must be fully resolved
205: * by the application before it is passed to the parser.</p>
206: *
207: * @param systemId The system identifier (URI).
208: * @exception org.xml.sax.SAXException Any SAX exception, possibly
209: * wrapping another exception.
210: * @exception java.io.IOException An IO exception from the parser,
211: * possibly from a byte stream or character stream
212: * supplied by the application.
213: * @see #parse(org.xml.sax.InputSource)
214: */
215: public abstract void parse(String systemId) throws SAXException,
216: IOException;
217:
218: }
|