001: // SAX document handler.
002: // http://www.saxproject.org
003: // No warranty; no copyright -- use this as you will.
004: // $Id: DocumentHandler.java,v 1.1.1.1 2002/05/03 23:29:40 yuvalo Exp $
005:
006: package org.xml.sax;
007:
008: /**
009: * Receive notification of general document events.
010: *
011: * <blockquote>
012: * <em>This module, both source code and documentation, is in the
013: * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
014: * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
015: * for further information.
016: * </blockquote>
017: *
018: * <p>This was the main event-handling interface for SAX1; in
019: * SAX2, it has been replaced by {@link org.xml.sax.ContentHandler
020: * ContentHandler}, which provides Namespace support and reporting
021: * of skipped entities. This interface is included in SAX2 only
022: * to support legacy SAX1 applications.</p>
023: *
024: * <p>The order of events in this interface is very important, and
025: * mirrors the order of information in the document itself. For
026: * example, all of an element's content (character data, processing
027: * instructions, and/or subelements) will appear, in order, between
028: * the startElement event and the corresponding endElement event.</p>
029: *
030: * <p>Application writers who do not want to implement the entire
031: * interface can derive a class from HandlerBase, which implements
032: * the default functionality; parser writers can instantiate
033: * HandlerBase to obtain a default handler. The application can find
034: * the location of any document event using the Locator interface
035: * supplied by the Parser through the setDocumentLocator method.</p>
036: *
037: * @deprecated This interface has been replaced by the SAX2
038: * {@link org.xml.sax.ContentHandler ContentHandler}
039: * interface, which includes Namespace support.
040: * @since SAX 1.0
041: * @author David Megginson
042: * @version 2.0.1 (sax2r2)
043: * @see org.xml.sax.Parser#setDocumentHandler
044: * @see org.xml.sax.Locator
045: * @see org.xml.sax.HandlerBase
046: */
047: public interface DocumentHandler {
048:
049: /**
050: * Receive an object for locating the origin of SAX document events.
051: *
052: * <p>SAX parsers are strongly encouraged (though not absolutely
053: * required) to supply a locator: if it does so, it must supply
054: * the locator to the application by invoking this method before
055: * invoking any of the other methods in the DocumentHandler
056: * interface.</p>
057: *
058: * <p>The locator allows the application to determine the end
059: * position of any document-related event, even if the parser is
060: * not reporting an error. Typically, the application will
061: * use this information for reporting its own errors (such as
062: * character content that does not match an application's
063: * business rules). The information returned by the locator
064: * is probably not sufficient for use with a search engine.</p>
065: *
066: * <p>Note that the locator will return correct information only
067: * during the invocation of the events in this interface. The
068: * application should not attempt to use it at any other time.</p>
069: *
070: * @param locator An object that can return the location of
071: * any SAX document event.
072: * @see org.xml.sax.Locator
073: */
074: public abstract void setDocumentLocator(Locator locator);
075:
076: /**
077: * Receive notification of the beginning of a document.
078: *
079: * <p>The SAX parser will invoke this method only once, before any
080: * other methods in this interface or in DTDHandler (except for
081: * setDocumentLocator).</p>
082: *
083: * @exception org.xml.sax.SAXException Any SAX exception, possibly
084: * wrapping another exception.
085: */
086: public abstract void startDocument() throws SAXException;
087:
088: /**
089: * Receive notification of the end of a document.
090: *
091: * <p>The SAX parser will invoke this method only once, and it will
092: * be the last method invoked during the parse. The parser shall
093: * not invoke this method until it has either abandoned parsing
094: * (because of an unrecoverable error) or reached the end of
095: * input.</p>
096: *
097: * @exception org.xml.sax.SAXException Any SAX exception, possibly
098: * wrapping another exception.
099: */
100: public abstract void endDocument() throws SAXException;
101:
102: /**
103: * Receive notification of the beginning of an element.
104: *
105: * <p>The Parser will invoke this method at the beginning of every
106: * element in the XML document; there will be a corresponding
107: * endElement() event for every startElement() event (even when the
108: * element is empty). All of the element's content will be
109: * reported, in order, before the corresponding endElement()
110: * event.</p>
111: *
112: * <p>If the element name has a namespace prefix, the prefix will
113: * still be attached. Note that the attribute list provided will
114: * contain only attributes with explicit values (specified or
115: * defaulted): #IMPLIED attributes will be omitted.</p>
116: *
117: * @param name The element type name.
118: * @param atts The attributes attached to the element, if any.
119: * @exception org.xml.sax.SAXException Any SAX exception, possibly
120: * wrapping another exception.
121: * @see #endElement
122: * @see org.xml.sax.AttributeList
123: */
124: public abstract void startElement(String name, AttributeList atts)
125: throws SAXException;
126:
127: /**
128: * Receive notification of the end of an element.
129: *
130: * <p>The SAX parser will invoke this method at the end of every
131: * element in the XML document; there will be a corresponding
132: * startElement() event for every endElement() event (even when the
133: * element is empty).</p>
134: *
135: * <p>If the element name has a namespace prefix, the prefix will
136: * still be attached to the name.</p>
137: *
138: * @param name The element type name
139: * @exception org.xml.sax.SAXException Any SAX exception, possibly
140: * wrapping another exception.
141: */
142: public abstract void endElement(String name) throws SAXException;
143:
144: /**
145: * Receive notification of character data.
146: *
147: * <p>The Parser will call this method to report each chunk of
148: * character data. SAX parsers may return all contiguous character
149: * data in a single chunk, or they may split it into several
150: * chunks; however, all of the characters in any single event
151: * must come from the same external entity, so that the Locator
152: * provides useful information.</p>
153: *
154: * <p>The application must not attempt to read from the array
155: * outside of the specified range.</p>
156: *
157: * <p>Note that some parsers will report whitespace using the
158: * ignorableWhitespace() method rather than this one (validating
159: * parsers must do so).</p>
160: *
161: * @param ch The characters from the XML document.
162: * @param start The start position in the array.
163: * @param length The number of characters to read from the array.
164: * @exception org.xml.sax.SAXException Any SAX exception, possibly
165: * wrapping another exception.
166: * @see #ignorableWhitespace
167: * @see org.xml.sax.Locator
168: */
169: public abstract void characters(char ch[], int start, int length)
170: throws SAXException;
171:
172: /**
173: * Receive notification of ignorable whitespace in element content.
174: *
175: * <p>Validating Parsers must use this method to report each chunk
176: * of ignorable whitespace (see the W3C XML 1.0 recommendation,
177: * section 2.10): non-validating parsers may also use this method
178: * if they are capable of parsing and using content models.</p>
179: *
180: * <p>SAX parsers may return all contiguous whitespace in a single
181: * chunk, or they may split it into several chunks; however, all of
182: * the characters in any single event must come from the same
183: * external entity, so that the Locator provides useful
184: * information.</p>
185: *
186: * <p>The application must not attempt to read from the array
187: * outside of the specified range.</p>
188: *
189: * @param ch The characters from the XML document.
190: * @param start The start position in the array.
191: * @param length The number of characters to read from the array.
192: * @exception org.xml.sax.SAXException Any SAX exception, possibly
193: * wrapping another exception.
194: * @see #characters
195: */
196: public abstract void ignorableWhitespace(char ch[], int start,
197: int length) throws SAXException;
198:
199: /**
200: * Receive notification of a processing instruction.
201: *
202: * <p>The Parser will invoke this method once for each processing
203: * instruction found: note that processing instructions may occur
204: * before or after the main document element.</p>
205: *
206: * <p>A SAX parser should never report an XML declaration (XML 1.0,
207: * section 2.8) or a text declaration (XML 1.0, section 4.3.1)
208: * using this method.</p>
209: *
210: * @param target The processing instruction target.
211: * @param data The processing instruction data, or null if
212: * none was supplied.
213: * @exception org.xml.sax.SAXException Any SAX exception, possibly
214: * wrapping another exception.
215: */
216: public abstract void processingInstruction(String target,
217: String data) throws SAXException;
218:
219: }
220:
221: // end of DocumentHandler.java
|