diff -r f4b2aa462b46 -r f2634f2bc36c jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java --- a/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java Mon Dec 23 14:07:05 2013 -0800 +++ b/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java Sun Jan 05 21:00:00 2014 -0800 @@ -20,34 +20,28 @@ package com.sun.org.apache.xerces.internal.impl; -import java.io.EOFException; -import java.io.IOException; -import java.util.Locale; -import java.util.Vector; - -import com.sun.xml.internal.stream.Entity; -import com.sun.xml.internal.stream.XMLBufferListener; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; import com.sun.org.apache.xerces.internal.impl.io.ASCIIReader; import com.sun.org.apache.xerces.internal.impl.io.UCSReader; import com.sun.org.apache.xerces.internal.impl.io.UTF8Reader; - - import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; import com.sun.org.apache.xerces.internal.util.EncodingMap; - import com.sun.org.apache.xerces.internal.util.SymbolTable; import com.sun.org.apache.xerces.internal.util.XMLChar; import com.sun.org.apache.xerces.internal.util.XMLStringBuffer; -import com.sun.org.apache.xerces.internal.xni.QName; -import com.sun.org.apache.xerces.internal.xni.XMLString; +import com.sun.org.apache.xerces.internal.xni.*; import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; -import com.sun.org.apache.xerces.internal.xni.*; +import com.sun.xml.internal.stream.Entity; +import com.sun.xml.internal.stream.XMLBufferListener; +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.Locale; +import java.util.Vector; /** * Implements the entity scanner methods. @@ -493,8 +487,7 @@ // load more characters, if needed if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(0); - load(0, true); + load(0, true, true); } // peek at character @@ -535,8 +528,7 @@ // load more characters, if needed if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(0); - load(0, true); + load(0, true, true); } // scan character @@ -546,9 +538,8 @@ fCurrentEntity.lineNumber++; fCurrentEntity.columnNumber = 1; if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(1); fCurrentEntity.ch[0] = (char)c; - load(1, false); + load(1, false, true); } if (c == '\r' && isExternal) { if (fCurrentEntity.ch[fCurrentEntity.position++] != '\n') { @@ -593,8 +584,7 @@ // load more characters, if needed if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(0); - load(0, true); + load(0, true, true); } // scan nmtoken @@ -626,7 +616,7 @@ fCurrentEntity.ch, 0, length); } offset = 0; - if (load(length, false)) { + if (load(length, false, false)) { break; } } @@ -673,18 +663,16 @@ // load more characters, if needed if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(0); - load(0, true); + load(0, true, 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)) { + if (load(1, false, true)) { fCurrentEntity.columnNumber++; String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1); @@ -721,7 +709,7 @@ fCurrentEntity.ch, 0, length); } offset = 0; - if (load(length, false)) { + if (load(length, false, false)) { break; } } @@ -776,8 +764,7 @@ // load more characters, if needed if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(0); - load(0, true); + load(0, true, true); } // scan qualified name @@ -789,11 +776,10 @@ 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)) { + if (load(1, false, true)) { fCurrentEntity.columnNumber++; //adding into symbol table. //XXX We are trying to add single character in SymbolTable?????? @@ -843,7 +829,7 @@ index = index - offset; } offset = 0; - if (load(length, false)) { + if (load(length, false, false)) { break; } } @@ -918,12 +904,10 @@ // load more characters, if needed if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(0); - load(0, true); + load(0, true, true); } else if (fCurrentEntity.position == fCurrentEntity.count - 1) { - invokeListeners(0); fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1]; - load(1, false); + load(1, false, true); fCurrentEntity.position = 0; } @@ -945,9 +929,8 @@ fCurrentEntity.columnNumber = 1; if (fCurrentEntity.position == fCurrentEntity.count) { offset = 0; - invokeListeners(newlines); fCurrentEntity.position = newlines; - if (load(newlines, false)) { + if (load(newlines, false, true)) { break; } } @@ -965,9 +948,8 @@ fCurrentEntity.columnNumber = 1; if (fCurrentEntity.position == fCurrentEntity.count) { offset = 0; - invokeListeners(newlines); fCurrentEntity.position = newlines; - if (load(newlines, false)) { + if (load(newlines, false, true)) { break; } } @@ -1070,13 +1052,10 @@ } // load more characters, if needed if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(0); - load(0, true); + load(0, true, true); } else if (fCurrentEntity.position == fCurrentEntity.count - 1) { - invokeListeners(0); fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1]; - - load(1, false); + load(1, false, true); fCurrentEntity.position = 0; } @@ -1099,10 +1078,9 @@ fCurrentEntity.lineNumber++; fCurrentEntity.columnNumber = 1; if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(newlines); offset = 0; fCurrentEntity.position = newlines; - if (load(newlines, false)) { + if (load(newlines, false, true)) { break; } } @@ -1121,9 +1099,8 @@ fCurrentEntity.columnNumber = 1; if (fCurrentEntity.position == fCurrentEntity.count) { offset = 0; - invokeListeners(newlines); fCurrentEntity.position = newlines; - if (load(newlines, false)) { + if (load(newlines, false, true)) { break; } } @@ -1174,7 +1151,6 @@ storeWhiteSpace(fCurrentEntity.position); } } - int length = fCurrentEntity.position - offset; fCurrentEntity.columnNumber += length - newlines; content.setValues(fCurrentEntity.ch, offset, length); @@ -1258,7 +1234,7 @@ // load more characters, if needed if (fCurrentEntity.position == fCurrentEntity.count) { - load(0, true); + load(0, true, false); } boolean bNextEntity = false; @@ -1272,7 +1248,7 @@ 0, fCurrentEntity.count - fCurrentEntity.position); - bNextEntity = load(fCurrentEntity.count - fCurrentEntity.position, false); + bNextEntity = load(fCurrentEntity.count - fCurrentEntity.position, false, false); fCurrentEntity.position = 0; fCurrentEntity.startPosition = 0; } @@ -1285,7 +1261,7 @@ fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition); fCurrentEntity.position = fCurrentEntity.count; fCurrentEntity.startPosition = fCurrentEntity.count; - load(0, true); + load(0, true, false); return false; } @@ -1307,9 +1283,8 @@ fCurrentEntity.columnNumber = 1; if (fCurrentEntity.position == fCurrentEntity.count) { offset = 0; - invokeListeners(newlines); fCurrentEntity.position = newlines; - if (load(newlines, false)) { + if (load(newlines, false, true)) { break; } } @@ -1327,10 +1302,9 @@ fCurrentEntity.columnNumber = 1; if (fCurrentEntity.position == fCurrentEntity.count) { offset = 0; - invokeListeners(newlines); fCurrentEntity.position = newlines; fCurrentEntity.count = newlines; - if (load(newlines, false)) { + if (load(newlines, false, true)) { break; } } @@ -1431,8 +1405,7 @@ // load more characters, if needed if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(0); - load(0, true); + load(0, true, true); } // skip character @@ -1454,9 +1427,8 @@ } else if (c == '\n' && cc == '\r' && isExternal) { // handle newlines if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(1); fCurrentEntity.ch[0] = (char)cc; - load(1, false); + load(1, false, true); } fCurrentEntity.position++; if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') { @@ -1507,8 +1479,7 @@ //boolean entityChanged = false; // load more characters, if needed if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(0); - load(0, true); + load(0, true, true); } //we are doing this check only in skipSpace() because it is called by @@ -1531,9 +1502,8 @@ fCurrentEntity.lineNumber++; fCurrentEntity.columnNumber = 1; if (fCurrentEntity.position == fCurrentEntity.count - 1) { - invokeListeners(0); fCurrentEntity.ch[0] = (char)c; - entityChanged = load(1, true); + entityChanged = load(1, true, true); if (!entityChanged){ // the load change the position to be 1, // need to restore it when entity not changed @@ -1558,8 +1528,7 @@ } if (fCurrentEntity.position == fCurrentEntity.count) { - invokeListeners(0); - load(0, true); + load(0, true, 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 @@ -1635,7 +1604,7 @@ if((fCurrentEntity.count - fCurrentEntity.position) < length){ int pos = fCurrentEntity.position; invokeListeners(pos); - entityChanged = load(fCurrentEntity.count, changeEntity); + entityChanged = load(fCurrentEntity.count, changeEntity, false); fCurrentEntity.position = pos; if(entityChanged)break; } @@ -1740,17 +1709,22 @@ * the current entity in place and the entity * boundary will be signaled by the return * value. + * @param notify Determine whether to notify listeners of + * the event * * @returns Returns true if the entity changed as a result of this * load operation. */ - final boolean load(int offset, boolean changeEntity) + final boolean load(int offset, boolean changeEntity, boolean notify) throws IOException { if (DEBUG_BUFFER) { System.out.print("(load, "+offset+": "); print(); System.out.println(); } + if (notify) { + invokeListeners(offset); + } //maintaing the count till last load fCurrentEntity.fTotalCountTillLastLoad = fCurrentEntity.fTotalCountTillLastLoad + fCurrentEntity.fLastCount ; // read characters @@ -1787,7 +1761,7 @@ } // handle the trailing edges if (fCurrentEntity.position == fCurrentEntity.count) { - load(0, true); + load(0, true, false); } } @@ -2084,7 +2058,7 @@ * * @param loadPos Starting position from which new data is being loaded into scanner buffer. */ - private void invokeListeners(int loadPos){ + public void invokeListeners(int loadPos){ for(int i=0;i