Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/xml/sax/ContentHandler.java
48534 views
/*1* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425// ContentHandler.java - handle main document content.26// http://www.saxproject.org27// Written by David Megginson28// NO WARRANTY! This class is in the public domain.29// $Id: ContentHandler.java,v 1.2 2004/11/03 22:44:51 jsuttor Exp $3031package org.xml.sax;323334/**35* Receive notification of the logical content of a document.36*37* <blockquote>38* <em>This module, both source code and documentation, is in the39* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>40* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>41* for further information.42* </blockquote>43*44* <p>This is the main interface that most SAX applications45* implement: if the application needs to be informed of basic parsing46* events, it implements this interface and registers an instance with47* the SAX parser using the {@link org.xml.sax.XMLReader#setContentHandler48* setContentHandler} method. The parser uses the instance to report49* basic document-related events like the start and end of elements50* and character data.</p>51*52* <p>The order of events in this interface is very important, and53* mirrors the order of information in the document itself. For54* example, all of an element's content (character data, processing55* instructions, and/or subelements) will appear, in order, between56* the startElement event and the corresponding endElement event.</p>57*58* <p>This interface is similar to the now-deprecated SAX 1.059* DocumentHandler interface, but it adds support for Namespaces60* and for reporting skipped entities (in non-validating XML61* processors).</p>62*63* <p>Implementors should note that there is also a64* <code>ContentHandler</code> class in the <code>java.net</code>65* package; that means that it's probably a bad idea to do</p>66*67* <pre>import java.net.*;68* import org.xml.sax.*;69* </pre>70*71* <p>In fact, "import ...*" is usually a sign of sloppy programming72* anyway, so the user should consider this a feature rather than a73* bug.</p>74*75* @since SAX 2.076* @author David Megginson77* @see org.xml.sax.XMLReader78* @see org.xml.sax.DTDHandler79* @see org.xml.sax.ErrorHandler80*/81public interface ContentHandler82{8384/**85* Receive an object for locating the origin of SAX document events.86*87* <p>SAX parsers are strongly encouraged (though not absolutely88* required) to supply a locator: if it does so, it must supply89* the locator to the application by invoking this method before90* invoking any of the other methods in the ContentHandler91* interface.</p>92*93* <p>The locator allows the application to determine the end94* position of any document-related event, even if the parser is95* not reporting an error. Typically, the application will96* use this information for reporting its own errors (such as97* character content that does not match an application's98* business rules). The information returned by the locator99* is probably not sufficient for use with a search engine.</p>100*101* <p>Note that the locator will return correct information only102* during the invocation SAX event callbacks after103* {@link #startDocument startDocument} returns and before104* {@link #endDocument endDocument} is called. The105* application should not attempt to use it at any other time.</p>106*107* @param locator an object that can return the location of108* any SAX document event109* @see org.xml.sax.Locator110*/111public void setDocumentLocator (Locator locator);112113114/**115* Receive notification of the beginning of a document.116*117* <p>The SAX parser will invoke this method only once, before any118* other event callbacks (except for {@link #setDocumentLocator119* setDocumentLocator}).</p>120*121* @throws org.xml.sax.SAXException any SAX exception, possibly122* wrapping another exception123* @see #endDocument124*/125public void startDocument ()126throws SAXException;127128129/**130* Receive notification of the end of a document.131*132* <p><strong>There is an apparent contradiction between the133* documentation for this method and the documentation for {@link134* org.xml.sax.ErrorHandler#fatalError}. Until this ambiguity is135* resolved in a future major release, clients should make no136* assumptions about whether endDocument() will or will not be137* invoked when the parser has reported a fatalError() or thrown138* an exception.</strong></p>139*140* <p>The SAX parser will invoke this method only once, and it will141* be the last method invoked during the parse. The parser shall142* not invoke this method until it has either abandoned parsing143* (because of an unrecoverable error) or reached the end of144* input.</p>145*146* @throws org.xml.sax.SAXException any SAX exception, possibly147* wrapping another exception148* @see #startDocument149*/150public void endDocument()151throws SAXException;152153154/**155* Begin the scope of a prefix-URI Namespace mapping.156*157* <p>The information from this event is not necessary for158* normal Namespace processing: the SAX XML reader will159* automatically replace prefixes for element and attribute160* names when the <code>http://xml.org/sax/features/namespaces</code>161* feature is <var>true</var> (the default).</p>162*163* <p>There are cases, however, when applications need to164* use prefixes in character data or in attribute values,165* where they cannot safely be expanded automatically; the166* start/endPrefixMapping event supplies the information167* to the application to expand prefixes in those contexts168* itself, if necessary.</p>169*170* <p>Note that start/endPrefixMapping events are not171* guaranteed to be properly nested relative to each other:172* all startPrefixMapping events will occur immediately before the173* corresponding {@link #startElement startElement} event,174* and all {@link #endPrefixMapping endPrefixMapping}175* events will occur immediately after the corresponding176* {@link #endElement endElement} event,177* but their order is not otherwise178* guaranteed.</p>179*180* <p>There should never be start/endPrefixMapping events for the181* "xml" prefix, since it is predeclared and immutable.</p>182*183* @param prefix the Namespace prefix being declared.184* An empty string is used for the default element namespace,185* which has no prefix.186* @param uri the Namespace URI the prefix is mapped to187* @throws org.xml.sax.SAXException the client may throw188* an exception during processing189* @see #endPrefixMapping190* @see #startElement191*/192public void startPrefixMapping (String prefix, String uri)193throws SAXException;194195196/**197* End the scope of a prefix-URI mapping.198*199* <p>See {@link #startPrefixMapping startPrefixMapping} for200* details. These events will always occur immediately after the201* corresponding {@link #endElement endElement} event, but the order of202* {@link #endPrefixMapping endPrefixMapping} events is not otherwise203* guaranteed.</p>204*205* @param prefix the prefix that was being mapped.206* This is the empty string when a default mapping scope ends.207* @throws org.xml.sax.SAXException the client may throw208* an exception during processing209* @see #startPrefixMapping210* @see #endElement211*/212public void endPrefixMapping (String prefix)213throws SAXException;214215216/**217* Receive notification of the beginning of an element.218*219* <p>The Parser will invoke this method at the beginning of every220* element in the XML document; there will be a corresponding221* {@link #endElement endElement} event for every startElement event222* (even when the element is empty). All of the element's content will be223* reported, in order, before the corresponding endElement224* event.</p>225*226* <p>This event allows up to three name components for each227* element:</p>228*229* <ol>230* <li>the Namespace URI;</li>231* <li>the local name; and</li>232* <li>the qualified (prefixed) name.</li>233* </ol>234*235* <p>Any or all of these may be provided, depending on the236* values of the <var>http://xml.org/sax/features/namespaces</var>237* and the <var>http://xml.org/sax/features/namespace-prefixes</var>238* properties:</p>239*240* <ul>241* <li>the Namespace URI and local name are required when242* the namespaces property is <var>true</var> (the default), and are243* optional when the namespaces property is <var>false</var> (if one is244* specified, both must be);</li>245* <li>the qualified name is required when the namespace-prefixes property246* is <var>true</var>, and is optional when the namespace-prefixes property247* is <var>false</var> (the default).</li>248* </ul>249*250* <p>Note that the attribute list provided will contain only251* attributes with explicit values (specified or defaulted):252* #IMPLIED attributes will be omitted. The attribute list253* will contain attributes used for Namespace declarations254* (xmlns* attributes) only if the255* <code>http://xml.org/sax/features/namespace-prefixes</code>256* property is true (it is false by default, and support for a257* true value is optional).</p>258*259* <p>Like {@link #characters characters()}, attribute values may have260* characters that need more than one <code>char</code> value. </p>261*262* @param uri the Namespace URI, or the empty string if the263* element has no Namespace URI or if Namespace264* processing is not being performed265* @param localName the local name (without prefix), or the266* empty string if Namespace processing is not being267* performed268* @param qName the qualified name (with prefix), or the269* empty string if qualified names are not available270* @param atts the attributes attached to the element. If271* there are no attributes, it shall be an empty272* Attributes object. The value of this object after273* startElement returns is undefined274* @throws org.xml.sax.SAXException any SAX exception, possibly275* wrapping another exception276* @see #endElement277* @see org.xml.sax.Attributes278* @see org.xml.sax.helpers.AttributesImpl279*/280public void startElement (String uri, String localName,281String qName, Attributes atts)282throws SAXException;283284285/**286* Receive notification of the end of an element.287*288* <p>The SAX parser will invoke this method at the end of every289* element in the XML document; there will be a corresponding290* {@link #startElement startElement} event for every endElement291* event (even when the element is empty).</p>292*293* <p>For information on the names, see startElement.</p>294*295* @param uri the Namespace URI, or the empty string if the296* element has no Namespace URI or if Namespace297* processing is not being performed298* @param localName the local name (without prefix), or the299* empty string if Namespace processing is not being300* performed301* @param qName the qualified XML name (with prefix), or the302* empty string if qualified names are not available303* @throws org.xml.sax.SAXException any SAX exception, possibly304* wrapping another exception305*/306public void endElement (String uri, String localName,307String qName)308throws SAXException;309310311/**312* Receive notification of character data.313*314* <p>The Parser will call this method to report each chunk of315* character data. SAX parsers may return all contiguous character316* data in a single chunk, or they may split it into several317* chunks; however, all of the characters in any single event318* must come from the same external entity so that the Locator319* provides useful information.</p>320*321* <p>The application must not attempt to read from the array322* outside of the specified range.</p>323*324* <p>Individual characters may consist of more than one Java325* <code>char</code> value. There are two important cases where this326* happens, because characters can't be represented in just sixteen bits.327* In one case, characters are represented in a <em>Surrogate Pair</em>,328* using two special Unicode values. Such characters are in the so-called329* "Astral Planes", with a code point above U+FFFF. A second case involves330* composite characters, such as a base character combining with one or331* more accent characters. </p>332*333* <p> Your code should not assume that algorithms using334* <code>char</code>-at-a-time idioms will be working in character335* units; in some cases they will split characters. This is relevant336* wherever XML permits arbitrary characters, such as attribute values,337* processing instruction data, and comments as well as in data reported338* from this method. It's also generally relevant whenever Java code339* manipulates internationalized text; the issue isn't unique to XML.</p>340*341* <p>Note that some parsers will report whitespace in element342* content using the {@link #ignorableWhitespace ignorableWhitespace}343* method rather than this one (validating parsers <em>must</em>344* do so).</p>345*346* @param ch the characters from the XML document347* @param start the start position in the array348* @param length the number of characters to read from the array349* @throws org.xml.sax.SAXException any SAX exception, possibly350* wrapping another exception351* @see #ignorableWhitespace352* @see org.xml.sax.Locator353*/354public void characters (char ch[], int start, int length)355throws SAXException;356357358/**359* Receive notification of ignorable whitespace in element content.360*361* <p>Validating Parsers must use this method to report each chunk362* of whitespace in element content (see the W3C XML 1.0363* recommendation, section 2.10): non-validating parsers may also364* use this method if they are capable of parsing and using365* content models.</p>366*367* <p>SAX parsers may return all contiguous whitespace in a single368* chunk, or they may split it into several chunks; however, all of369* the characters in any single event must come from the same370* external entity, so that the Locator provides useful371* information.</p>372*373* <p>The application must not attempt to read from the array374* outside of the specified range.</p>375*376* @param ch the characters from the XML document377* @param start the start position in the array378* @param length the number of characters to read from the array379* @throws org.xml.sax.SAXException any SAX exception, possibly380* wrapping another exception381* @see #characters382*/383public void ignorableWhitespace (char ch[], int start, int length)384throws SAXException;385386387/**388* Receive notification of a processing instruction.389*390* <p>The Parser will invoke this method once for each processing391* instruction found: note that processing instructions may occur392* before or after the main document element.</p>393*394* <p>A SAX parser must never report an XML declaration (XML 1.0,395* section 2.8) or a text declaration (XML 1.0, section 4.3.1)396* using this method.</p>397*398* <p>Like {@link #characters characters()}, processing instruction399* data may have characters that need more than one <code>char</code>400* value. </p>401*402* @param target the processing instruction target403* @param data the processing instruction data, or null if404* none was supplied. The data does not include any405* whitespace separating it from the target406* @throws org.xml.sax.SAXException any SAX exception, possibly407* wrapping another exception408*/409public void processingInstruction (String target, String data)410throws SAXException;411412413/**414* Receive notification of a skipped entity.415* This is not called for entity references within markup constructs416* such as element start tags or markup declarations. (The XML417* recommendation requires reporting skipped external entities.418* SAX also reports internal entity expansion/non-expansion, except419* within markup constructs.)420*421* <p>The Parser will invoke this method each time the entity is422* skipped. Non-validating processors may skip entities if they423* have not seen the declarations (because, for example, the424* entity was declared in an external DTD subset). All processors425* may skip external entities, depending on the values of the426* <code>http://xml.org/sax/features/external-general-entities</code>427* and the428* <code>http://xml.org/sax/features/external-parameter-entities</code>429* properties.</p>430*431* @param name the name of the skipped entity. If it is a432* parameter entity, the name will begin with '%', and if433* it is the external DTD subset, it will be the string434* "[dtd]"435* @throws org.xml.sax.SAXException any SAX exception, possibly436* wrapping another exception437*/438public void skippedEntity (String name)439throws SAXException;440}441442// end of ContentHandler.java443444445