001: // LexicalHandler.java - optional handler for lexical parse events.
002: // http://www.saxproject.org
003: // Public Domain: no warranty.
004: // $Id: LexicalHandler.java,v 1.6 2002/02/01 20:06:20 db Exp $
005:
006: package org.xml.sax.ext;
007:
008: import org.xml.sax.SAXException;
009:
010: /**
011: * SAX2 extension handler for lexical events.
012: *
013: * <blockquote>
014: * <em>This module, both source code and documentation, is in the
015: * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
016: * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
017: * for further information.
018: * </blockquote>
019: *
020: * <p>This is an optional extension handler for SAX2 to provide
021: * lexical information about an XML document, such as comments
022: * and CDATA section boundaries.
023: * XML readers are not required to recognize this handler, and it
024: * is not part of core-only SAX2 distributions.</p>
025: *
026: * <p>The events in the lexical handler apply to the entire document,
027: * not just to the document element, and all lexical handler events
028: * must appear between the content handler's startDocument and
029: * endDocument events.</p>
030: *
031: * <p>To set the LexicalHandler for an XML reader, use the
032: * {@link org.xml.sax.XMLReader#setProperty setProperty} method
033: * with the property name
034: * <code>http://xml.org/sax/properties/lexical-handler</code>
035: * and an object implementing this interface (or null) as the value.
036: * If the reader does not report lexical events, it will throw a
037: * {@link org.xml.sax.SAXNotRecognizedException SAXNotRecognizedException}
038: * when you attempt to register the handler.</p>
039: *
040: * @since SAX 2.0 (extensions 1.0)
041: * @author David Megginson
042: * @version 2.0.1 (sax2r2)
043: */
044: public interface LexicalHandler {
045:
046: /**
047: * Report the start of DTD declarations, if any.
048: *
049: * <p>This method is intended to report the beginning of the
050: * DOCTYPE declaration; if the document has no DOCTYPE declaration,
051: * this method will not be invoked.</p>
052: *
053: * <p>All declarations reported through
054: * {@link org.xml.sax.DTDHandler DTDHandler} or
055: * {@link org.xml.sax.ext.DeclHandler DeclHandler} events must appear
056: * between the startDTD and {@link #endDTD endDTD} events.
057: * Declarations are assumed to belong to the internal DTD subset
058: * unless they appear between {@link #startEntity startEntity}
059: * and {@link #endEntity endEntity} events. Comments and
060: * processing instructions from the DTD should also be reported
061: * between the startDTD and endDTD events, in their original
062: * order of (logical) occurrence; they are not required to
063: * appear in their correct locations relative to DTDHandler
064: * or DeclHandler events, however.</p>
065: *
066: * <p>Note that the start/endDTD events will appear within
067: * the start/endDocument events from ContentHandler and
068: * before the first
069: * {@link org.xml.sax.ContentHandler#startElement startElement}
070: * event.</p>
071: *
072: * @param name The document type name.
073: * @param publicId The declared public identifier for the
074: * external DTD subset, or null if none was declared.
075: * @param systemId The declared system identifier for the
076: * external DTD subset, or null if none was declared.
077: * (Note that this is not resolved against the document
078: * base URI.)
079: * @exception SAXException The application may raise an
080: * exception.
081: * @see #endDTD
082: * @see #startEntity
083: */
084: public abstract void startDTD(String name, String publicId,
085: String systemId) throws SAXException;
086:
087: /**
088: * Report the end of DTD declarations.
089: *
090: * <p>This method is intended to report the end of the
091: * DOCTYPE declaration; if the document has no DOCTYPE declaration,
092: * this method will not be invoked.</p>
093: *
094: * @exception SAXException The application may raise an exception.
095: * @see #startDTD
096: */
097: public abstract void endDTD() throws SAXException;
098:
099: /**
100: * Report the beginning of some internal and external XML entities.
101: *
102: * <p>The reporting of parameter entities (including
103: * the external DTD subset) is optional, and SAX2 drivers that
104: * report LexicalHandler events may not implement it; you can use the
105: * <code
106: * >http://xml.org/sax/features/lexical-handler/parameter-entities</code>
107: * feature to query or control the reporting of parameter entities.</p>
108: *
109: * <p>General entities are reported with their regular names,
110: * parameter entities have '%' prepended to their names, and
111: * the external DTD subset has the pseudo-entity name "[dtd]".</p>
112: *
113: * <p>When a SAX2 driver is providing these events, all other
114: * events must be properly nested within start/end entity
115: * events. There is no additional requirement that events from
116: * {@link org.xml.sax.ext.DeclHandler DeclHandler} or
117: * {@link org.xml.sax.DTDHandler DTDHandler} be properly ordered.</p>
118: *
119: * <p>Note that skipped entities will be reported through the
120: * {@link org.xml.sax.ContentHandler#skippedEntity skippedEntity}
121: * event, which is part of the ContentHandler interface.</p>
122: *
123: * <p>Because of the streaming event model that SAX uses, some
124: * entity boundaries cannot be reported under any
125: * circumstances:</p>
126: *
127: * <ul>
128: * <li>general entities within attribute values</li>
129: * <li>parameter entities within declarations</li>
130: * </ul>
131: *
132: * <p>These will be silently expanded, with no indication of where
133: * the original entity boundaries were.</p>
134: *
135: * <p>Note also that the boundaries of character references (which
136: * are not really entities anyway) are not reported.</p>
137: *
138: * <p>All start/endEntity events must be properly nested.
139: *
140: * @param name The name of the entity. If it is a parameter
141: * entity, the name will begin with '%', and if it is the
142: * external DTD subset, it will be "[dtd]".
143: * @exception SAXException The application may raise an exception.
144: * @see #endEntity
145: * @see org.xml.sax.ext.DeclHandler#internalEntityDecl
146: * @see org.xml.sax.ext.DeclHandler#externalEntityDecl
147: */
148: public abstract void startEntity(String name) throws SAXException;
149:
150: /**
151: * Report the end of an entity.
152: *
153: * @param name The name of the entity that is ending.
154: * @exception SAXException The application may raise an exception.
155: * @see #startEntity
156: */
157: public abstract void endEntity(String name) throws SAXException;
158:
159: /**
160: * Report the start of a CDATA section.
161: *
162: * <p>The contents of the CDATA section will be reported through
163: * the regular {@link org.xml.sax.ContentHandler#characters
164: * characters} event; this event is intended only to report
165: * the boundary.</p>
166: *
167: * @exception SAXException The application may raise an exception.
168: * @see #endCDATA
169: */
170: public abstract void startCDATA() throws SAXException;
171:
172: /**
173: * Report the end of a CDATA section.
174: *
175: * @exception SAXException The application may raise an exception.
176: * @see #startCDATA
177: */
178: public abstract void endCDATA() throws SAXException;
179:
180: /**
181: * Report an XML comment anywhere in the document.
182: *
183: * <p>This callback will be used for comments inside or outside the
184: * document element, including comments in the external DTD
185: * subset (if read). Comments in the DTD must be properly
186: * nested inside start/endDTD and start/endEntity events (if
187: * used).</p>
188: *
189: * @param ch An array holding the characters in the comment.
190: * @param start The starting position in the array.
191: * @param length The number of characters to use from the array.
192: * @exception SAXException The application may raise an exception.
193: */
194: public abstract void comment(char ch[], int start, int length)
195: throws SAXException;
196:
197: }
198:
199: // end of LexicalHandler.java
|