org.enhydra.apache.xerces.readers
Class UCSReader

java.lang.Object
  |
  +--org.enhydra.apache.xerces.readers.XMLEntityReader
        |
        +--org.enhydra.apache.xerces.readers.UCSReader
All Implemented Interfaces:
StringPool.StringProducer, XMLEntityHandler.EntityReader

final class UCSReader
extends XMLEntityReader
implements StringPool.StringProducer

Reader for UCS-2 and UCS-4 encodings.

This reader is created by the UCSRecognizer class when it decides that the byte stream is encoded in a format supported by this class. This class was intended to be another example of an encoding sensitive reader that could take advantage of the system design to improve performance and reduce resource consumption, but the actual performance tuning remains to be done.

Version:
$Id: UCSReader.java,v 1.1.1.1 2003/03/10 16:34:37 taweili Exp $

Field Summary
(package private) static int E_UCS2B
           
(package private) static int E_UCS2B_NOBOM
           
(package private) static int E_UCS2L
           
(package private) static int E_UCS2L_NOBOM
           
(package private) static int E_UCS4B
           
(package private) static int E_UCS4L
           
protected  int fCarriageReturnCounter
           
protected  int fCharacterCounter
           
protected  XMLEntityHandler.CharDataHandler fCharDataHandler
           
protected  int fCurrentOffset
           
protected  XMLEntityHandler fEntityHandler
           
protected  XMLErrorReporter fErrorReporter
           
protected  boolean fInCDSect
           
protected  int fLinefeedCounter
           
protected  boolean fSendCharDataAsCharArray
           
 
Constructor Summary
(package private) UCSReader(XMLEntityHandler entityHandler, XMLErrorReporter errorReporter, boolean sendCharDataAsCharArray, ChunkyByteArray data, int encoding, StringPool stringPool)
           
 
Method Summary
 int addString(int offset, int length)
          Add a string to the StringPool from the characters scanned using this reader as described by offset and length.
 int addSymbol(int offset, int length)
          Add a symbol to the StringPool from the characters scanned using this reader as described by offset and length.
 void append(XMLEntityHandler.CharBuffer charBuffer, int offset, int length)
          Append the characters processed by this reader associated with offset and length to the CharBuffer.
 void callCharDataHandler(int offset, int length, boolean isWhitespace)
           
protected  XMLEntityHandler.EntityReader changeReaders()
          This method is called by the reader subclasses at the end of input.
 int currentOffset()
          Return the current offset within this reader.
 boolean equalsString(int offset, int length, char[] strChars, int strOffset, int strLength)
           
 int getColumnNumber()
          Return the column number of the current position within the document that we are processing.
 boolean getInCDSect()
          This method is provided for scanner implementations.
 int getLineNumber()
          Return the line number of the current position within the document that we are processing.
protected  void init(XMLEntityHandler entityHandler, XMLErrorReporter errorReporter, boolean sendCharDataAsCharArray, int lineNumber, int columnNumber)
           
 boolean lookingAtChar(char ch, boolean skipPastChar)
          Test that the current character is a ch character.
 boolean lookingAtSpace(boolean skipPastChar)
          Test that the current character is a whitespace character.
 boolean lookingAtValidChar(boolean skipPastChar)
          Test that the current character is valid.
 void releaseString(int offset, int length)
           
 int scanAttValue(char qchar, boolean asSymbol)
          Scan an attribute value.
 int scanCharRef(boolean hex)
          Scan a character reference.
 int scanContent(QName element)
          Skip through the input while we are looking at character data.
 int scanEntityValue(int qchar, boolean createString)
          Scan an entity value.
 boolean scanExpectedName(char fastcheck, StringPool.CharArrayRange expectedName)
          Scan the name that is expected at the current position in the document.
 int scanInvalidChar()
          Scan an invalid character.
 int scanName(char fastcheck)
          Add a sequence of characters that match the XML definition of a Name to the StringPool.
 void scanQName(char fastcheck, QName qname)
          Add a sequence of characters that match the XML Namespaces definition of a QName to the StringPool.
 int scanStringLiteral()
          Scan a string literal.
 void setInCDSect(boolean inCDSect)
          This method is provided for scanner implementations.
 void skipPastName(char fastcheck)
          Skip past a sequence of characters that match the XML definition of a Name.
 void skipPastNmtoken(char fastcheck)
          Skip past a sequence of characters that match the XML definition of an Nmtoken.
 void skipPastSpaces()
          Skip past whitespace characters starting at the current position.
 boolean skippedString(char[] s)
          Skip past a sequence of characters that matches the specified character array.
 void skipToChar(char chr)
          Advance through the input data up to the next ch character.
 String toString(int offset, int length)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

