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