com.sun.xml.stream
Class XMLEntityReaderImpl

java.lang.Object
  extended by com.sun.xml.stream.XMLEntityReader
      extended by com.sun.xml.stream.XMLEntityReaderImpl
All Implemented Interfaces:
org.apache.xerces.xni.XMLLocator, org.apache.xerces.xni.XMLResourceIdentifier

public class XMLEntityReaderImpl
extends XMLEntityReader

Implements the entity scanner methods.

Author:
Neeraj Bajaj, Sun Microsystems, Andy Clark, IBM, Arnaud Le Hors, IBM, K.Venugopal Sun Microsystems

Field Summary
protected static java.lang.String ALLOW_JAVA_ENCODINGS
          Feature identifier: allow Java encodings.
protected static java.lang.String ERROR_REPORTER
          Property identifier: error reporter.
protected  boolean fAllowJavaEncodings
          Allow Java encoding names.
protected  Entity.ScannedEntity fCurrentEntity
           
protected  XMLEntityManager fEntityManager
           
protected  XMLErrorReporter fErrorReporter
           
protected  PropertyManager fPropertyManager
           
protected  org.apache.xerces.util.SymbolTable fSymbolTable
           
protected static java.lang.String SYMBOL_TABLE
          Property identifier: symbol table.
static boolean[] validContent
           
static boolean[] validNames
           
 
Constructor Summary
XMLEntityReaderImpl(PropertyManager propertyManager, XMLEntityManager entityManager)
          private constructor, this class can only be instantiated within this class.
XMLEntityReaderImpl(XMLEntityManager entityManager)
          private constructor, this class can only be instantiated within this class.
 
Method Summary
 boolean arrangeCapacity(int length)
           
 boolean arrangeCapacity(int length, boolean changeEntity)
           
protected  java.io.Reader createReader(java.io.InputStream inputStream, java.lang.String encoding, java.lang.Boolean isBigEndian)
          Creates a reader capable of reading the given input stream in the specified encoding.
 java.lang.String getBaseSystemId()
          Returns the base system identifier of the currently scanned entity, or null if none is available.
 int getChar(int relative)
           
 int getCharacterOffset()
           
 int getColumnNumber()
          Returns the column number.
 Entity.ScannedEntity getCurrentEntity()
           
 java.lang.String getEncoding()
           
protected  java.lang.Object[] getEncodingName(byte[] b4, int count)
          Returns the IANA encoding name that is auto-detected from the bytes specified, with the endian-ness of that encoding where appropriate.
 java.lang.String getExpandedSystemId()
          Returns the expanded system identifier.
 int getLineNumber()
          Returns the line number.
 java.lang.String getLiteralSystemId()
          Returns the literal system identifier.
 java.lang.String getPublicId()
          Returns the public identifier.
 java.lang.String getVersion()
          get the version of the entity on which reader is operating
 boolean isExternal()
          Returns true if the current entity being scanned is external.
 boolean isSpace(char ch)
           
 int peekChar()
          Returns the next character on the input.
 void registerListener(XMLBufferListener listener)
          Registers the listener object and provides callback.
 void reset(PropertyManager propertyManager)
          Resets the components.
 void reset(org.apache.xerces.xni.parser.XMLComponentManager componentManager)
          Resets the component.
 int scanChar()
          Returns the next character on the input.
 int scanContent(org.apache.xerces.xni.XMLString content)
          CHANGED: Scans a range of parsed character data, This function appends the character data to the supplied buffer.
 boolean scanData(java.lang.String delimiter, org.apache.xerces.util.XMLStringBuffer buffer)
          Scans a range of character data up to the specified delimiter, setting the fields of the XMLString structure, appropriately.
 int scanLiteral(int quote, org.apache.xerces.xni.XMLString content)
          Scans a range of attribute value data, setting the fields of the XMLString structure, appropriately.
 java.lang.String scanName()
          Returns a string matching the Name production appearing immediately on the input as a symbol, or null if no Name string is present.
 java.lang.String scanNmtoken()
          Returns a string matching the NMTOKEN production appearing immediately on the input as a symbol, or null if NMTOKEN Name string is present.
 boolean scanQName(org.apache.xerces.xni.QName qname)
          Scans a qualified name from the input, setting the fields of the QName structure appropriately.
 void setCurrentEntity(Entity.ScannedEntity scannedEntity)
          set the instance of current scanned entity.
 void setEncoding(java.lang.String encoding)
          Sets the encoding of the scanner.
 void setVersion(java.lang.String version)
          the version of the current entity being scanned
 boolean skipChar(int c)
          Skips a character appearing immediately on the input.
 boolean skipSpaces()
          Skips space characters appearing immediately on the input.
 boolean skipString(char[] s)
           
 boolean skipString(java.lang.String s)
          Skips the specified string appearing immediately on the input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fCurrentEntity