E_UCS4B

static final int E_UCS4B
See Also:
Constant Field Values

E_UCS4L

static final int E_UCS4L
See Also:
Constant Field Values

E_UCS2B

static final int E_UCS2B
See Also:
Constant Field Values

E_UCS2L

static final int E_UCS2L
See Also:
Constant Field Values

E_UCS2B_NOBOM

static final int E_UCS2B_NOBOM
See Also:
Constant Field Values

E_UCS2L_NOBOM

static final int E_UCS2L_NOBOM
See Also:
Constant Field Values

fEntityHandler

protected XMLEntityHandler fEntityHandler

fErrorReporter

protected XMLErrorReporter fErrorReporter

fSendCharDataAsCharArray

protected boolean fSendCharDataAsCharArray

fCharDataHandler

protected XMLEntityHandler.CharDataHandler fCharDataHandler

fInCDSect

protected boolean fInCDSect

fCarriageReturnCounter

protected int fCarriageReturnCounter

fLinefeedCounter

protected int fLinefeedCounter

fCharacterCounter

protected int fCharacterCounter

fCurrentOffset

protected int fCurrentOffset
Constructor Detail

UCSReader

UCSReader(XMLEntityHandler entityHandler,
          XMLErrorReporter errorReporter,
          boolean sendCharDataAsCharArray,
          ChunkyByteArray data,
          int encoding,
          StringPool stringPool)
    throws Exception
Method Detail

addString

public int addString(int offset,
                     int length)
Description copied from interface: XMLEntityHandler.EntityReader
Add a string to the StringPool from the characters scanned using this reader as described by offset and length.

Specified by:
addString in interface XMLEntityHandler.EntityReader
Parameters:
offset - The offset within this reader where the characters start.
length - The length within this reader where the characters end.
Returns:
The StringPool handle for the string.

addSymbol

public int addSymbol(int offset,
                     int length)
Description copied from interface: XMLEntityHandler.EntityReader
Add a symbol to the StringPool from the characters scanned using this reader as described by offset and length.

Specified by:
addSymbol in interface XMLEntityHandler.EntityReader
Parameters:
offset - The offset within this reader where the characters start.
length - The length within this reader where the characters end.
Returns:
The StringPool handle for the symbol.

append

public void append(XMLEntityHandler.CharBuffer charBuffer,
                   int offset,
                   int length)
Description copied from interface: XMLEntityHandler.EntityReader
Append the characters processed by this reader associated with offset and length to the CharBuffer.

Specified by:
append in interface XMLEntityHandler.EntityReader
Parameters:
charBuffer - The CharBuffer to append the characters to.
offset - The offset within this reader where the copy should start.
length - The length within this reader where the copy should stop.

releaseString

public void releaseString(int offset,
                          int length)
Specified by:
releaseString in interface StringPool.StringProducer

toString

public String toString(int offset,
                       int length)
Specified by:
toString in interface StringPool.StringProducer

equalsString

public boolean equalsString(int offset,
                            int length,
                            char[] strChars,
                            int strOffset,
                            int strLength)
Specified by:
equalsString in interface StringPool.StringProducer

callCharDataHandler

public void callCharDataHandler(int offset,
                                int length,
                                boolean isWhitespace)
                         throws Exception
Exception

lookingAtChar

public boolean lookingAtChar(char ch,
                             boolean skipPastChar)
                      throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Test that the current character is a ch character.

Specified by:
lookingAtChar in interface XMLEntityHandler.EntityReader
Parameters:
ch - The character to match against.
skipPastChar - If true, we advance past the matched character.
Returns:
true if the current character is a ch character; false otherwise.
Throws:
Exception

