Path: blob/jdk8u272-b10-aarch32-20201026/jaxp/src/com/sun/xml/internal/stream/XMLEntityReader.java
83408 views
/*1* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.2*/34/*5* Copyright 2005 The Apache Software Foundation.6*7* Licensed under the Apache License, Version 2.0 (the "License");8* you may not use this file except in compliance with the License.9* You may obtain a copy of the License at10*11* http://www.apache.org/licenses/LICENSE-2.012*13* Unless required by applicable law or agreed to in writing, software14* distributed under the License is distributed on an "AS IS" BASIS,15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16* See the License for the specific language governing permissions and17* limitations under the License.18*/1920package com.sun.xml.internal.stream;2122import java.io.IOException;2324import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;25import com.sun.org.apache.xerces.internal.xni.*;2627/**28* This class allows various parser scanners to scan basic XML constructs29* from entities. This class works directly with the entity manager to30* provide this functionality.31* <p>32* There is only one entity scanner and entity manager per parser. The33* entity manager <em>could</em> implement the methods to perform entity34* scanning, but the entity scanner class allows a cleaner separation35* between entity management API and entity scanning.36*37* @author Andy Clark, IBM38* @author Neeraj Bajaj Sun Microsystems39* @author K.Venugopal Sun Microsystems40*41* @see XMLEntityHandler42* @see XMLEntityManager43*/44public abstract class XMLEntityReader implements XMLLocator {4546//47// Public methods48//495051/**52* Sets the encoding of the scanner. This method is used by the53* scanners if the XMLDecl or TextDecl line contains an encoding54* pseudo-attribute.55* <p>56* <strong>Note:</strong> The underlying character reader on the57* current entity will be changed to accomodate the new encoding.58* However, the new encoding is ignored if the current reader was59* not constructed from an input stream (e.g. an external entity60* that is resolved directly to the appropriate java.io.Reader61* object).62*63* @param encoding The IANA encoding name of the new encoding.64*65* @throws IOException Thrown if the new encoding is not supported.66*67* @see com.sun.org.apache.xerces.internal.util.EncodingMap68* @see com.sun.org.apache.xerces.internal.util.XMLChar#isValidIANAEncoding69* @see com.sun.org.apache.xerces.internal.util.XMLChar#isValidJavaEncoding70*/71public abstract void setEncoding(String encoding)72throws IOException;7374public abstract String getEncoding() ;7576public abstract int getCharacterOffset() ;7778/** the version of the current entity being scanned or the version of the entity on which reader is operating */79public abstract void setVersion(String version) ;8081/** get the version of the entity on which reader is operating */82public abstract String getVersion() ;8384/** Returns true if the current entity being scanned is external. */85public abstract boolean isExternal();8687/**88* Returns the next character on the input.89* <p>90* <strong>Note:</strong> The character is <em>not</em> consumed.91*92* @throws IOException Thrown if i/o error occurs.93* @throws EOFException Thrown on end of file.94*/95public abstract int peekChar() throws IOException;9697/**98* Returns the next character on the input.99* <p>100* <strong>Note:</strong> The character is consumed.101*102* @throws IOException Thrown if i/o error occurs.103* @throws EOFException Thrown on end of file.104*/105public abstract int scanChar() throws IOException;106107/**108* Returns a string matching the NMTOKEN production appearing immediately109* on the input as a symbol, or null if NMTOKEN Name string is present.110* <p>111* <strong>Note:</strong> The NMTOKEN characters are consumed.112* <p>113* <strong>Note:</strong> The string returned must be a symbol. The114* SymbolTable can be used for this purpose.115*116* @throws IOException Thrown if i/o error occurs.117* @throws EOFException Thrown on end of file.118*119* @see com.sun.org.apache.xerces.internal.util.SymbolTable120* @see com.sun.org.apache.xerces.internal.util.XMLChar#isName121*/122public abstract String scanNmtoken() throws IOException;123124/**125* Returns a string matching the Name production appearing immediately126* on the input as a symbol, or null if no Name string is present.127* <p>128* <strong>Note:</strong> The Name characters are consumed.129* <p>130* <strong>Note:</strong> The string returned must be a symbol. The131* SymbolTable can be used for this purpose.132*133* @throws IOException Thrown if i/o error occurs.134* @throws EOFException Thrown on end of file.135*136* @see com.sun.org.apache.xerces.internal.util.SymbolTable137* @see com.sun.org.apache.xerces.internal.util.XMLChar#isName138* @see com.sun.org.apache.xerces.internal.util.XMLChar#isNameStart139*/140public abstract String scanName() throws IOException;141142/**143* Scans a qualified name from the input, setting the fields of the144* QName structure appropriately.145* <p>146* <strong>Note:</strong> The qualified name characters are consumed.147* <p>148* <strong>Note:</strong> The strings used to set the values of the149* QName structure must be symbols. The SymbolTable can be used for150* this purpose.151*152* @param qname The qualified name structure to fill.153*154* @return Returns true if a qualified name appeared immediately on155* the input and was scanned, false otherwise.156*157* @throws IOException Thrown if i/o error occurs.158* @throws EOFException Thrown on end of file.159*160* @see com.sun.org.apache.xerces.internal.util.SymbolTable161* @see com.sun.org.apache.xerces.internal.util.XMLChar#isName162* @see com.sun.org.apache.xerces.internal.util.XMLChar#isNameStart163*/164public abstract boolean scanQName(QName qname) throws IOException;165166/**167* CHANGED:168* Scans a range of parsed character data, This function appends the character data to169* the supplied buffer.170* <p>171* <strong>Note:</strong> The characters are consumed.172* <p>173* <strong>Note:</strong> This method does not guarantee to return174* the longest run of parsed character data. This method may return175* before markup due to reaching the end of the input buffer or any176* other reason.177* <p>178*179* @param content The content structure to fill.180*181* @return Returns the next character on the input, if known. This182* value may be -1 but this does <em>note</em> designate183* end of file.184*185* @throws IOException Thrown if i/o error occurs.186* @throws EOFException Thrown on end of file.187*/188public abstract int scanContent(XMLString content) throws IOException;189190/**191* Scans a range of attribute value data, setting the fields of the192* XMLString structure, appropriately.193* <p>194* <strong>Note:</strong> The characters are consumed.195* <p>196* <strong>Note:</strong> This method does not guarantee to return197* the longest run of attribute value data. This method may return198* before the quote character due to reaching the end of the input199* buffer or any other reason.200* <p>201* <strong>Note:</strong> The fields contained in the XMLString202* structure are not guaranteed to remain valid upon subsequent calls203* to the entity scanner. Therefore, the caller is responsible for204* immediately using the returned character data or making a copy of205* the character data.206*207* @param quote The quote character that signifies the end of the208* attribute value data.209* @param content The content structure to fill.210*211* @return Returns the next character on the input, if known. This212* value may be -1 but this does <em>note</em> designate213* end of file.214*215* @throws IOException Thrown if i/o error occurs.216* @throws EOFException Thrown on end of file.217*/218public abstract int scanLiteral(int quote, XMLString content)219throws IOException;220221/**222* Scans a range of character data up to the specicied delimiter,223* setting the fields of the XMLString structure, appropriately.224* <p>225* <strong>Note:</strong> The characters are consumed.226* <p>227* <strong>Note:</strong> This assumes that the internal buffer is228* at least the same size, or bigger, than the length of the delimiter229* and that the delimiter contains at least one character.230* <p>231* <strong>Note:</strong> This method does not guarantee to return232* the longest run of character data. This method may return before233* the delimiter due to reaching the end of the input buffer or any234* other reason.235* <p>236* <strong>Note:</strong> The fields contained in the XMLString237* structure are not guaranteed to remain valid upon subsequent calls238* to the entity scanner. Therefore, the caller is responsible for239* immediately using the returned character data or making a copy of240* the character data.241*242* @param delimiter The string that signifies the end of the character243* data to be scanned.244* @param data The data structure to fill.245*246* @return Returns true if there is more data to scan, false otherwise.247*248* @throws IOException Thrown if i/o error occurs.249* @throws EOFException Thrown on end of file.250*/251public abstract boolean scanData(String delimiter, XMLStringBuffer data)252throws IOException;253254/**255* Skips a character appearing immediately on the input.256* <p>257* <strong>Note:</strong> The character is consumed only if it matches258* the specified character.259*260* @param c The character to skip.261*262* @return Returns true if the character was skipped.263*264* @throws IOException Thrown if i/o error occurs.265* @throws EOFException Thrown on end of file.266*/267public abstract boolean skipChar(int c) throws IOException;268269/**270* Skips space characters appearing immediately on the input.271* <p>272* <strong>Note:</strong> The characters are consumed only if they are273* space characters.274*275* @return Returns true if at least one space character was skipped.276*277* @throws IOException Thrown if i/o error occurs.278* @throws EOFException Thrown on end of file.279*280* @see com.sun.org.apache.xerces.internal.util.XMLChar#isSpace281*/282public abstract boolean skipSpaces() throws IOException;283284/**285* Skips the specified string appearing immediately on the input.286* <p>287* <strong>Note:</strong> The characters are consumed only if they are288* space characters.289*290* @param s The string to skip.291*292* @return Returns true if the string was skipped.293*294* @throws IOException Thrown if i/o error occurs.295* @throws EOFException Thrown on end of file.296*/297public abstract boolean skipString(String s) throws IOException;298299public abstract void registerListener(XMLBufferListener listener);300301} // class XMLEntityScanner302303304