protected Entity.ScannedEntity fCurrentEntity

fEntityManager

protected XMLEntityManager fEntityManager

validContent

public static final boolean[] validContent

validNames

public static final boolean[] validNames

fSymbolTable

protected org.apache.xerces.util.SymbolTable fSymbolTable

fErrorReporter

protected XMLErrorReporter fErrorReporter

fAllowJavaEncodings

protected boolean fAllowJavaEncodings
Allow Java encoding names. This feature identifier is: http://apache.org/xml/features/allow-java-encodings


SYMBOL_TABLE

protected static final java.lang.String SYMBOL_TABLE
Property identifier: symbol table.

See Also:
Constant Field Values

ERROR_REPORTER

protected static final java.lang.String ERROR_REPORTER
Property identifier: error reporter.

See Also:
Constant Field Values

ALLOW_JAVA_ENCODINGS

protected static final java.lang.String ALLOW_JAVA_ENCODINGS
Feature identifier: allow Java encodings.

See Also:
Constant Field Values

fPropertyManager

protected PropertyManager fPropertyManager
Constructor Detail

XMLEntityReaderImpl

public XMLEntityReaderImpl(XMLEntityManager entityManager)
private constructor, this class can only be instantiated within this class. Instance of this class should be obtained using getEntityScanner() or getEntityScanner(ScannedEntity scannedEntity)

See Also:
getEntityScanner(), getEntityScanner(ScannedEntity)

XMLEntityReaderImpl

public XMLEntityReaderImpl(PropertyManager propertyManager,
                           XMLEntityManager entityManager)
private constructor, this class can only be instantiated within this class. Instance of this class should be obtained using getEntityScanner() or getEntityScanner(ScannedEntity scannedEntity)

See Also:
getEntityScanner(), getEntityScanner(ScannedEntity)
Method Detail

reset

public void reset(PropertyManager propertyManager)
Resets the components.


reset

public void reset(org.apache.xerces.xni.parser.XMLComponentManager componentManager)
           throws org.apache.xerces.xni.parser.XMLConfigurationException
Resets the component. The component can query the component manager about any features and properties that affect the operation of the component.

Parameters:
componentManager - The component manager.
Throws:
SAXException - Thrown by component on initialization error. For example, if a feature or property is required for the operation of the component, the component manager may throw a SAXNotRecognizedException or a SAXNotSupportedException.
org.apache.xerces.xni.parser.XMLConfigurationException

setCurrentEntity

public void setCurrentEntity(Entity.ScannedEntity scannedEntity)
set the instance of current scanned entity.

Parameters:
ScannedEntity -

getCurrentEntity

public Entity.ScannedEntity getCurrentEntity()

getBaseSystemId

public java.lang.String getBaseSystemId()
Returns the base system identifier of the currently scanned entity, or null if none is available.


getLineNumber

public int getLineNumber()
Description copied from interface: org.apache.xerces.xni.XMLLocator
Returns the line number.


getColumnNumber

public int getColumnNumber()
Description copied from interface: org.apache.xerces.xni.XMLLocator
Returns the column number.


getCharacterOffset

public int getCharacterOffset()
Specified by:
getCharacterOffset in interface org.apache.xerces.xni.XMLLocator
Specified by:
getCharacterOffset in class XMLEntityReader

getExpandedSystemId

public java.lang.String getExpandedSystemId()
Returns the expanded system identifier.


getLiteralSystemId

public java.lang.String getLiteralSystemId()
Returns the literal system identifier.


getPublicId

public java.lang.String getPublicId()
Returns the public identifier.


setVersion

public void setVersion(java.lang.String version)
the version of the current entity being scanned

Specified by:
setVersion in class XMLEntityReader

getVersion

public java.lang.String getVersion()
Description copied from class: XMLEntityReader
get the version of the entity on which reader is operating

Specified by:
getVersion in class XMLEntityReader

getEncoding

public java.lang.String getEncoding()
Specified by:
getEncoding in interface org.apache.xerces.xni.XMLLocator
Specified by:
getEncoding in class XMLEntityReader

setEncoding

public void setEncoding(java.lang.String encoding)
                 throws java.io.IOException