lookingAtValidChar

public boolean lookingAtValidChar(boolean skipPastChar)
                           throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Test that the current character is valid.

Specified by:
lookingAtValidChar in interface XMLEntityHandler.EntityReader
Parameters:
skipPastChar - If true, we advance past the valid character.
Returns:
true if the current character is valid; false otherwise.
Throws:
Exception

lookingAtSpace

public boolean lookingAtSpace(boolean skipPastChar)
                       throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Test that the current character is a whitespace character.

Specified by:
lookingAtSpace in interface XMLEntityHandler.EntityReader
Parameters:
skipPastChar - If true, we advance past the whitespace character.
Returns:
true if the current character is whitespace; false otherwise.
Throws:
Exception

skipToChar

public void skipToChar(char chr)
                throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Advance through the input data up to the next ch character.

Specified by:
skipToChar in interface XMLEntityHandler.EntityReader
Parameters:
chr - The character to search for.
Throws:
Exception

skipPastSpaces

public void skipPastSpaces()
                    throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Skip past whitespace characters starting at the current position.

Specified by:
skipPastSpaces in interface XMLEntityHandler.EntityReader
Throws:
Exception

skipPastName

public void skipPastName(char fastcheck)
                  throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Skip past a sequence of characters that match the XML definition of a Name.

Specified by:
skipPastName in interface XMLEntityHandler.EntityReader
Throws:
Exception

skipPastNmtoken

public void skipPastNmtoken(char fastcheck)
                     throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Skip past a sequence of characters that match the XML definition of an Nmtoken.

Specified by:
skipPastNmtoken in interface XMLEntityHandler.EntityReader
Throws:
Exception

skippedString

public boolean skippedString(char[] s)
                      throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Skip past a sequence of characters that matches the specified character array.

Specified by:
skippedString in interface XMLEntityHandler.EntityReader
Parameters:
s - The characters to match.
Returns:
true if the current character is valid; false otherwise.
Throws:
Exception

scanInvalidChar

public int scanInvalidChar()
                    throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Scan an invalid character.

Specified by:
scanInvalidChar in interface XMLEntityHandler.EntityReader
Returns:
The invalid character as an integer, or -1 if there was a bad encoding.
Throws:
Exception

scanCharRef

public int scanCharRef(boolean hex)
                throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Scan a character reference.

Specified by:
scanCharRef in interface XMLEntityHandler.EntityReader
Returns:
The value of the character, or one of the following error codes: CHARREF_RESULT_SEMICOLON_REQUIRED CHARREF_RESULT_INVALID_CHAR CHARREF_RESULT_OUT_OF_RANGE
Throws:
Exception

scanStringLiteral

public int scanStringLiteral()
                      throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Scan a string literal.

Specified by:
scanStringLiteral in interface XMLEntityHandler.EntityReader
Returns:
The StringPool handle for the string that was scanned, or one of the following error codes: STRINGLIT_RESULT_QUOTE_REQUIRED STRINGLIT_RESULT_INVALID_CHAR
Throws:
Exception

scanAttValue

public int scanAttValue(char qchar,
                        boolean asSymbol)
                 throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Scan an attribute value.

Specified by:
scanAttValue in interface XMLEntityHandler.EntityReader
Parameters:
qchar - The initial quote character, either a single or double quote.
Returns:
The StringPool handle for the string that was scanned, or one of the following error codes: ATTVALUE_RESULT_COMPLEX ATTVALUE_RESULT_LESSTHAN ATTVALUE_RESULT_INVALID_CHAR
Throws:
Exception

scanEntityValue

public int scanEntityValue(int qchar,
                           boolean createString)
                    throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Scan an entity value.

Specified by:
scanEntityValue in interface XMLEntityHandler.EntityReader
Parameters:
qchar - The initial quote character, either a single or double quote.
Returns:
The StringPool handle for the string that was scanned, or one of the following error codes: ENTITYVALUE_RESULT_FINISHED ENTITYVALUE_RESULT_REFERENCE ENTITYVALUE_RESULT_PEREF ENTITYVALUE_RESULT_INVALID_CHAR ENTITYVALUE_RESULT_END_OF_INPUT
Throws:
Exception

