XMLEntityScannerpublic class XMLEntityScanner extends Object implements XMLLocatorImplements the entity scanner methods. |
Fields Summary |
---|
protected Entity$ScannedEntity | fCurrentEntity | protected int | fBufferSize | protected XMLEntityManager | fEntityManager | private static final boolean | DEBUG_ENCODINGSDebug switching readers for encodings. | private Vector | listenersListeners which should know when load is being called | public static final boolean[] | VALID_NAMES | private static final boolean | DEBUG_BUFFERDebug printing of buffer. This debugging flag works best when you
resize the DEFAULT_BUFFER_SIZE down to something reasonable like
64 characters. | private static final boolean | DEBUG_SKIP_STRING | protected SymbolTable | fSymbolTable | protected XMLErrorReporter | fErrorReporter | int[] | whiteSpaceLookup | int | whiteSpaceLen | boolean | whiteSpaceInfoNeeded | protected boolean | fAllowJavaEncodingsAllow Java encoding names. This feature identifier is:
http://apache.org/xml/features/allow-java-encodings | protected static final String | SYMBOL_TABLEProperty identifier: symbol table. | protected static final String | ERROR_REPORTERProperty identifier: error reporter. | protected static final String | ALLOW_JAVA_ENCODINGSFeature identifier: allow Java encodings. | protected PropertyManager | fPropertyManager | boolean | isExternal |
Constructors Summary |
---|
public XMLEntityScanner()Default constructor.
for(int i=0x0041;i<=0x005A ; i++){
VALID_NAMES[i]=true;
}
for(int i=0x0061;i<=0x007A; i++){
VALID_NAMES[i]=true;
}
for(int i=0x0030;i<=0x0039; i++){
VALID_NAMES[i]=true;
}
VALID_NAMES[45]=true;
VALID_NAMES[46]=true;
VALID_NAMES[58]=true;
VALID_NAMES[95]=true;
| public XMLEntityScanner(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)
fEntityManager = entityManager ;
reset(propertyManager);
|
Methods Summary |
---|
public boolean | arrangeCapacity(int length)
return arrangeCapacity(length, false);
| public boolean | arrangeCapacity(int length, boolean changeEntity)
//check if the capacity is availble in the current buffer
//count is no. of characters in the buffer [x][m][l]
//position is '0' based
//System.out.println("fCurrent Entity " + fCurrentEntity);
if((fCurrentEntity.count - fCurrentEntity.position) >= length) {
return true;
}
if(DEBUG_SKIP_STRING){
System.out.println("fCurrentEntity.count = " + fCurrentEntity.count);
System.out.println("fCurrentEntity.position = " + fCurrentEntity.position);
System.out.println("length = " + length);
}
boolean entityChanged = false;
//load more characters -- this function shouldn't change the entity
while((fCurrentEntity.count - fCurrentEntity.position) < length){
if( (fCurrentEntity.ch.length - fCurrentEntity.position) < length){
invokeListeners(0);
System.arraycopy(fCurrentEntity.ch, fCurrentEntity.position, fCurrentEntity.ch,0,fCurrentEntity.count - fCurrentEntity.position);
fCurrentEntity.count = fCurrentEntity.count - fCurrentEntity.position;
fCurrentEntity.position = 0;
}
if((fCurrentEntity.count - fCurrentEntity.position) < length){
int pos = fCurrentEntity.position;
invokeListeners(pos);
entityChanged = load(fCurrentEntity.count, changeEntity);
fCurrentEntity.position = pos;
if(entityChanged)break;
}
if(DEBUG_SKIP_STRING){
System.out.println("fCurrentEntity.count = " + fCurrentEntity.count);
System.out.println("fCurrentEntity.position = " + fCurrentEntity.position);
System.out.println("length = " + length);
}
}
//load changes the position.. set it back to the point where we started.
//after loading check again.
if((fCurrentEntity.count - fCurrentEntity.position) >= length) {
return true;
} else {
return false;
}
| 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.
// normalize encoding name
if (encoding == null) {
encoding = "UTF-8";
}
// try to use an optimized reader
String ENCODING = encoding.toUpperCase(Locale.ENGLISH);
if (ENCODING.equals("UTF-8")) {
if (DEBUG_ENCODINGS) {
System.out.println("$$$ creating UTF8Reader");
}
return new UTF8Reader(inputStream, fCurrentEntity.fBufferSize, fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN), fErrorReporter.getLocale() );
}
if (ENCODING.equals("US-ASCII")) {
if (DEBUG_ENCODINGS) {
System.out.println("$$$ creating ASCIIReader");
}
return new ASCIIReader(inputStream, fCurrentEntity.fBufferSize, fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN), fErrorReporter.getLocale());
}
if(ENCODING.equals("ISO-10646-UCS-4")) {
if(isBigEndian != null) {
boolean isBE = isBigEndian.booleanValue();
if(isBE) {
return new UCSReader(inputStream, UCSReader.UCS4BE);
} else {
return new UCSReader(inputStream, UCSReader.UCS4LE);
}
} else {
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
"EncodingByteOrderUnsupported",
new Object[] { encoding },
XMLErrorReporter.SEVERITY_FATAL_ERROR);
}
}
if(ENCODING.equals("ISO-10646-UCS-2")) {
if(isBigEndian != null) { // sould never happen with this encoding...
boolean isBE = isBigEndian.booleanValue();
if(isBE) {
return new UCSReader(inputStream, UCSReader.UCS2BE);
} else {
return new UCSReader(inputStream, UCSReader.UCS2LE);
}
} else {
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
"EncodingByteOrderUnsupported",
new Object[] { encoding },
XMLErrorReporter.SEVERITY_FATAL_ERROR);
}
}
// check for valid name
boolean validIANA = XMLChar.isValidIANAEncoding(encoding);
boolean validJava = XMLChar.isValidJavaEncoding(encoding);
if (!validIANA || (fAllowJavaEncodings && !validJava)) {
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
"EncodingDeclInvalid",
new Object[] { encoding },
XMLErrorReporter.SEVERITY_FATAL_ERROR);
// NOTE: AndyH suggested that, on failure, we use ISO Latin 1
// because every byte is a valid ISO Latin 1 character.
// It may not translate correctly but if we failed on
// the encoding anyway, then we're expecting the content
// of the document to be bad. This will just prevent an
// invalid UTF-8 sequence to be detected. This is only
// important when continue-after-fatal-error is turned
// on. -Ac
encoding = "ISO-8859-1";
}
// try to use a Java reader
String javaEncoding = EncodingMap.getIANA2JavaMapping(ENCODING);
if (javaEncoding == null) {
if(fAllowJavaEncodings) {
javaEncoding = encoding;
} else {
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
"EncodingDeclInvalid",
new Object[] { encoding },
XMLErrorReporter.SEVERITY_FATAL_ERROR);
// see comment above.
javaEncoding = "ISO8859_1";
}
}
else if (javaEncoding.equals("ASCII")) {
if (DEBUG_ENCODINGS) {
System.out.println("$$$ creating ASCIIReader");
}
return new ASCIIReader(inputStream, fBufferSize, fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN), fErrorReporter.getLocale());
}
if (DEBUG_ENCODINGS) {
System.out.print("$$$ creating Java InputStreamReader: encoding="+javaEncoding);
if (javaEncoding == encoding) {
System.out.print(" (IANA encoding)");
}
System.out.println();
}
return new InputStreamReader(inputStream, javaEncoding);
| public java.lang.String | getBaseSystemId()Returns the base system identifier of the currently scanned
entity, or null if none is available.
return (fCurrentEntity != null && fCurrentEntity.entityLocation != null) ? fCurrentEntity.entityLocation.getExpandedSystemId() : null;
| public int | getChar(int relative)
if(arrangeCapacity(relative + 1, false)){
return fCurrentEntity.ch[fCurrentEntity.position + relative];
}else{
return -1;
}
| public int | getCharacterOffset()
return fCurrentEntity != null ? fCurrentEntity.fTotalCountTillLastLoad + fCurrentEntity.position : -1 ;
| public int | getColumnNumber()
//if the entity is closed, we should return -1
//xxx at first place why such call should be there...
return fCurrentEntity != null ? fCurrentEntity.columnNumber : -1 ;
| public com.sun.xml.internal.stream.Entity$ScannedEntity | getCurrentEntity()
return fCurrentEntity ;
| public java.lang.String | getEncoding()
return fCurrentEntity.encoding ;
| 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.
if (count < 2) {
return new Object[]{"UTF-8", null};
}
// UTF-16, with BOM
int b0 = b4[0] & 0xFF;
int b1 = b4[1] & 0xFF;
if (b0 == 0xFE && b1 == 0xFF) {
// UTF-16, big-endian
return new Object [] {"UTF-16BE", new Boolean(true)};
}
if (b0 == 0xFF && b1 == 0xFE) {
// UTF-16, little-endian
return new Object [] {"UTF-16LE", new Boolean(false)};
}
// default to UTF-8 if we don't have enough bytes to make a
// good determination of the encoding
if (count < 3) {
return new Object [] {"UTF-8", null};
}
// UTF-8 with a BOM
int b2 = b4[2] & 0xFF;
if (b0 == 0xEF && b1 == 0xBB && b2 == 0xBF) {
return new Object [] {"UTF-8", null};
}
// default to UTF-8 if we don't have enough bytes to make a
// good determination of the encoding
if (count < 4) {
return new Object [] {"UTF-8", null};
}
// other encodings
int b3 = b4[3] & 0xFF;
if (b0 == 0x00 && b1 == 0x00 && b2 == 0x00 && b3 == 0x3C) {
// UCS-4, big endian (1234)
return new Object [] {"ISO-10646-UCS-4", new Boolean(true)};
}
if (b0 == 0x3C && b1 == 0x00 && b2 == 0x00 && b3 == 0x00) {
// UCS-4, little endian (4321)
return new Object [] {"ISO-10646-UCS-4", new Boolean(false)};
}
if (b0 == 0x00 && b1 == 0x00 && b2 == 0x3C && b3 == 0x00) {
// UCS-4, unusual octet order (2143)
// REVISIT: What should this be?
return new Object [] {"ISO-10646-UCS-4", null};
}
if (b0 == 0x00 && b1 == 0x3C && b2 == 0x00 && b3 == 0x00) {
// UCS-4, unusual octect order (3412)
// REVISIT: What should this be?
return new Object [] {"ISO-10646-UCS-4", null};
}
if (b0 == 0x00 && b1 == 0x3C && b2 == 0x00 && b3 == 0x3F) {
// UTF-16, big-endian, no BOM
// (or could turn out to be UCS-2...
// REVISIT: What should this be?
return new Object [] {"UTF-16BE", new Boolean(true)};
}
if (b0 == 0x3C && b1 == 0x00 && b2 == 0x3F && b3 == 0x00) {
// UTF-16, little-endian, no BOM
// (or could turn out to be UCS-2...
return new Object [] {"UTF-16LE", new Boolean(false)};
}
if (b0 == 0x4C && b1 == 0x6F && b2 == 0xA7 && b3 == 0x94) {
// EBCDIC
// a la xerces1, return CP037 instead of EBCDIC here
return new Object [] {"CP037", null};
}
// default encoding
return new Object [] {"UTF-8", null};
| public java.lang.String | getExpandedSystemId()Returns the expanded system identifier.
return (fCurrentEntity != null && fCurrentEntity.entityLocation != null) ? fCurrentEntity.entityLocation.getExpandedSystemId() : null;
| public int | getLineNumber()
//if the entity is closed, we should return -1
//xxx at first place why such call should be there...
return fCurrentEntity != null ? fCurrentEntity.lineNumber : -1 ;
| public java.lang.String | getLiteralSystemId()Returns the literal system identifier.
return (fCurrentEntity != null && fCurrentEntity.entityLocation != null) ? fCurrentEntity.entityLocation.getLiteralSystemId() : null;
| public java.lang.String | getPublicId()Returns the public identifier.
return (fCurrentEntity != null && fCurrentEntity.entityLocation != null) ? fCurrentEntity.entityLocation.getPublicId() : null;
| public java.lang.String | getVersion()
return fCurrentEntity.version ;
| public java.lang.String | getXMLVersion()Returns the XML version of the current entity. This will normally be the
value from the XML or text declaration or defaulted by the parser. Note that
that this value may be different than the version of the processing rules
applied to the current entity. For instance, an XML 1.1 document may refer to
XML 1.0 entities. In such a case the rules of XML 1.1 are applied to the entire
document. Also note that, for a given entity, this value can only be considered
final once the XML or text declaration has been read or once it has been
determined that there is no such declaration.
if (fCurrentEntity != null) {
return fCurrentEntity.xmlVersion;
}
return null;
| private void | invokeListeners(int loadPos)
for(int i=0;i<listeners.size();i++){
XMLBufferListener listener =(XMLBufferListener) listeners.get(i);
listener.refresh(loadPos);
}
| public boolean | isExternal()Returns true if the current entity being scanned is external.
return fCurrentEntity.isExternal();
| public boolean | isSpace(char ch)
return (ch == ' ") || (ch == '\n") || (ch == '\t") || (ch == '\r");
| final boolean | load(int offset, boolean changeEntity)Loads a chunk of text.
if (DEBUG_BUFFER) {
System.out.print("(load, "+offset+": ");
print();
System.out.println();
}
//maintaing the count till last load
fCurrentEntity.fTotalCountTillLastLoad = fCurrentEntity.fTotalCountTillLastLoad + fCurrentEntity.fLastCount ;
// read characters
int length = fCurrentEntity.mayReadChunks ?
(fCurrentEntity.ch.length - offset): (fCurrentEntity.DEFAULT_XMLDECL_BUFFER_SIZE);
if (DEBUG_BUFFER) System.out.println(" length to try to read: "+length);
int count = fCurrentEntity.reader.read(fCurrentEntity.ch, offset, length);
if (DEBUG_BUFFER) System.out.println(" length actually read: "+count);
// reset count and position
boolean entityChanged = false;
if (count != -1) {
if (count != 0) {
// record the last count
fCurrentEntity.fLastCount = count;
fCurrentEntity.count = count + offset;
fCurrentEntity.position = offset;
}
}
// end of this entity
else {
fCurrentEntity.count = offset;
fCurrentEntity.position = offset;
entityChanged = true;
if (changeEntity) {
//notify the entity manager about the end of entity
fEntityManager.endEntity();
//return if the current entity becomes null
if(fCurrentEntity == null){
return true ;
}
// handle the trailing edges
if (fCurrentEntity.position == fCurrentEntity.count) {
load(0, true);
}
}
}
if (DEBUG_BUFFER) {
System.out.print(")load, "+offset+": ");
print();
System.out.println();
}
return entityChanged;
| public int | peekChar()Returns the next character on the input.
Note: The character is not consumed.
if (DEBUG_BUFFER) {
System.out.print("(peekChar: ");
print();
System.out.println();
}
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(0);
load(0, true);
}
// peek at character
int c = fCurrentEntity.ch[fCurrentEntity.position];
// return peeked character
if (DEBUG_BUFFER) {
System.out.print(")peekChar: ");
print();
if (isExternal) {
System.out.println(" -> '"+(c!='\r"?(char)c:'\n")+"'");
} else {
System.out.println(" -> '"+(char)c+"'");
}
}
if (isExternal) {
return c != '\r" ? c : '\n";
} else {
return c;
}
| final void | print()Prints the contents of the buffer.
if (DEBUG_BUFFER) {
if (fCurrentEntity != null) {
System.out.print('[");
System.out.print(fCurrentEntity.count);
System.out.print(' ");
System.out.print(fCurrentEntity.position);
if (fCurrentEntity.count > 0) {
System.out.print(" \"");
for (int i = 0; i < fCurrentEntity.count; i++) {
if (i == fCurrentEntity.position) {
System.out.print('^");
}
char c = fCurrentEntity.ch[i];
switch (c) {
case '\n": {
System.out.print("\\n");
break;
}
case '\r": {
System.out.print("\\r");
break;
}
case '\t": {
System.out.print("\\t");
break;
}
case '\\": {
System.out.print("\\\\");
break;
}
default: {
System.out.print(c);
}
}
}
if (fCurrentEntity.position == fCurrentEntity.count) {
System.out.print('^");
}
System.out.print('"");
}
System.out.print(']");
System.out.print(" @ ");
System.out.print(fCurrentEntity.lineNumber);
System.out.print(',");
System.out.print(fCurrentEntity.columnNumber);
} else {
System.out.print("*NO CURRENT ENTITY*");
}
}
| public void | registerListener(com.sun.xml.internal.stream.XMLBufferListener listener)Registers the listener object and provides callback.
if(!listeners.contains(listener))
listeners.add(listener);
| public void | reset(com.sun.org.apache.xerces.internal.impl.PropertyManager propertyManager)Resets the components.
fSymbolTable = (SymbolTable)propertyManager.getProperty(SYMBOL_TABLE) ;
fErrorReporter = (XMLErrorReporter)propertyManager.getProperty(ERROR_REPORTER) ;
fCurrentEntity = null;
whiteSpaceLen = 0;
whiteSpaceInfoNeeded = true;
listeners.clear();
| public void | reset(com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager componentManager)Resets the component. The component can query the component manager
about any features and properties that affect the operation of the
component.
//System.out.println(" this is being called");
// xerces features
try {
fAllowJavaEncodings = componentManager.getFeature(ALLOW_JAVA_ENCODINGS);
} catch (XMLConfigurationException e) {
fAllowJavaEncodings = false;
}
//xerces properties
fSymbolTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE);
fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);
fCurrentEntity = null;
whiteSpaceLen = 0;
whiteSpaceInfoNeeded = true;
listeners.clear();
| public void | reset(com.sun.org.apache.xerces.internal.util.SymbolTable symbolTable, com.sun.org.apache.xerces.internal.impl.XMLEntityManager entityManager, com.sun.org.apache.xerces.internal.impl.XMLErrorReporter reporter)
fCurrentEntity = null;
fSymbolTable = symbolTable;
fEntityManager = entityManager;
fErrorReporter = reporter;
| public int | scanChar()Returns the next character on the input.
Note: The character is consumed.
if (DEBUG_BUFFER) {
System.out.print("(scanChar: ");
print();
System.out.println();
}
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(0);
load(0, true);
}
// scan character
int c = fCurrentEntity.ch[fCurrentEntity.position++];
if (c == '\n" ||
(c == '\r" && isExternal)) {
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(1);
fCurrentEntity.ch[0] = (char)c;
load(1, false);
}
if (c == '\r" && isExternal) {
if (fCurrentEntity.ch[fCurrentEntity.position++] != '\n") {
fCurrentEntity.position--;
}
c = '\n";
}
}
// return character that was scanned
if (DEBUG_BUFFER) {
System.out.print(")scanChar: ");
print();
System.out.println(" -> '"+(char)c+"'");
}
fCurrentEntity.columnNumber++;
return c;
| public int | scanContent(com.sun.org.apache.xerces.internal.xni.XMLString content)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.
if (DEBUG_BUFFER) {
System.out.print("(scanContent: ");
print();
System.out.println();
}
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(0);
load(0, true);
} else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
invokeListeners(0);
fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
load(1, false);
fCurrentEntity.position = 0;
}
// normalize newlines
int offset = fCurrentEntity.position;
int c = fCurrentEntity.ch[offset];
int newlines = 0;
if (c == '\n" || (c == '\r" && isExternal)) {
if (DEBUG_BUFFER) {
System.out.print("[newline, "+offset+", "+fCurrentEntity.position+": ");
print();
System.out.println();
}
do {
c = fCurrentEntity.ch[fCurrentEntity.position++];
if (c == '\r" && isExternal) {
newlines++;
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (fCurrentEntity.position == fCurrentEntity.count) {
offset = 0;
invokeListeners(newlines);
fCurrentEntity.position = newlines;
if (load(newlines, false)) {
break;
}
}
if (fCurrentEntity.ch[fCurrentEntity.position] == '\n") {
fCurrentEntity.position++;
offset++;
}
/*** NEWLINE NORMALIZATION ***/
else {
newlines++;
}
} else if (c == '\n") {
newlines++;
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (fCurrentEntity.position == fCurrentEntity.count) {
offset = 0;
invokeListeners(newlines);
fCurrentEntity.position = newlines;
if (load(newlines, false)) {
break;
}
}
} else {
fCurrentEntity.position--;
break;
}
} while (fCurrentEntity.position < fCurrentEntity.count - 1);
for (int i = offset; i < fCurrentEntity.position; i++) {
fCurrentEntity.ch[i] = '\n";
}
int length = fCurrentEntity.position - offset;
if (fCurrentEntity.position == fCurrentEntity.count - 1) {
//CHANGED: dont replace the value.. append to the buffer. This gives control to the callee
//on buffering the data..
content.setValues(fCurrentEntity.ch, offset, length);
//content.append(fCurrentEntity.ch, offset, length);
if (DEBUG_BUFFER) {
System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": ");
print();
System.out.println();
}
return -1;
}
if (DEBUG_BUFFER) {
System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": ");
print();
System.out.println();
}
}
while (fCurrentEntity.position < fCurrentEntity.count) {
c = fCurrentEntity.ch[fCurrentEntity.position++];
if (!XMLChar.isContent(c)) {
fCurrentEntity.position--;
break;
}
}
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines;
//CHANGED: dont replace the value.. append to the buffer. This gives control to the callee
//on buffering the data..
content.setValues(fCurrentEntity.ch, offset, length);
//content.append(fCurrentEntity.ch, offset, length);
// return next character
if (fCurrentEntity.position != fCurrentEntity.count) {
c = fCurrentEntity.ch[fCurrentEntity.position];
// REVISIT: Does this need to be updated to fix the
// #x0D ^#x0A newline normalization problem? -Ac
if (c == '\r" && isExternal) {
c = '\n";
}
} else {
c = -1;
}
if (DEBUG_BUFFER) {
System.out.print(")scanContent: ");
print();
System.out.println(" -> '"+(char)c+"'");
}
return c;
| public boolean | scanData(java.lang.String delimiter, com.sun.org.apache.xerces.internal.util.XMLStringBuffer buffer)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.
boolean done = false;
int delimLen = delimiter.length();
char charAt0 = delimiter.charAt(0);
do {
if (DEBUG_BUFFER) {
System.out.print("(scanData: ");
print();
System.out.println();
}
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
load(0, true);
}
boolean bNextEntity = false;
while ((fCurrentEntity.position > fCurrentEntity.count - delimLen)
&& (!bNextEntity))
{
System.arraycopy(fCurrentEntity.ch,
fCurrentEntity.position,
fCurrentEntity.ch,
0,
fCurrentEntity.count - fCurrentEntity.position);
bNextEntity = load(fCurrentEntity.count - fCurrentEntity.position, false);
fCurrentEntity.position = 0;
fCurrentEntity.startPosition = 0;
}
if (fCurrentEntity.position > fCurrentEntity.count - delimLen) {
// something must be wrong with the input: e.g., file ends in an unterminated comment
int length = fCurrentEntity.count - fCurrentEntity.position;
buffer.append (fCurrentEntity.ch, fCurrentEntity.position, length);
fCurrentEntity.columnNumber += fCurrentEntity.count;
fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
fCurrentEntity.position = fCurrentEntity.count;
fCurrentEntity.startPosition = fCurrentEntity.count;
load(0, true);
return false;
}
// normalize newlines
int offset = fCurrentEntity.position;
int c = fCurrentEntity.ch[offset];
int newlines = 0;
if (c == '\n" || (c == '\r" && isExternal)) {
if (DEBUG_BUFFER) {
System.out.print("[newline, "+offset+", "+fCurrentEntity.position+": ");
print();
System.out.println();
}
do {
c = fCurrentEntity.ch[fCurrentEntity.position++];
if (c == '\r" && isExternal) {
newlines++;
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (fCurrentEntity.position == fCurrentEntity.count) {
offset = 0;
invokeListeners(newlines);
fCurrentEntity.position = newlines;
if (load(newlines, false)) {
break;
}
}
if (fCurrentEntity.ch[fCurrentEntity.position] == '\n") {
fCurrentEntity.position++;
offset++;
}
/*** NEWLINE NORMALIZATION ***/
else {
newlines++;
}
} else if (c == '\n") {
newlines++;
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (fCurrentEntity.position == fCurrentEntity.count) {
offset = 0;
invokeListeners(newlines);
fCurrentEntity.position = newlines;
fCurrentEntity.count = newlines;
if (load(newlines, false)) {
break;
}
}
} else {
fCurrentEntity.position--;
break;
}
} while (fCurrentEntity.position < fCurrentEntity.count - 1);
for (int i = offset; i < fCurrentEntity.position; i++) {
fCurrentEntity.ch[i] = '\n";
}
int length = fCurrentEntity.position - offset;
if (fCurrentEntity.position == fCurrentEntity.count - 1) {
buffer.append(fCurrentEntity.ch, offset, length);
if (DEBUG_BUFFER) {
System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": ");
print();
System.out.println();
}
return true;
}
if (DEBUG_BUFFER) {
System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": ");
print();
System.out.println();
}
}
// iterate over buffer looking for delimiter
OUTER: while (fCurrentEntity.position < fCurrentEntity.count) {
c = fCurrentEntity.ch[fCurrentEntity.position++];
if (c == charAt0) {
// looks like we just hit the delimiter
int delimOffset = fCurrentEntity.position - 1;
for (int i = 1; i < delimLen; i++) {
if (fCurrentEntity.position == fCurrentEntity.count) {
fCurrentEntity.position -= i;
break OUTER;
}
c = fCurrentEntity.ch[fCurrentEntity.position++];
if (delimiter.charAt(i) != c) {
fCurrentEntity.position -= i;
break;
}
}
if (fCurrentEntity.position == delimOffset + delimLen) {
done = true;
break;
}
} else if (c == '\n" || (isExternal && c == '\r")) {
fCurrentEntity.position--;
break;
} else if (XMLChar.isInvalid(c)) {
fCurrentEntity.position--;
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines;
buffer.append(fCurrentEntity.ch, offset, length);
return true;
}
}
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines;
if (done) {
length -= delimLen;
}
buffer.append(fCurrentEntity.ch, offset, length);
// return true if string was skipped
if (DEBUG_BUFFER) {
System.out.print(")scanData: ");
print();
System.out.println(" -> " + done);
}
} while (!done);
return !done;
| public int | scanLiteral(int quote, com.sun.org.apache.xerces.internal.xni.XMLString content)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.
if (DEBUG_BUFFER) {
System.out.print("(scanLiteral, '"+(char)quote+"': ");
print();
System.out.println();
}
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(0);
load(0, true);
} else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
invokeListeners(0);
fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
load(1, false);
fCurrentEntity.position = 0;
}
// normalize newlines
int offset = fCurrentEntity.position;
int c = fCurrentEntity.ch[offset];
int newlines = 0;
if(whiteSpaceInfoNeeded)
whiteSpaceLen=0;
if (c == '\n" || (c == '\r" && isExternal)) {
if (DEBUG_BUFFER) {
System.out.print("[newline, "+offset+", "+fCurrentEntity.position+": ");
print();
System.out.println();
}
do {
c = fCurrentEntity.ch[fCurrentEntity.position++];
if (c == '\r" && isExternal) {
newlines++;
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(newlines);
offset = 0;
fCurrentEntity.position = newlines;
if (load(newlines, false)) {
break;
}
}
if (fCurrentEntity.ch[fCurrentEntity.position] == '\n") {
fCurrentEntity.position++;
offset++;
}
/*** NEWLINE NORMALIZATION ***/
else {
newlines++;
}
/***/
} else if (c == '\n") {
newlines++;
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (fCurrentEntity.position == fCurrentEntity.count) {
offset = 0;
invokeListeners(newlines);
fCurrentEntity.position = newlines;
if (load(newlines, false)) {
break;
}
}
/*** NEWLINE NORMALIZATION ***
* if (fCurrentEntity.ch[fCurrentEntity.position] == '\r'
* && external) {
* fCurrentEntity.position++;
* offset++;
* }
* /***/
} else {
fCurrentEntity.position--;
break;
}
} while (fCurrentEntity.position < fCurrentEntity.count - 1);
int i=0;
for ( i = offset; i < fCurrentEntity.position; i++) {
fCurrentEntity.ch[i] = '\n";
whiteSpaceLookup[whiteSpaceLen++]=i;
}
int length = fCurrentEntity.position - offset;
if (fCurrentEntity.position == fCurrentEntity.count - 1) {
content.setValues(fCurrentEntity.ch, offset, length);
if (DEBUG_BUFFER) {
System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": ");
print();
System.out.println();
}
return -1;
}
if (DEBUG_BUFFER) {
System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": ");
print();
System.out.println();
}
}
// scan literal value
while (fCurrentEntity.position < fCurrentEntity.count) {
c = fCurrentEntity.ch[fCurrentEntity.position++];
if ((c == quote &&
(!fCurrentEntity.literal || isExternal))
|| c == '%" || !XMLChar.isContent(c)) {
fCurrentEntity.position--;
break;
}
if(whiteSpaceInfoNeeded){
if(c == 0x20 || c == 0x9){
if(whiteSpaceLen < whiteSpaceLookup.length){
whiteSpaceLookup[whiteSpaceLen++]= fCurrentEntity.position-1;
}else{
int [] tmp = new int[whiteSpaceLookup.length*2];
System.arraycopy(whiteSpaceLookup,0,tmp,0,whiteSpaceLookup.length);
whiteSpaceLookup = tmp;
whiteSpaceLookup[whiteSpaceLen++]= fCurrentEntity.position - 1;
}
}
}
}
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines;
content.setValues(fCurrentEntity.ch, offset, length);
// return next character
if (fCurrentEntity.position != fCurrentEntity.count) {
c = fCurrentEntity.ch[fCurrentEntity.position];
// NOTE: We don't want to accidentally signal the
// end of the literal if we're expanding an
// entity appearing in the literal. -Ac
if (c == quote && fCurrentEntity.literal) {
c = -1;
}
} else {
c = -1;
}
if (DEBUG_BUFFER) {
System.out.print(")scanLiteral, '"+(char)quote+"': ");
print();
System.out.println(" -> '"+(char)c+"'");
}
return c;
| public 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.
Note: The Name characters are consumed.
Note: The string returned must be a symbol. The
SymbolTable can be used for this purpose.
if (DEBUG_BUFFER) {
System.out.print("(scanName: ");
print();
System.out.println();
}
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(0);
load(0, true);
}
// scan name
int offset = fCurrentEntity.position;
if (XMLChar.isNameStart(fCurrentEntity.ch[offset])) {
if (++fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(1);
fCurrentEntity.ch[0] = fCurrentEntity.ch[offset];
offset = 0;
if (load(1, false)) {
fCurrentEntity.columnNumber++;
String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
if (DEBUG_BUFFER) {
System.out.print(")scanName: ");
print();
System.out.println(" -> "+String.valueOf(symbol));
}
return symbol;
}
}
boolean vc =false;
while (true ){
//XMLChar.isName(fCurrentEntity.ch[fCurrentEntity.position])) ;
char c = fCurrentEntity.ch[fCurrentEntity.position];
if(c < 127){
vc = VALID_NAMES[c];
}else{
vc = XMLChar.isName(c);
}
if(!vc)break;
if (++fCurrentEntity.position == fCurrentEntity.count) {
int length = fCurrentEntity.position - offset;
invokeListeners(length);
if (length == fCurrentEntity.fBufferSize) {
// bad luck we have to resize our buffer
char[] tmp = new char[fCurrentEntity.fBufferSize * 2];
System.arraycopy(fCurrentEntity.ch, offset,
tmp, 0, length);
fCurrentEntity.ch = tmp;
fCurrentEntity.fBufferSize *= 2;
} else {
System.arraycopy(fCurrentEntity.ch, offset,
fCurrentEntity.ch, 0, length);
}
offset = 0;
if (load(length, false)) {
break;
}
}
}
}
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length;
// return name
String symbol;
if (length > 0) {
symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length);
} else
symbol = null;
if (DEBUG_BUFFER) {
System.out.print(")scanName: ");
print();
System.out.println(" -> "+String.valueOf(symbol));
}
return symbol;
| public 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.
Note: The NMTOKEN characters are consumed.
Note: The string returned must be a symbol. The
SymbolTable can be used for this purpose.
if (DEBUG_BUFFER) {
System.out.print("(scanNmtoken: ");
print();
System.out.println();
}
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(0);
load(0, true);
}
// scan nmtoken
int offset = fCurrentEntity.position;
boolean vc = false;
char c;
while (true){
//while (XMLChar.isName(fCurrentEntity.ch[fCurrentEntity.position])) {
c = fCurrentEntity.ch[fCurrentEntity.position];
if(c < 127){
vc = VALID_NAMES[c];
}else{
vc = XMLChar.isName(c);
}
if(!vc)break;
if (++fCurrentEntity.position == fCurrentEntity.count) {
int length = fCurrentEntity.position - offset;
invokeListeners(length);
if (length == fCurrentEntity.fBufferSize) {
// bad luck we have to resize our buffer
char[] tmp = new char[fCurrentEntity.fBufferSize * 2];
System.arraycopy(fCurrentEntity.ch, offset,
tmp, 0, length);
fCurrentEntity.ch = tmp;
fCurrentEntity.fBufferSize *= 2;
} else {
System.arraycopy(fCurrentEntity.ch, offset,
fCurrentEntity.ch, 0, length);
}
offset = 0;
if (load(length, false)) {
break;
}
}
}
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length;
// return nmtoken
String symbol = null;
if (length > 0) {
symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length);
}
if (DEBUG_BUFFER) {
System.out.print(")scanNmtoken: ");
print();
System.out.println(" -> "+String.valueOf(symbol));
}
return symbol;
| public boolean | scanQName(com.sun.org.apache.xerces.internal.xni.QName qname)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.
if (DEBUG_BUFFER) {
System.out.print("(scanQName, "+qname+": ");
print();
System.out.println();
}
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(0);
load(0, true);
}
// scan qualified name
int offset = fCurrentEntity.position;
//making a check if if the specified character is a valid name start character
//as defined by production [5] in the XML 1.0 specification.
// Name ::= (Letter | '_' | ':') (NameChar)*
if (XMLChar.isNameStart(fCurrentEntity.ch[offset])) {
if (++fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(1);
fCurrentEntity.ch[0] = fCurrentEntity.ch[offset];
offset = 0;
if (load(1, false)) {
fCurrentEntity.columnNumber++;
//adding into symbol table.
//XXX We are trying to add single character in SymbolTable??????
String name = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
qname.setValues(null, name, name, null);
if (DEBUG_BUFFER) {
System.out.print(")scanQName, "+qname+": ");
print();
System.out.println(" -> true");
}
return true;
}
}
int index = -1;
boolean vc = false;
while ( true){
//XMLChar.isName(fCurrentEntity.ch[fCurrentEntity.position])) ;
char c = fCurrentEntity.ch[fCurrentEntity.position];
if(c < 127){
vc = VALID_NAMES[c];
}else{
vc = XMLChar.isName(c);
}
if(!vc)break;
if (c == ':") {
if (index != -1) {
break;
}
index = fCurrentEntity.position;
}
if (++fCurrentEntity.position == fCurrentEntity.count) {
int length = fCurrentEntity.position - offset;
invokeListeners(length);
if (length == fCurrentEntity.fBufferSize) {
// bad luck we have to resize our buffer
char[] tmp = new char[fCurrentEntity.fBufferSize * 2];
System.arraycopy(fCurrentEntity.ch, offset,
tmp, 0, length);
fCurrentEntity.ch = tmp;
fCurrentEntity.fBufferSize *= 2;
} else {
System.arraycopy(fCurrentEntity.ch, offset,
fCurrentEntity.ch, 0, length);
}
if (index != -1) {
index = index - offset;
}
offset = 0;
if (load(length, false)) {
break;
}
}
}
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length;
if (length > 0) {
String prefix = null;
String localpart = null;
String rawname = fSymbolTable.addSymbol(fCurrentEntity.ch,
offset, length);
if (index != -1) {
int prefixLength = index - offset;
prefix = fSymbolTable.addSymbol(fCurrentEntity.ch,
offset, prefixLength);
int len = length - prefixLength - 1;
localpart = fSymbolTable.addSymbol(fCurrentEntity.ch,
index + 1, len);
} else {
localpart = rawname;
}
qname.setValues(prefix, localpart, rawname, null);
if (DEBUG_BUFFER) {
System.out.print(")scanQName, "+qname+": ");
print();
System.out.println(" -> true");
}
return true;
}
}
// no qualified name found
if (DEBUG_BUFFER) {
System.out.print(")scanQName, "+qname+": ");
print();
System.out.println(" -> false");
}
return false;
| public void | setBaseSystemId(java.lang.String systemId)
//no-op
| public void | setBufferSize(int size)
// REVISIT: Buffer size passed to entity scanner
// was not being kept in synch with the actual size
// of the buffers in each scanned entity. If any
// of the buffers were actually resized, it was possible
// that the parser would throw an ArrayIndexOutOfBoundsException
// for documents which contained names which are longer than
// the current buffer size. Conceivably the buffer size passed
// to entity scanner could be used to determine a minimum size
// for resizing, if doubling its size is smaller than this
// minimum. -- mrglavas
fBufferSize = size;
| public void | setColumnNumber(int col)
// no-op
| public void | setCurrentEntity(com.sun.xml.internal.stream.Entity$ScannedEntity scannedEntity)set the instance of current scanned entity.
fCurrentEntity = scannedEntity ;
if(fCurrentEntity != null){
isExternal = fCurrentEntity.isExternal();
if(DEBUG_BUFFER)
System.out.println("Current Entity is "+scannedEntity.name);
}
| public void | setEncoding(java.lang.String encoding)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).
if (DEBUG_ENCODINGS) {
System.out.println("$$$ setEncoding: "+encoding);
}
if (fCurrentEntity.stream != null) {
// if the encoding is the same, don't change the reader and
// re-use the original reader used by the OneCharReader
// NOTE: Besides saving an object, this overcomes deficiencies
// in the UTF-16 reader supplied with the standard Java
// distribution (up to and including 1.3). The UTF-16
// decoder buffers 8K blocks even when only asked to read
// a single char! -Ac
if (fCurrentEntity.encoding == null ||
!fCurrentEntity.encoding.equals(encoding)) {
// UTF-16 is a bit of a special case. If the encoding is UTF-16,
// and we know the endian-ness, we shouldn't change readers.
// If it's ISO-10646-UCS-(2|4), then we'll have to deduce
// the endian-ness from the encoding we presently have.
if(fCurrentEntity.encoding != null && fCurrentEntity.encoding.startsWith("UTF-16")) {
String ENCODING = encoding.toUpperCase(Locale.ENGLISH);
if(ENCODING.equals("UTF-16")) return;
if(ENCODING.equals("ISO-10646-UCS-4")) {
if(fCurrentEntity.encoding.equals("UTF-16BE")) {
fCurrentEntity.reader = new UCSReader(fCurrentEntity.stream, UCSReader.UCS4BE);
} else {
fCurrentEntity.reader = new UCSReader(fCurrentEntity.stream, UCSReader.UCS4LE);
}
return;
}
if(ENCODING.equals("ISO-10646-UCS-2")) {
if(fCurrentEntity.encoding.equals("UTF-16BE")) {
fCurrentEntity.reader = new UCSReader(fCurrentEntity.stream, UCSReader.UCS2BE);
} else {
fCurrentEntity.reader = new UCSReader(fCurrentEntity.stream, UCSReader.UCS2LE);
}
return;
}
}
// wrap a new reader around the input stream, changing
// the encoding
if (DEBUG_ENCODINGS) {
System.out.println("$$$ creating new reader from stream: "+
fCurrentEntity.stream);
}
//fCurrentEntity.stream.reset();
fCurrentEntity.reader = createReader(fCurrentEntity.stream, encoding, null);
fCurrentEntity.encoding = encoding;
} else {
if (DEBUG_ENCODINGS)
System.out.println("$$$ reusing old reader on stream");
}
}
| public void | setExpandedSystemId(java.lang.String systemId)
//no-op
| public void | setLineNumber(int line)
//no-op
| public void | setLiteralSystemId(java.lang.String systemId)
//no-op
| public void | setPublicId(java.lang.String publicId)
//no-op
| public void | setVersion(java.lang.String version)the version of the current entity being scanned
fCurrentEntity.version = version;
| void | setXMLVersion(java.lang.String version)
fCurrentEntity.xmlVersion = version;
| public boolean | skipChar(int c)Skips a character appearing immediately on the input.
Note: The character is consumed only if it matches
the specified character.
if (DEBUG_BUFFER) {
System.out.print("(skipChar, '"+(char)c+"': ");
print();
System.out.println();
}
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(0);
load(0, true);
}
// skip character
int cc = fCurrentEntity.ch[fCurrentEntity.position];
if (cc == c) {
fCurrentEntity.position++;
if (c == '\n") {
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
} else {
fCurrentEntity.columnNumber++;
}
if (DEBUG_BUFFER) {
System.out.print(")skipChar, '"+(char)c+"': ");
print();
System.out.println(" -> true");
}
return true;
} else if (c == '\n" && cc == '\r" && isExternal) {
// handle newlines
if (fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(1);
fCurrentEntity.ch[0] = (char)cc;
load(1, false);
}
fCurrentEntity.position++;
if (fCurrentEntity.ch[fCurrentEntity.position] == '\n") {
fCurrentEntity.position++;
}
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (DEBUG_BUFFER) {
System.out.print(")skipChar, '"+(char)c+"': ");
print();
System.out.println(" -> true");
}
return true;
}
// character was not skipped
if (DEBUG_BUFFER) {
System.out.print(")skipChar, '"+(char)c+"': ");
print();
System.out.println(" -> false");
}
return false;
| public boolean | skipDeclSpaces()Skips space characters appearing immediately on the input that would
match non-terminal S (0x09, 0x0A, 0x0D, 0x20) before end of line
normalization is performed. This is useful when scanning structures
such as the XMLDecl and TextDecl that can only contain US-ASCII
characters.
Note: The characters are consumed only if they would
match non-terminal S before end of line normalization is performed.
if (DEBUG_BUFFER) {
System.out.print("(skipDeclSpaces: ");
//XMLEntityManager.print(fCurrentEntity);
System.out.println();
}
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
load(0, true);
}
// skip spaces
int c = fCurrentEntity.ch[fCurrentEntity.position];
if (XMLChar.isSpace(c)) {
boolean external = fCurrentEntity.isExternal();
do {
boolean entityChanged = false;
// handle newlines
if (c == '\n" || (external && c == '\r")) {
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (fCurrentEntity.position == fCurrentEntity.count - 1) {
fCurrentEntity.ch[0] = (char)c;
entityChanged = load(1, true);
if (!entityChanged)
// the load change the position to be 1,
// need to restore it when entity not changed
fCurrentEntity.position = 0;
}
if (c == '\r" && external) {
// REVISIT: Does this need to be updated to fix the
// #x0D ^#x0A newline normalization problem? -Ac
if (fCurrentEntity.ch[++fCurrentEntity.position] != '\n") {
fCurrentEntity.position--;
}
}
/*** NEWLINE NORMALIZATION ***
* else {
* if (fCurrentEntity.ch[fCurrentEntity.position + 1] == '\r'
* && external) {
* fCurrentEntity.position++;
* }
* }
* /***/
} else {
fCurrentEntity.columnNumber++;
}
// load more characters, if needed
if (!entityChanged)
fCurrentEntity.position++;
if (fCurrentEntity.position == fCurrentEntity.count) {
load(0, true);
}
} while (XMLChar.isSpace(c = fCurrentEntity.ch[fCurrentEntity.position]));
if (DEBUG_BUFFER) {
System.out.print(")skipDeclSpaces: ");
// XMLEntityManager.print(fCurrentEntity);
System.out.println(" -> true");
}
return true;
}
// no spaces were found
if (DEBUG_BUFFER) {
System.out.print(")skipDeclSpaces: ");
//XMLEntityManager.print(fCurrentEntity);
System.out.println(" -> false");
}
return false;
| public boolean | skipSpaces()Skips space characters appearing immediately on the input.
Note: The characters are consumed only if they are
space characters.
if (DEBUG_BUFFER) {
System.out.print("(skipSpaces: ");
print();
System.out.println();
}
//boolean entityChanged = false;
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(0);
load(0, true);
}
//we are doing this check only in skipSpace() because it is called by
//fMiscDispatcher and we want the parser to exit gracefully when document
//is well-formed.
//it is possible that end of document is reached and
//fCurrentEntity becomes null
//nothing was read so entity changed 'false' should be returned.
if(fCurrentEntity == null){
return false ;
}
// skip spaces
int c = fCurrentEntity.ch[fCurrentEntity.position];
if (XMLChar.isSpace(c)) {
do {
boolean entityChanged = false;
// handle newlines
if (c == '\n" || (isExternal && c == '\r")) {
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (fCurrentEntity.position == fCurrentEntity.count - 1) {
invokeListeners(0);
fCurrentEntity.ch[0] = (char)c;
entityChanged = load(1, true);
if (!entityChanged){
// the load change the position to be 1,
// need to restore it when entity not changed
fCurrentEntity.position = 0;
}else if(fCurrentEntity == null){
return true ;
}
}
if (c == '\r" && isExternal) {
// REVISIT: Does this need to be updated to fix the
// #x0D ^#x0A newline normalization problem? -Ac
if (fCurrentEntity.ch[++fCurrentEntity.position] != '\n") {
fCurrentEntity.position--;
}
}
} else {
fCurrentEntity.columnNumber++;
}
// load more characters, if needed
if (!entityChanged){
fCurrentEntity.position++;
}
if (fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(0);
load(0, true);
//we are doing this check only in skipSpace() because it is called by
//fMiscDispatcher and we want the parser to exit gracefully when document
//is well-formed.
//it is possible that end of document is reached and
//fCurrentEntity becomes null
//nothing was read so entity changed 'false' should be returned.
if(fCurrentEntity == null){
return true ;
}
}
} while (XMLChar.isSpace(c = fCurrentEntity.ch[fCurrentEntity.position]));
if (DEBUG_BUFFER) {
System.out.print(")skipSpaces: ");
print();
System.out.println(" -> true");
}
return true;
}
// no spaces were found
if (DEBUG_BUFFER) {
System.out.print(")skipSpaces: ");
print();
System.out.println(" -> false");
}
return false;
| public boolean | skipString(java.lang.String s)Skips the specified string appearing immediately on the input.
Note: The characters are consumed only if all
the characters are skipped.
final int length = s.length();
//first make sure that required capacity is avaible
if(arrangeCapacity(length, false)){
final int beforeSkip = fCurrentEntity.position ;
int afterSkip = fCurrentEntity.position + length - 1 ;
if(DEBUG_SKIP_STRING){
System.out.println("skipString,length = " + s + "," + length);
System.out.println("Buffer string to be skipped = " + new String(fCurrentEntity.ch, beforeSkip, length));
}
//s.charAt() indexes are 0 to 'Length -1' based.
int i = length - 1 ;
//check from reverse
while(s.charAt(i--) == fCurrentEntity.ch[afterSkip]){
if(afterSkip-- == beforeSkip){
fCurrentEntity.position = fCurrentEntity.position + length ;
fCurrentEntity.columnNumber += length;
return true;
}
}
}
return false;
| public boolean | skipString(char[] s)
final int length = s.length;
//first make sure that required capacity is avaible
if(arrangeCapacity(length, false)){
int beforeSkip = fCurrentEntity.position ;
int afterSkip = fCurrentEntity.position + length ;
if(DEBUG_SKIP_STRING){
System.out.println("skipString,length = " + new String(s) + "," + length);
System.out.println("skipString,length = " + new String(s) + "," + length);
}
for(int i=0;i<length;i++){
if(!(fCurrentEntity.ch[beforeSkip++]==s[i])){
return false;
}
}
fCurrentEntity.position = fCurrentEntity.position + length ;
fCurrentEntity.columnNumber += length;
return true;
}
return false;
|
|