Sets the encoding of the scanner. This method is used by the scanners if the XMLDecl or TextDecl line contains an encoding pseudo-attribute.

Note: The underlying character reader on the current entity will be changed to accomodate the new encoding. However, the new encoding is ignored if the current reader was not constructed from an input stream (e.g. an external entity that is resolved directly to the appropriate java.io.Reader object).

Specified by:
setEncoding in class XMLEntityReader
Parameters:
encoding - The IANA encoding name of the new encoding.
Throws:
java.io.IOException - Thrown if the new encoding is not supported.
See Also:
EncodingMap

isExternal

public boolean isExternal()
Returns true if the current entity being scanned is external.

Specified by:
isExternal in class XMLEntityReader

getChar

public int getChar(int relative)
            throws java.io.IOException
Throws:
java.io.IOException

peekChar

public int peekChar()
             throws java.io.IOException
Returns the next character on the input.

Note: The character is not consumed.

Specified by:
peekChar in class XMLEntityReader
Throws:
java.io.IOException - Thrown if i/o error occurs.
EOFException - Thrown on end of file.

scanChar

public int scanChar()
             throws java.io.IOException
Returns the next character on the input.

Note: The character is consumed.

Specified by:
scanChar in class XMLEntityReader
Throws:
java.io.IOException - Thrown if i/o error occurs.
EOFException - Thrown on end of file.

scanNmtoken

public java.lang.String scanNmtoken()
                             throws java.io.IOException
Returns a string matching the NMTOKEN production appearing immediately on the input as a symbol, or null if NMTOKEN Name string is present.

Note: The NMTOKEN characters are consumed.

Note: The string returned must be a symbol. The SymbolTable can be used for this purpose.

Specified by:
scanNmtoken in class XMLEntityReader
Throws:
java.io.IOException - Thrown if i/o error occurs.
EOFException - Thrown on end of file.
See Also:
SymbolTable, XMLChar.isName(int)

scanName

public java.lang.String scanName()
                          throws java.io.IOException
Returns a string matching the Name production appearing immediately on the input as a symbol, or null if no Name string is present.

Note: The Name characters are consumed.

Note: The string returned must be a symbol. The SymbolTable can be used for this purpose.

Specified by:
scanName in class XMLEntityReader
Throws:
java.io.IOException - Thrown if i/o error occurs.
EOFException - Thrown on end of file.
See Also:
SymbolTable, XMLChar.isName(int), XMLChar.isNameStart(int)

scanQName

public boolean scanQName(org.apache.xerces.xni.QName qname)
                  throws java.io.IOException
Scans a qualified name from the input, setting the fields of the QName structure appropriately.

Note: The qualified name characters are consumed.

Note: The strings used to set the values of the QName structure must be symbols. The SymbolTable can be used for this purpose.

Specified by:
scanQName in class XMLEntityReader
Parameters:
qname - The qualified name structure to fill.
Returns:
Returns true if a qualified name appeared immediately on the input and was scanned, false otherwise.
Throws:
java.io.IOException - Thrown if i/o error occurs.
EOFException - Thrown on end of file.
See Also:
SymbolTable, XMLChar.isName(int), XMLChar.isNameStart(int)

scanContent

public int scanContent(org.apache.xerces.xni.XMLString content)
                throws java.io.IOException
CHANGED: Scans a range of parsed character data, This function appends the character data to the supplied buffer.

Note: The characters are consumed.

Note: This method does not guarantee to return the longest run of parsed character data. This method may return before markup due to reaching the end of the input buffer or any other reason.

Specified by:
scanContent in class XMLEntityReader
Parameters:
content - The content structure to fill.
Returns:
Returns the next character on the input, if known. This value may be -1 but this does note designate end of file.
Throws:
java.io.IOException - Thrown if i/o error occurs.
EOFException - Thrown on end of file.

scanLiteral

public int scanLiteral(int quote,
                       org.apache.xerces.xni.XMLString content)
                throws java.io.IOException
Scans a range of attribute value data, setting the fields of the XMLString structure, appropriately.

Note: The characters are consumed.

Note: This method does not guarantee to return the longest run of attribute value data. This method may return before the quote character due to reaching the end of the input buffer or any other reason.

Note: The fields contained in the XMLString structure are not guaranteed to remain valid upon subsequent calls to the entity scanner. Therefore, the caller is responsible for immediately using the returned character data or making a copy of the character data.