scanExpectedName

public boolean scanExpectedName(char fastcheck,
                                StringPool.CharArrayRange expectedName)
                         throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Scan the name that is expected at the current position in the document. This method is invoked when we are scanning the element type in an end tag that must match the element type in the corresponding start tag.

Specified by:
scanExpectedName in interface XMLEntityHandler.EntityReader
Parameters:
fastcheck - A character that is not a legal name character that is provided as a hint to the reader of a character likely to terminate the Name.
expectedName - The characters of the name we expect.
Returns:
true if we scanned the name we expected to find; otherwise false if we did not.
Throws:
Exception

scanQName

public void scanQName(char fastcheck,
                      QName qname)
               throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Add a sequence of characters that match the XML Namespaces definition of a QName to the StringPool. If we find a QName at the current position we will add it to the StringPool and will return the string pool handle of that QName to the caller.

Specified by:
scanQName in interface XMLEntityHandler.EntityReader
Parameters:
fastcheck - A character that is not a legal name character that is provided as a hint to the reader of a character likely to terminate the Name.
Throws:
Exception

scanName

public int scanName(char fastcheck)
             throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Add a sequence of characters that match the XML definition of a Name to the StringPool. If we find a name at the current position we will add it to the StringPool as a symbol and will return the string pool handle for that symbol to the caller.

Specified by:
scanName in interface XMLEntityHandler.EntityReader
Parameters:
fastcheck - A character that is not a legal name character that is provided as a hint to the reader of a character likely to terminate the Name.
Returns:
The StringPool handle for the name that was scanned, or -1 if a name was not found at the current position within the input data.
Throws:
Exception

scanContent

public int scanContent(QName element)
                throws Exception
Description copied from interface: XMLEntityHandler.EntityReader
Skip through the input while we are looking at character data.

Specified by:
scanContent in interface XMLEntityHandler.EntityReader
Returns:
One of the following result codes: CONTENT_RESULT_START_OF_PI CONTENT_RESULT_START_OF_COMMENT CONTENT_RESULT_START_OF_CDSECT CONTENT_RESULT_END_OF_CDSECT CONTENT_RESULT_START_OF_ETAG CONTENT_RESULT_MATCHING_ETAG CONTENT_RESULT_START_OF_ELEMENT CONTENT_RESULT_START_OF_CHARREF CONTENT_RESULT_START_OF_ENTITYREF CONTENT_RESULT_INVALID_CHAR CONTENT_RESULT_MARKUP_NOT_RECOGNIZED CONTENT_RESULT_MARKUP_END_OF_INPUT CONTENT_RESULT_REFERENCE_END_OF_INPUT
Throws:
Exception

init

protected void init(XMLEntityHandler entityHandler,
                    XMLErrorReporter errorReporter,
                    boolean sendCharDataAsCharArray,
                    int lineNumber,
                    int columnNumber)

currentOffset

public int currentOffset()
Return the current offset within this reader.

Specified by:
currentOffset in interface XMLEntityHandler.EntityReader
Returns:
The offset.

getLineNumber

public int getLineNumber()
Return the line number of the current position within the document that we are processing.

Specified by:
getLineNumber in interface XMLEntityHandler.EntityReader
Returns:
The current line number.

getColumnNumber

public int getColumnNumber()
Return the column number of the current position within the document that we are processing.

Specified by:
getColumnNumber in interface XMLEntityHandler.EntityReader
Returns:
The current column number.

setInCDSect

public void setInCDSect(boolean inCDSect)
This method is provided for scanner implementations.

Specified by:
setInCDSect in interface XMLEntityHandler.EntityReader

getInCDSect

public boolean getInCDSect()
This method is provided for scanner implementations.

Specified by:
getInCDSect in interface XMLEntityHandler.EntityReader

changeReaders

protected XMLEntityHandler.EntityReader changeReaders()
                                               throws Exception
This method is called by the reader subclasses at the end of input.

Exception


Copyright © 1999 The Apache Software Foundation. All Rights reserved.