aoqi@0: /* aoqi@0: * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.dtdparser; aoqi@0: aoqi@0: import org.xml.sax.Locator; aoqi@0: import org.xml.sax.SAXException; aoqi@0: import org.xml.sax.SAXParseException; aoqi@0: aoqi@0: import java.util.EventListener; aoqi@0: aoqi@0: /** aoqi@0: * All DTD parsing events are signaled through this interface. aoqi@0: */ aoqi@0: public interface DTDEventListener extends EventListener { aoqi@0: aoqi@0: public void setDocumentLocator(Locator loc); aoqi@0: aoqi@0: /** aoqi@0: * Receive notification of a Processing Instruction. aoqi@0: * Processing instructions contain information meaningful aoqi@0: * to the application. aoqi@0: * aoqi@0: * @param target The target of the proceessing instruction aoqi@0: * which should have meaning to the application. aoqi@0: * @param data The instruction itself which should contain aoqi@0: * valid XML characters. aoqi@0: * @throws SAXException aoqi@0: */ aoqi@0: public void processingInstruction(String target, String data) aoqi@0: throws SAXException; aoqi@0: aoqi@0: /** aoqi@0: * Receive notification of a Notation Declaration. aoqi@0: * Notation declarations are used by elements and entities aoqi@0: * for identifying embedded non-XML data. aoqi@0: * aoqi@0: * @param name The notation name, referred to by entities and aoqi@0: * elements. aoqi@0: * @param publicId The public identifier aoqi@0: * @param systemId The system identifier aoqi@0: */ aoqi@0: public void notationDecl(String name, String publicId, String systemId) aoqi@0: throws SAXException; aoqi@0: aoqi@0: /** aoqi@0: * Receive notification of an unparsed entity declaration. aoqi@0: * Unparsed entities are non-XML data. aoqi@0: * aoqi@0: * @param name The name of the unparsed entity. aoqi@0: * @param publicId The public identifier aoqi@0: * @param systemId The system identifier aoqi@0: * @param notationName The associated notation aoqi@0: */ aoqi@0: public void unparsedEntityDecl(String name, String publicId, aoqi@0: String systemId, String notationName) aoqi@0: throws SAXException; aoqi@0: aoqi@0: /** aoqi@0: * Receive notification of a internal general entity declaration event. aoqi@0: * aoqi@0: * @param name The internal general entity name. aoqi@0: * @param value The value of the entity, which may include unexpanded aoqi@0: * entity references. Character references will have been aoqi@0: * expanded. aoqi@0: * @throws SAXException aoqi@0: * @see #externalGeneralEntityDecl(String, String, String) aoqi@0: */ aoqi@0: public void internalGeneralEntityDecl(String name, String value) aoqi@0: throws SAXException; aoqi@0: aoqi@0: /** aoqi@0: * Receive notification of an external parsed general entity aoqi@0: * declaration event. aoqi@0: *

aoqi@0: *

If a system identifier is present, and it is a relative URL, the aoqi@0: * parser will have resolved it fully before passing it through this aoqi@0: * method to a listener.

aoqi@0: * aoqi@0: * @param name The entity name. aoqi@0: * @param publicId The entity's public identifier, or null if aoqi@0: * none was given. aoqi@0: * @param systemId The entity's system identifier. aoqi@0: * @throws SAXException aoqi@0: * @see #unparsedEntityDecl(String, String, String, String) aoqi@0: */ aoqi@0: public void externalGeneralEntityDecl(String name, String publicId, aoqi@0: String systemId) aoqi@0: throws SAXException; aoqi@0: aoqi@0: /** aoqi@0: * Receive notification of a internal parameter entity declaration aoqi@0: * event. aoqi@0: * aoqi@0: * @param name The internal parameter entity name. aoqi@0: * @param value The value of the entity, which may include unexpanded aoqi@0: * entity references. Character references will have been aoqi@0: * expanded. aoqi@0: * @throws SAXException aoqi@0: * @see #externalParameterEntityDecl(String, String, String) aoqi@0: */ aoqi@0: public void internalParameterEntityDecl(String name, String value) aoqi@0: throws SAXException; aoqi@0: aoqi@0: /** aoqi@0: * Receive notification of an external parameter entity declaration aoqi@0: * event. aoqi@0: *

aoqi@0: *

If a system identifier is present, and it is a relative URL, the aoqi@0: * parser will have resolved it fully before passing it through this aoqi@0: * method to a listener.

aoqi@0: * aoqi@0: * @param name The parameter entity name. aoqi@0: * @param publicId The entity's public identifier, or null if aoqi@0: * none was given. aoqi@0: * @param systemId The entity's system identifier. aoqi@0: * @throws SAXException aoqi@0: * @see #unparsedEntityDecl(String, String, String, String) aoqi@0: */ aoqi@0: public void externalParameterEntityDecl(String name, String publicId, aoqi@0: String systemId) aoqi@0: throws SAXException; aoqi@0: aoqi@0: /** aoqi@0: * Receive notification of the beginning of the DTD. aoqi@0: * aoqi@0: * @param in Current input entity. aoqi@0: * @see #endDTD() aoqi@0: */ aoqi@0: public void startDTD(InputEntity in) aoqi@0: throws SAXException; aoqi@0: aoqi@0: /** aoqi@0: * Receive notification of the end of a DTD. The parser will invoke aoqi@0: * this method only once. aoqi@0: * aoqi@0: * @throws SAXException aoqi@0: * @see #startDTD(InputEntity) aoqi@0: */ aoqi@0: public void endDTD() aoqi@0: throws SAXException; aoqi@0: aoqi@0: /** aoqi@0: * Receive notification that a comment has been read. aoqi@0: *

aoqi@0: *

Note that processing instructions are the mechanism designed aoqi@0: * to hold information for consumption by applications, not comments. aoqi@0: * XML systems may rely on applications being able to access information aoqi@0: * found in processing instructions; this is not true of comments, which aoqi@0: * are typically discarded. aoqi@0: * aoqi@0: * @param text the text within the comment delimiters. aoqi@0: * @throws SAXException aoqi@0: */ aoqi@0: public void comment(String text) aoqi@0: throws SAXException; aoqi@0: aoqi@0: /** aoqi@0: * Receive notification of character data. aoqi@0: *

aoqi@0: *

The Parser will call this method to report each chunk of aoqi@0: * character data. SAX parsers may return all contiguous character aoqi@0: * data in a single chunk, or they may split it into several aoqi@0: * chunks; however, all of the characters in any single event aoqi@0: * must come from the same external entity, so that the Locator aoqi@0: * provides useful information.

aoqi@0: *

aoqi@0: *

The application must not attempt to read from the array aoqi@0: * outside of the specified range.

aoqi@0: *

aoqi@0: *

Note that some parsers will report whitespace using the aoqi@0: * ignorableWhitespace() method rather than this one (validating aoqi@0: * parsers must do so).

aoqi@0: * aoqi@0: * @param ch The characters from the DTD. aoqi@0: * @param start The start position in the array. aoqi@0: * @param length The number of characters to read from the array. aoqi@0: * @throws SAXException aoqi@0: * @see #ignorableWhitespace(char[], int, int) aoqi@0: */ aoqi@0: public void characters(char ch[], int start, int length) aoqi@0: throws SAXException; aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Receive notification of ignorable whitespace in element content. aoqi@0: *

aoqi@0: *

Validating Parsers must use this method to report each chunk aoqi@0: * of ignorable whitespace (see the W3C XML 1.0 recommendation, aoqi@0: * section 2.10): non-validating parsers may also use this method aoqi@0: * if they are capable of parsing and using content models.

aoqi@0: *

aoqi@0: *

SAX parsers may return all contiguous whitespace in a single aoqi@0: * chunk, or they may split it into several chunks; however, all of aoqi@0: * the characters in any single event must come from the same aoqi@0: * external entity, so that the Locator provides useful aoqi@0: * information.

aoqi@0: *

aoqi@0: *

The application must not attempt to read from the array aoqi@0: * outside of the specified range.

aoqi@0: * aoqi@0: * @param ch The characters from the DTD. aoqi@0: * @param start The start position in the array. aoqi@0: * @param length The number of characters to read from the array. aoqi@0: * @throws SAXException aoqi@0: * @see #characters(char[], int, int) aoqi@0: */ aoqi@0: public void ignorableWhitespace(char ch[], int start, int length) aoqi@0: throws SAXException; aoqi@0: aoqi@0: /** aoqi@0: * Receive notification that a CDATA section is beginning. Data in a aoqi@0: * CDATA section is is reported through the appropriate event, either aoqi@0: * characters() or ignorableWhitespace. aoqi@0: * aoqi@0: * @throws SAXException aoqi@0: * @see #endCDATA() aoqi@0: */ aoqi@0: public void startCDATA() throws SAXException; aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Receive notification that the CDATA section finished. aoqi@0: * aoqi@0: * @throws SAXException aoqi@0: * @see #startCDATA() aoqi@0: */ aoqi@0: public void endCDATA() throws SAXException; aoqi@0: aoqi@0: aoqi@0: public void fatalError(SAXParseException e) aoqi@0: throws SAXException; aoqi@0: aoqi@0: public void error(SAXParseException e) throws SAXException; aoqi@0: aoqi@0: public void warning(SAXParseException err) throws SAXException; aoqi@0: aoqi@0: public final short CONTENT_MODEL_EMPTY = 0; aoqi@0: public final short CONTENT_MODEL_ANY = 1; aoqi@0: public final short CONTENT_MODEL_MIXED = 2; aoqi@0: public final short CONTENT_MODEL_CHILDREN = 3; aoqi@0: aoqi@0: /** aoqi@0: * receives notification that parsing of content model is beginning. aoqi@0: * aoqi@0: * @param elementName name of the element whose content model is going to be defined. aoqi@0: * @param contentModelType {@link #CONTENT_MODEL_EMPTY} aoqi@0: * this element has EMPTY content model. This notification aoqi@0: * will be immediately followed by the corresponding endContentModel. aoqi@0: * {@link #CONTENT_MODEL_ANY} aoqi@0: * this element has ANY content model. This notification aoqi@0: * will be immediately followed by the corresponding endContentModel. aoqi@0: * {@link #CONTENT_MODEL_MIXED} aoqi@0: * this element has mixed content model. #PCDATA will not be reported. aoqi@0: * each child element will be reported by mixedElement method. aoqi@0: * {@link #CONTENT_MODEL_CHILDREN} aoqi@0: * this elemen has child content model. The actual content model will aoqi@0: * be reported by childElement, startModelGroup, endModelGroup, and aoqi@0: * connector methods. Possible call sequences are: aoqi@0: *

aoqi@0: * START := MODEL_GROUP aoqi@0: * MODEL_GROUP := startModelGroup TOKEN (connector TOKEN)* endModelGroup aoqi@0: * TOKEN := childElement aoqi@0: * | MODEL_GROUP aoqi@0: */ aoqi@0: public void startContentModel(String elementName, short contentModelType) throws SAXException; aoqi@0: aoqi@0: /** aoqi@0: * receives notification that parsing of content model is finished. aoqi@0: */ aoqi@0: public void endContentModel(String elementName, short contentModelType) throws SAXException; aoqi@0: aoqi@0: public final short USE_NORMAL = 0; aoqi@0: public final short USE_IMPLIED = 1; aoqi@0: public final short USE_FIXED = 2; aoqi@0: public final short USE_REQUIRED = 3; aoqi@0: aoqi@0: /** aoqi@0: * For each entry in an ATTLIST declaration, aoqi@0: * this event will be fired. aoqi@0: *

aoqi@0: *

aoqi@0: * DTD allows the same attributes to be declared more than aoqi@0: * once, and in that case the first one wins. I think aoqi@0: * this method will be only fired for the first one, aoqi@0: * but I need to check. aoqi@0: */ aoqi@0: public void attributeDecl(String elementName, String attributeName, String attributeType, aoqi@0: String[] enumeration, short attributeUse, String defaultValue) throws SAXException; aoqi@0: aoqi@0: public void childElement(String elementName, short occurence) throws SAXException; aoqi@0: aoqi@0: /** aoqi@0: * receives notification of child element of mixed content model. aoqi@0: * this method is called for each child element. aoqi@0: * aoqi@0: * @see #startContentModel(String, short) aoqi@0: */ aoqi@0: public void mixedElement(String elementName) throws SAXException; aoqi@0: aoqi@0: public void startModelGroup() throws SAXException; aoqi@0: aoqi@0: public void endModelGroup(short occurence) throws SAXException; aoqi@0: aoqi@0: public final short CHOICE = 0; aoqi@0: public final short SEQUENCE = 1; aoqi@0: aoqi@0: /** aoqi@0: * Connectors in one model group is guaranteed to be the same. aoqi@0: *

aoqi@0: *

aoqi@0: * IOW, you'll never see an event sequence like (a|b,c) aoqi@0: * aoqi@0: * @return {@link #CHOICE} or {@link #SEQUENCE}. aoqi@0: */ aoqi@0: public void connector(short connectorType) throws SAXException; aoqi@0: aoqi@0: public final short OCCURENCE_ZERO_OR_MORE = 0; aoqi@0: public final short OCCURENCE_ONE_OR_MORE = 1; aoqi@0: public final short OCCURENCE_ZERO_OR_ONE = 2; aoqi@0: public final short OCCURENCE_ONCE = 3; aoqi@0: }