Specified by:
scanLiteral in class XMLEntityReader
Parameters:
quote - The quote character that signifies the end of the attribute value data.
content - The content structure to fill.
Returns:
Returns the next character on the input, if known. This value may be -1 but this does note designate end of file.
Throws:
java.io.IOException - Thrown if i/o error occurs.
EOFException - Thrown on end of file.

scanData

public boolean scanData(java.lang.String delimiter,
                        org.apache.xerces.util.XMLStringBuffer buffer)
                 throws java.io.IOException
Scans a range of character data up to the specified delimiter, setting the fields of the XMLString structure, appropriately.

Note: The characters are consumed.

Note: This assumes that the length of the delimiter and that the delimiter contains at least one character.

Note: This method does not guarantee to return the longest run of character data. This method may return before the delimiter due to reaching the end of the input buffer or any other reason.

Specified by:
scanData in class XMLEntityReader
Parameters:
delimiter - The string that signifies the end of the character data to be scanned.
data - The data structure to fill. Data will be appendd to the current buffer.
Returns:
Returns true if there is more data to scan, false otherwise.
Throws:
java.io.IOException - Thrown if i/o error occurs.
EOFException - Thrown on end of file.

skipChar

public boolean skipChar(int c)
                 throws java.io.IOException
Skips a character appearing immediately on the input.

Note: The character is consumed only if it matches the specified character.

Specified by:
skipChar in class XMLEntityReader
Parameters:
c - The character to skip.
Returns:
Returns true if the character was skipped.
Throws:
java.io.IOException - Thrown if i/o error occurs.
EOFException - Thrown on end of file.

isSpace

public boolean isSpace(char ch)

skipSpaces

public boolean skipSpaces()
                   throws java.io.IOException
Skips space characters appearing immediately on the input.

Note: The characters are consumed only if they are space characters.

Specified by:
skipSpaces in class XMLEntityReader
Returns:
Returns true if at least one space character was skipped.
Throws:
java.io.IOException - Thrown if i/o error occurs.
EOFException - Thrown on end of file.
See Also:
XMLChar.isSpace(int)

arrangeCapacity

public boolean arrangeCapacity(int length)
                        throws java.io.IOException
Parameters:
legnth - This function checks that following number of characters are available. to the underlying buffer.
Returns:
This function returns true if capacity asked is available.
Throws:
java.io.IOException

arrangeCapacity

public boolean arrangeCapacity(int length,
                               boolean changeEntity)
                        throws java.io.IOException
Parameters:
legnth - This function checks that following number of characters are available. to the underlying buffer.
if - the underlying function should change the entity
Returns:
This function returns true if capacity asked is available.
Throws:
java.io.IOException

skipString

public boolean skipString(java.lang.String s)
                   throws java.io.IOException
Skips the specified string appearing immediately on the input.

Note: The characters are consumed only if all the characters are skipped.

Specified by:
skipString in class XMLEntityReader
Parameters:
s - The string to skip.
Returns:
Returns true if the string was skipped.
Throws:
java.io.IOException - Thrown if i/o error occurs.
EOFException - Thrown on end of file.

skipString

public boolean skipString(char[] s)
                   throws java.io.IOException
Throws:
java.io.IOException

createReader

protected java.io.Reader createReader(java.io.InputStream inputStream,
                                      java.lang.String encoding,
                                      java.lang.Boolean isBigEndian)
                               throws java.io.IOException
Creates a reader capable of reading the given input stream in the specified encoding.

Parameters:
inputStream - The input stream.
encoding - The encoding name that the input stream is encoded using. If the user has specified that Java encoding names are allowed, then the encoding name may be a Java encoding name; otherwise, it is an ianaEncoding name.
isBigEndian - For encodings (like uCS-4), whose names cannot specify a byte order, this tells whether the order is bigEndian. null menas unknown or not relevant.
Returns:
Returns a reader.
Throws:
java.io.IOException

getEncodingName

protected java.lang.Object[] getEncodingName(byte[] b4,
                                             int count)
Returns the IANA encoding name that is auto-detected from the bytes specified, with the endian-ness of that encoding where appropriate.

Parameters:
b4 - The first four bytes of the input.
count - The number of bytes actually read.
Returns:
a 2-element array: the first element, an IANA-encoding string, the second element a Boolean which is true iff the document is big endian, false if it's little-endian, and null if the distinction isn't relevant.

registerListener

public void registerListener(XMLBufferListener listener)
Registers the listener object and provides callback.

Specified by:
registerListener in class XMLEntityReader
Parameters:
listener - listener to which call back should be provided when scanner buffer is being changed.


Copyright ? 2002-2003 Apache XML Project. All Rights Reserved.