jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java
changeset 22140 f2634f2bc36c
parent 22138 069c98fc4646
equal deleted inserted replaced
22139:f4b2aa462b46 22140:f2634f2bc36c
    18  * limitations under the License.
    18  * limitations under the License.
    19  */
    19  */
    20 
    20 
    21 package com.sun.org.apache.xerces.internal.impl;
    21 package com.sun.org.apache.xerces.internal.impl;
    22 
    22 
       
    23 
       
    24 
       
    25 import com.sun.org.apache.xerces.internal.impl.io.ASCIIReader;
       
    26 import com.sun.org.apache.xerces.internal.impl.io.UCSReader;
       
    27 import com.sun.org.apache.xerces.internal.impl.io.UTF8Reader;
       
    28 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
       
    29 import com.sun.org.apache.xerces.internal.util.EncodingMap;
       
    30 import com.sun.org.apache.xerces.internal.util.SymbolTable;
       
    31 import com.sun.org.apache.xerces.internal.util.XMLChar;
       
    32 import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
       
    33 import com.sun.org.apache.xerces.internal.xni.*;
       
    34 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
       
    35 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
       
    36 import com.sun.xml.internal.stream.Entity;
       
    37 import com.sun.xml.internal.stream.XMLBufferListener;
    23 import java.io.EOFException;
    38 import java.io.EOFException;
    24 import java.io.IOException;
    39 import java.io.IOException;
    25 import java.util.Locale;
       
    26 import java.util.Vector;
       
    27 
       
    28 import com.sun.xml.internal.stream.Entity;
       
    29 import com.sun.xml.internal.stream.XMLBufferListener;
       
    30 import java.io.InputStream;
    40 import java.io.InputStream;
    31 import java.io.InputStreamReader;
    41 import java.io.InputStreamReader;
    32 import java.io.Reader;
    42 import java.io.Reader;
    33 
    43 import java.util.Locale;
    34 
    44 import java.util.Vector;
    35 import com.sun.org.apache.xerces.internal.impl.io.ASCIIReader;
       
    36 import com.sun.org.apache.xerces.internal.impl.io.UCSReader;
       
    37 import com.sun.org.apache.xerces.internal.impl.io.UTF8Reader;
       
    38 
       
    39 
       
    40 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
       
    41 import com.sun.org.apache.xerces.internal.util.EncodingMap;
       
    42 
       
    43 import com.sun.org.apache.xerces.internal.util.SymbolTable;
       
    44 import com.sun.org.apache.xerces.internal.util.XMLChar;
       
    45 import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
       
    46 import com.sun.org.apache.xerces.internal.xni.QName;
       
    47 import com.sun.org.apache.xerces.internal.xni.XMLString;
       
    48 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
       
    49 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
       
    50 import com.sun.org.apache.xerces.internal.xni.*;
       
    51 
    45 
    52 /**
    46 /**
    53  * Implements the entity scanner methods.
    47  * Implements the entity scanner methods.
    54  *
    48  *
    55  * @author Neeraj Bajaj, Sun Microsystems
    49  * @author Neeraj Bajaj, Sun Microsystems
   491             System.out.println();
   485             System.out.println();
   492         }
   486         }
   493 
   487 
   494         // load more characters, if needed
   488         // load more characters, if needed
   495         if (fCurrentEntity.position == fCurrentEntity.count) {
   489         if (fCurrentEntity.position == fCurrentEntity.count) {
   496             invokeListeners(0);
   490             load(0, true, true);
   497             load(0, true);
       
   498         }
   491         }
   499 
   492 
   500         // peek at character
   493         // peek at character
   501         int c = fCurrentEntity.ch[fCurrentEntity.position];
   494         int c = fCurrentEntity.ch[fCurrentEntity.position];
   502 
   495 
   533             System.out.println();
   526             System.out.println();
   534         }
   527         }
   535 
   528 
   536         // load more characters, if needed
   529         // load more characters, if needed
   537         if (fCurrentEntity.position == fCurrentEntity.count) {
   530         if (fCurrentEntity.position == fCurrentEntity.count) {
   538             invokeListeners(0);
   531             load(0, true, true);
   539             load(0, true);
       
   540         }
   532         }
   541 
   533 
   542         // scan character
   534         // scan character
   543         int c = fCurrentEntity.ch[fCurrentEntity.position++];
   535         int c = fCurrentEntity.ch[fCurrentEntity.position++];
   544         if (c == '\n' ||
   536         if (c == '\n' ||
   545                 (c == '\r' && isExternal)) {
   537                 (c == '\r' && isExternal)) {
   546             fCurrentEntity.lineNumber++;
   538             fCurrentEntity.lineNumber++;
   547             fCurrentEntity.columnNumber = 1;
   539             fCurrentEntity.columnNumber = 1;
   548             if (fCurrentEntity.position == fCurrentEntity.count) {
   540             if (fCurrentEntity.position == fCurrentEntity.count) {
   549                 invokeListeners(1);
       
   550                 fCurrentEntity.ch[0] = (char)c;
   541                 fCurrentEntity.ch[0] = (char)c;
   551                 load(1, false);
   542                 load(1, false, true);
   552             }
   543             }
   553             if (c == '\r' && isExternal) {
   544             if (c == '\r' && isExternal) {
   554                 if (fCurrentEntity.ch[fCurrentEntity.position++] != '\n') {
   545                 if (fCurrentEntity.ch[fCurrentEntity.position++] != '\n') {
   555                     fCurrentEntity.position--;
   546                     fCurrentEntity.position--;
   556                 }
   547                 }
   591             System.out.println();
   582             System.out.println();
   592         }
   583         }
   593 
   584 
   594         // load more characters, if needed
   585         // load more characters, if needed
   595         if (fCurrentEntity.position == fCurrentEntity.count) {
   586         if (fCurrentEntity.position == fCurrentEntity.count) {
   596             invokeListeners(0);
   587             load(0, true, true);
   597             load(0, true);
       
   598         }
   588         }
   599 
   589 
   600         // scan nmtoken
   590         // scan nmtoken
   601         int offset = fCurrentEntity.position;
   591         int offset = fCurrentEntity.position;
   602         boolean vc = false;
   592         boolean vc = false;
   624                 } else {
   614                 } else {
   625                     System.arraycopy(fCurrentEntity.ch, offset,
   615                     System.arraycopy(fCurrentEntity.ch, offset,
   626                             fCurrentEntity.ch, 0, length);
   616                             fCurrentEntity.ch, 0, length);
   627                 }
   617                 }
   628                 offset = 0;
   618                 offset = 0;
   629                 if (load(length, false)) {
   619                 if (load(length, false, false)) {
   630                     break;
   620                     break;
   631                 }
   621                 }
   632             }
   622             }
   633         }
   623         }
   634         int length = fCurrentEntity.position - offset;
   624         int length = fCurrentEntity.position - offset;
   671             System.out.println();
   661             System.out.println();
   672         }
   662         }
   673 
   663 
   674         // load more characters, if needed
   664         // load more characters, if needed
   675         if (fCurrentEntity.position == fCurrentEntity.count) {
   665         if (fCurrentEntity.position == fCurrentEntity.count) {
   676             invokeListeners(0);
   666             load(0, true, true);
   677             load(0, true);
       
   678         }
   667         }
   679 
   668 
   680         // scan name
   669         // scan name
   681         int offset = fCurrentEntity.position;
   670         int offset = fCurrentEntity.position;
   682         if (XMLChar.isNameStart(fCurrentEntity.ch[offset])) {
   671         if (XMLChar.isNameStart(fCurrentEntity.ch[offset])) {
   683             if (++fCurrentEntity.position == fCurrentEntity.count) {
   672             if (++fCurrentEntity.position == fCurrentEntity.count) {
   684                 invokeListeners(1);
       
   685                 fCurrentEntity.ch[0] = fCurrentEntity.ch[offset];
   673                 fCurrentEntity.ch[0] = fCurrentEntity.ch[offset];
   686                 offset = 0;
   674                 offset = 0;
   687                 if (load(1, false)) {
   675                 if (load(1, false, true)) {
   688                     fCurrentEntity.columnNumber++;
   676                     fCurrentEntity.columnNumber++;
   689                     String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
   677                     String symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
   690 
   678 
   691                     if (DEBUG_BUFFER) {
   679                     if (DEBUG_BUFFER) {
   692                         System.out.print(")scanName: ");
   680                         System.out.print(")scanName: ");
   719                     } else {
   707                     } else {
   720                         System.arraycopy(fCurrentEntity.ch, offset,
   708                         System.arraycopy(fCurrentEntity.ch, offset,
   721                                 fCurrentEntity.ch, 0, length);
   709                                 fCurrentEntity.ch, 0, length);
   722                     }
   710                     }
   723                     offset = 0;
   711                     offset = 0;
   724                     if (load(length, false)) {
   712                     if (load(length, false, false)) {
   725                         break;
   713                         break;
   726                     }
   714                     }
   727                 }
   715                 }
   728             }
   716             }
   729         }
   717         }
   774             System.out.println();
   762             System.out.println();
   775         }
   763         }
   776 
   764 
   777         // load more characters, if needed
   765         // load more characters, if needed
   778         if (fCurrentEntity.position == fCurrentEntity.count) {
   766         if (fCurrentEntity.position == fCurrentEntity.count) {
   779             invokeListeners(0);
   767             load(0, true, true);
   780             load(0, true);
       
   781         }
   768         }
   782 
   769 
   783         // scan qualified name
   770         // scan qualified name
   784         int offset = fCurrentEntity.position;
   771         int offset = fCurrentEntity.position;
   785 
   772 
   787         //as defined by production [5] in the XML 1.0 specification.
   774         //as defined by production [5] in the XML 1.0 specification.
   788         // Name ::= (Letter | '_' | ':') (NameChar)*
   775         // Name ::= (Letter | '_' | ':') (NameChar)*
   789 
   776 
   790         if (XMLChar.isNameStart(fCurrentEntity.ch[offset])) {
   777         if (XMLChar.isNameStart(fCurrentEntity.ch[offset])) {
   791             if (++fCurrentEntity.position == fCurrentEntity.count) {
   778             if (++fCurrentEntity.position == fCurrentEntity.count) {
   792                 invokeListeners(1);
       
   793                 fCurrentEntity.ch[0] = fCurrentEntity.ch[offset];
   779                 fCurrentEntity.ch[0] = fCurrentEntity.ch[offset];
   794                 offset = 0;
   780                 offset = 0;
   795 
   781 
   796                 if (load(1, false)) {
   782                 if (load(1, false, true)) {
   797                     fCurrentEntity.columnNumber++;
   783                     fCurrentEntity.columnNumber++;
   798                     //adding into symbol table.
   784                     //adding into symbol table.
   799                     //XXX We are trying to add single character in SymbolTable??????
   785                     //XXX We are trying to add single character in SymbolTable??????
   800                     String name = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
   786                     String name = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
   801                     qname.setValues(null, name, name, null);
   787                     qname.setValues(null, name, name, null);
   841                     }
   827                     }
   842                     if (index != -1) {
   828                     if (index != -1) {
   843                         index = index - offset;
   829                         index = index - offset;
   844                     }
   830                     }
   845                     offset = 0;
   831                     offset = 0;
   846                     if (load(length, false)) {
   832                     if (load(length, false, false)) {
   847                         break;
   833                         break;
   848                     }
   834                     }
   849                 }
   835                 }
   850             }
   836             }
   851             int length = fCurrentEntity.position - offset;
   837             int length = fCurrentEntity.position - offset;
   916             System.out.println();
   902             System.out.println();
   917         }
   903         }
   918 
   904 
   919         // load more characters, if needed
   905         // load more characters, if needed
   920         if (fCurrentEntity.position == fCurrentEntity.count) {
   906         if (fCurrentEntity.position == fCurrentEntity.count) {
   921             invokeListeners(0);
   907             load(0, true, true);
   922             load(0, true);
       
   923         } else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
   908         } else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
   924             invokeListeners(0);
       
   925             fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
   909             fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
   926             load(1, false);
   910             load(1, false, true);
   927             fCurrentEntity.position = 0;
   911             fCurrentEntity.position = 0;
   928         }
   912         }
   929 
   913 
   930         // normalize newlines
   914         // normalize newlines
   931         int offset = fCurrentEntity.position;
   915         int offset = fCurrentEntity.position;
   943                     newlines++;
   927                     newlines++;
   944                     fCurrentEntity.lineNumber++;
   928                     fCurrentEntity.lineNumber++;
   945                     fCurrentEntity.columnNumber = 1;
   929                     fCurrentEntity.columnNumber = 1;
   946                     if (fCurrentEntity.position == fCurrentEntity.count) {
   930                     if (fCurrentEntity.position == fCurrentEntity.count) {
   947                         offset = 0;
   931                         offset = 0;
   948                         invokeListeners(newlines);
       
   949                         fCurrentEntity.position = newlines;
   932                         fCurrentEntity.position = newlines;
   950                         if (load(newlines, false)) {
   933                         if (load(newlines, false, true)) {
   951                             break;
   934                             break;
   952                         }
   935                         }
   953                     }
   936                     }
   954                     if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') {
   937                     if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') {
   955                         fCurrentEntity.position++;
   938                         fCurrentEntity.position++;
   963                     newlines++;
   946                     newlines++;
   964                     fCurrentEntity.lineNumber++;
   947                     fCurrentEntity.lineNumber++;
   965                     fCurrentEntity.columnNumber = 1;
   948                     fCurrentEntity.columnNumber = 1;
   966                     if (fCurrentEntity.position == fCurrentEntity.count) {
   949                     if (fCurrentEntity.position == fCurrentEntity.count) {
   967                         offset = 0;
   950                         offset = 0;
   968                         invokeListeners(newlines);
       
   969                         fCurrentEntity.position = newlines;
   951                         fCurrentEntity.position = newlines;
   970                         if (load(newlines, false)) {
   952                         if (load(newlines, false, true)) {
   971                             break;
   953                             break;
   972                         }
   954                         }
   973                     }
   955                     }
   974                 } else {
   956                 } else {
   975                     fCurrentEntity.position--;
   957                     fCurrentEntity.position--;
  1068             print();
  1050             print();
  1069             System.out.println();
  1051             System.out.println();
  1070         }
  1052         }
  1071         // load more characters, if needed
  1053         // load more characters, if needed
  1072         if (fCurrentEntity.position == fCurrentEntity.count) {
  1054         if (fCurrentEntity.position == fCurrentEntity.count) {
  1073             invokeListeners(0);
  1055             load(0, true, true);
  1074             load(0, true);
       
  1075         } else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
  1056         } else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
  1076             invokeListeners(0);
       
  1077             fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
  1057             fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
  1078 
  1058             load(1, false, true);
  1079             load(1, false);
       
  1080             fCurrentEntity.position = 0;
  1059             fCurrentEntity.position = 0;
  1081         }
  1060         }
  1082 
  1061 
  1083         // normalize newlines
  1062         // normalize newlines
  1084         int offset = fCurrentEntity.position;
  1063         int offset = fCurrentEntity.position;
  1097                 if (c == '\r' && isExternal) {
  1076                 if (c == '\r' && isExternal) {
  1098                     newlines++;
  1077                     newlines++;
  1099                     fCurrentEntity.lineNumber++;
  1078                     fCurrentEntity.lineNumber++;
  1100                     fCurrentEntity.columnNumber = 1;
  1079                     fCurrentEntity.columnNumber = 1;
  1101                     if (fCurrentEntity.position == fCurrentEntity.count) {
  1080                     if (fCurrentEntity.position == fCurrentEntity.count) {
  1102                         invokeListeners(newlines);
       
  1103                         offset = 0;
  1081                         offset = 0;
  1104                         fCurrentEntity.position = newlines;
  1082                         fCurrentEntity.position = newlines;
  1105                         if (load(newlines, false)) {
  1083                         if (load(newlines, false, true)) {
  1106                             break;
  1084                             break;
  1107                         }
  1085                         }
  1108                     }
  1086                     }
  1109                     if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') {
  1087                     if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') {
  1110                         fCurrentEntity.position++;
  1088                         fCurrentEntity.position++;
  1119                     newlines++;
  1097                     newlines++;
  1120                     fCurrentEntity.lineNumber++;
  1098                     fCurrentEntity.lineNumber++;
  1121                     fCurrentEntity.columnNumber = 1;
  1099                     fCurrentEntity.columnNumber = 1;
  1122                     if (fCurrentEntity.position == fCurrentEntity.count) {
  1100                     if (fCurrentEntity.position == fCurrentEntity.count) {
  1123                         offset = 0;
  1101                         offset = 0;
  1124                         invokeListeners(newlines);
       
  1125                         fCurrentEntity.position = newlines;
  1102                         fCurrentEntity.position = newlines;
  1126                         if (load(newlines, false)) {
  1103                         if (load(newlines, false, true)) {
  1127                             break;
  1104                             break;
  1128                         }
  1105                         }
  1129                     }
  1106                     }
  1130                     /*** NEWLINE NORMALIZATION ***
  1107                     /*** NEWLINE NORMALIZATION ***
  1131                      * if (fCurrentEntity.ch[fCurrentEntity.position] == '\r'
  1108                      * if (fCurrentEntity.ch[fCurrentEntity.position] == '\r'
  1172             }
  1149             }
  1173             if (whiteSpaceInfoNeeded && c == '\t') {
  1150             if (whiteSpaceInfoNeeded && c == '\t') {
  1174                 storeWhiteSpace(fCurrentEntity.position);
  1151                 storeWhiteSpace(fCurrentEntity.position);
  1175             }
  1152             }
  1176         }
  1153         }
  1177 
       
  1178         int length = fCurrentEntity.position - offset;
  1154         int length = fCurrentEntity.position - offset;
  1179         fCurrentEntity.columnNumber += length - newlines;
  1155         fCurrentEntity.columnNumber += length - newlines;
  1180         content.setValues(fCurrentEntity.ch, offset, length);
  1156         content.setValues(fCurrentEntity.ch, offset, length);
  1181 
  1157 
  1182         // return next character
  1158         // return next character
  1256             }
  1232             }
  1257 
  1233 
  1258             // load more characters, if needed
  1234             // load more characters, if needed
  1259 
  1235 
  1260             if (fCurrentEntity.position == fCurrentEntity.count) {
  1236             if (fCurrentEntity.position == fCurrentEntity.count) {
  1261                 load(0, true);
  1237                 load(0, true, false);
  1262             }
  1238             }
  1263 
  1239 
  1264             boolean bNextEntity = false;
  1240             boolean bNextEntity = false;
  1265 
  1241 
  1266             while ((fCurrentEntity.position > fCurrentEntity.count - delimLen)
  1242             while ((fCurrentEntity.position > fCurrentEntity.count - delimLen)
  1270                                fCurrentEntity.position,
  1246                                fCurrentEntity.position,
  1271                                fCurrentEntity.ch,
  1247                                fCurrentEntity.ch,
  1272                                0,
  1248                                0,
  1273                                fCurrentEntity.count - fCurrentEntity.position);
  1249                                fCurrentEntity.count - fCurrentEntity.position);
  1274 
  1250 
  1275               bNextEntity = load(fCurrentEntity.count - fCurrentEntity.position, false);
  1251               bNextEntity = load(fCurrentEntity.count - fCurrentEntity.position, false, false);
  1276               fCurrentEntity.position = 0;
  1252               fCurrentEntity.position = 0;
  1277               fCurrentEntity.startPosition = 0;
  1253               fCurrentEntity.startPosition = 0;
  1278             }
  1254             }
  1279 
  1255 
  1280             if (fCurrentEntity.position > fCurrentEntity.count - delimLen) {
  1256             if (fCurrentEntity.position > fCurrentEntity.count - delimLen) {
  1283                 buffer.append (fCurrentEntity.ch, fCurrentEntity.position, length);
  1259                 buffer.append (fCurrentEntity.ch, fCurrentEntity.position, length);
  1284                 fCurrentEntity.columnNumber += fCurrentEntity.count;
  1260                 fCurrentEntity.columnNumber += fCurrentEntity.count;
  1285                 fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
  1261                 fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
  1286                 fCurrentEntity.position = fCurrentEntity.count;
  1262                 fCurrentEntity.position = fCurrentEntity.count;
  1287                 fCurrentEntity.startPosition = fCurrentEntity.count;
  1263                 fCurrentEntity.startPosition = fCurrentEntity.count;
  1288                 load(0, true);
  1264                 load(0, true, false);
  1289                 return false;
  1265                 return false;
  1290             }
  1266             }
  1291 
  1267 
  1292             // normalize newlines
  1268             // normalize newlines
  1293             int offset = fCurrentEntity.position;
  1269             int offset = fCurrentEntity.position;
  1305                         newlines++;
  1281                         newlines++;
  1306                         fCurrentEntity.lineNumber++;
  1282                         fCurrentEntity.lineNumber++;
  1307                         fCurrentEntity.columnNumber = 1;
  1283                         fCurrentEntity.columnNumber = 1;
  1308                         if (fCurrentEntity.position == fCurrentEntity.count) {
  1284                         if (fCurrentEntity.position == fCurrentEntity.count) {
  1309                             offset = 0;
  1285                             offset = 0;
  1310                             invokeListeners(newlines);
       
  1311                             fCurrentEntity.position = newlines;
  1286                             fCurrentEntity.position = newlines;
  1312                             if (load(newlines, false)) {
  1287                             if (load(newlines, false, true)) {
  1313                                 break;
  1288                                 break;
  1314                             }
  1289                             }
  1315                         }
  1290                         }
  1316                         if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') {
  1291                         if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') {
  1317                             fCurrentEntity.position++;
  1292                             fCurrentEntity.position++;
  1325                         newlines++;
  1300                         newlines++;
  1326                         fCurrentEntity.lineNumber++;
  1301                         fCurrentEntity.lineNumber++;
  1327                         fCurrentEntity.columnNumber = 1;
  1302                         fCurrentEntity.columnNumber = 1;
  1328                         if (fCurrentEntity.position == fCurrentEntity.count) {
  1303                         if (fCurrentEntity.position == fCurrentEntity.count) {
  1329                             offset = 0;
  1304                             offset = 0;
  1330                             invokeListeners(newlines);
       
  1331                             fCurrentEntity.position = newlines;
  1305                             fCurrentEntity.position = newlines;
  1332                             fCurrentEntity.count = newlines;
  1306                             fCurrentEntity.count = newlines;
  1333                             if (load(newlines, false)) {
  1307                             if (load(newlines, false, true)) {
  1334                                 break;
  1308                                 break;
  1335                             }
  1309                             }
  1336                         }
  1310                         }
  1337                     } else {
  1311                     } else {
  1338                         fCurrentEntity.position--;
  1312                         fCurrentEntity.position--;
  1429             System.out.println();
  1403             System.out.println();
  1430         }
  1404         }
  1431 
  1405 
  1432         // load more characters, if needed
  1406         // load more characters, if needed
  1433         if (fCurrentEntity.position == fCurrentEntity.count) {
  1407         if (fCurrentEntity.position == fCurrentEntity.count) {
  1434             invokeListeners(0);
  1408             load(0, true, true);
  1435             load(0, true);
       
  1436         }
  1409         }
  1437 
  1410 
  1438         // skip character
  1411         // skip character
  1439         int cc = fCurrentEntity.ch[fCurrentEntity.position];
  1412         int cc = fCurrentEntity.ch[fCurrentEntity.position];
  1440         if (cc == c) {
  1413         if (cc == c) {
  1452             }
  1425             }
  1453             return true;
  1426             return true;
  1454         } else if (c == '\n' && cc == '\r' && isExternal) {
  1427         } else if (c == '\n' && cc == '\r' && isExternal) {
  1455             // handle newlines
  1428             // handle newlines
  1456             if (fCurrentEntity.position == fCurrentEntity.count) {
  1429             if (fCurrentEntity.position == fCurrentEntity.count) {
  1457                 invokeListeners(1);
       
  1458                 fCurrentEntity.ch[0] = (char)cc;
  1430                 fCurrentEntity.ch[0] = (char)cc;
  1459                 load(1, false);
  1431                 load(1, false, true);
  1460             }
  1432             }
  1461             fCurrentEntity.position++;
  1433             fCurrentEntity.position++;
  1462             if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') {
  1434             if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') {
  1463                 fCurrentEntity.position++;
  1435                 fCurrentEntity.position++;
  1464             }
  1436             }
  1505             System.out.println();
  1477             System.out.println();
  1506         }
  1478         }
  1507         //boolean entityChanged = false;
  1479         //boolean entityChanged = false;
  1508         // load more characters, if needed
  1480         // load more characters, if needed
  1509         if (fCurrentEntity.position == fCurrentEntity.count) {
  1481         if (fCurrentEntity.position == fCurrentEntity.count) {
  1510             invokeListeners(0);
  1482             load(0, true, true);
  1511             load(0, true);
       
  1512         }
  1483         }
  1513 
  1484 
  1514         //we are doing this check only in skipSpace() because it is called by
  1485         //we are doing this check only in skipSpace() because it is called by
  1515         //fMiscDispatcher and we want the parser to exit gracefully when document
  1486         //fMiscDispatcher and we want the parser to exit gracefully when document
  1516         //is well-formed.
  1487         //is well-formed.
  1529                 // handle newlines
  1500                 // handle newlines
  1530                 if (c == '\n' || (isExternal && c == '\r')) {
  1501                 if (c == '\n' || (isExternal && c == '\r')) {
  1531                     fCurrentEntity.lineNumber++;
  1502                     fCurrentEntity.lineNumber++;
  1532                     fCurrentEntity.columnNumber = 1;
  1503                     fCurrentEntity.columnNumber = 1;
  1533                     if (fCurrentEntity.position == fCurrentEntity.count - 1) {
  1504                     if (fCurrentEntity.position == fCurrentEntity.count - 1) {
  1534                         invokeListeners(0);
       
  1535                         fCurrentEntity.ch[0] = (char)c;
  1505                         fCurrentEntity.ch[0] = (char)c;
  1536                         entityChanged = load(1, true);
  1506                         entityChanged = load(1, true, true);
  1537                         if (!entityChanged){
  1507                         if (!entityChanged){
  1538                             // the load change the position to be 1,
  1508                             // the load change the position to be 1,
  1539                             // need to restore it when entity not changed
  1509                             // need to restore it when entity not changed
  1540                             fCurrentEntity.position = 0;
  1510                             fCurrentEntity.position = 0;
  1541                         }else if(fCurrentEntity == null){
  1511                         }else if(fCurrentEntity == null){
  1556                 if (!entityChanged){
  1526                 if (!entityChanged){
  1557                     fCurrentEntity.position++;
  1527                     fCurrentEntity.position++;
  1558                 }
  1528                 }
  1559 
  1529 
  1560                 if (fCurrentEntity.position == fCurrentEntity.count) {
  1530                 if (fCurrentEntity.position == fCurrentEntity.count) {
  1561                     invokeListeners(0);
  1531                     load(0, true, true);
  1562                     load(0, true);
       
  1563 
  1532 
  1564                     //we are doing this check only in skipSpace() because it is called by
  1533                     //we are doing this check only in skipSpace() because it is called by
  1565                     //fMiscDispatcher and we want the parser to exit gracefully when document
  1534                     //fMiscDispatcher and we want the parser to exit gracefully when document
  1566                     //is well-formed.
  1535                     //is well-formed.
  1567 
  1536 
  1633             }
  1602             }
  1634 
  1603 
  1635             if((fCurrentEntity.count - fCurrentEntity.position) < length){
  1604             if((fCurrentEntity.count - fCurrentEntity.position) < length){
  1636                 int pos = fCurrentEntity.position;
  1605                 int pos = fCurrentEntity.position;
  1637                 invokeListeners(pos);
  1606                 invokeListeners(pos);
  1638                 entityChanged = load(fCurrentEntity.count, changeEntity);
  1607                 entityChanged = load(fCurrentEntity.count, changeEntity, false);
  1639                 fCurrentEntity.position = pos;
  1608                 fCurrentEntity.position = pos;
  1640                 if(entityChanged)break;
  1609                 if(entityChanged)break;
  1641             }
  1610             }
  1642             if(DEBUG_SKIP_STRING){
  1611             if(DEBUG_SKIP_STRING){
  1643                 System.out.println("fCurrentEntity.count = " + fCurrentEntity.count);
  1612                 System.out.println("fCurrentEntity.count = " + fCurrentEntity.count);
  1738      * @param changeEntity True if the load should change entities
  1707      * @param changeEntity True if the load should change entities
  1739      *                     at the end of the entity, otherwise leave
  1708      *                     at the end of the entity, otherwise leave
  1740      *                     the current entity in place and the entity
  1709      *                     the current entity in place and the entity
  1741      *                     boundary will be signaled by the return
  1710      *                     boundary will be signaled by the return
  1742      *                     value.
  1711      *                     value.
       
  1712      * @param notify       Determine whether to notify listeners of
       
  1713      *                     the event
  1743      *
  1714      *
  1744      * @returns Returns true if the entity changed as a result of this
  1715      * @returns Returns true if the entity changed as a result of this
  1745      *          load operation.
  1716      *          load operation.
  1746      */
  1717      */
  1747     final boolean load(int offset, boolean changeEntity)
  1718     final boolean load(int offset, boolean changeEntity, boolean notify)
  1748     throws IOException {
  1719     throws IOException {
  1749         if (DEBUG_BUFFER) {
  1720         if (DEBUG_BUFFER) {
  1750             System.out.print("(load, "+offset+": ");
  1721             System.out.print("(load, "+offset+": ");
  1751             print();
  1722             print();
  1752             System.out.println();
  1723             System.out.println();
       
  1724         }
       
  1725         if (notify) {
       
  1726             invokeListeners(offset);
  1753         }
  1727         }
  1754         //maintaing the count till last load
  1728         //maintaing the count till last load
  1755         fCurrentEntity.fTotalCountTillLastLoad = fCurrentEntity.fTotalCountTillLastLoad + fCurrentEntity.fLastCount ;
  1729         fCurrentEntity.fTotalCountTillLastLoad = fCurrentEntity.fTotalCountTillLastLoad + fCurrentEntity.fLastCount ;
  1756         // read characters
  1730         // read characters
  1757         int length = fCurrentEntity.ch.length - offset;
  1731         int length = fCurrentEntity.ch.length - offset;
  1785                 if(fCurrentEntity == null){
  1759                 if(fCurrentEntity == null){
  1786                     throw END_OF_DOCUMENT_ENTITY;
  1760                     throw END_OF_DOCUMENT_ENTITY;
  1787                 }
  1761                 }
  1788                 // handle the trailing edges
  1762                 // handle the trailing edges
  1789                 if (fCurrentEntity.position == fCurrentEntity.count) {
  1763                 if (fCurrentEntity.position == fCurrentEntity.count) {
  1790                     load(0, true);
  1764                     load(0, true, false);
  1791                 }
  1765                 }
  1792             }
  1766             }
  1793 
  1767 
  1794         }
  1768         }
  1795         if (DEBUG_BUFFER) {
  1769         if (DEBUG_BUFFER) {
  2082 
  2056 
  2083     /**
  2057     /**
  2084      *
  2058      *
  2085      * @param loadPos Starting position from which new data is being loaded into scanner buffer.
  2059      * @param loadPos Starting position from which new data is being loaded into scanner buffer.
  2086      */
  2060      */
  2087     private void invokeListeners(int loadPos){
  2061     public void invokeListeners(int loadPos){
  2088         for(int i=0;i<listeners.size();i++){
  2062         for(int i=0;i<listeners.size();i++){
  2089             XMLBufferListener listener =(XMLBufferListener) listeners.get(i);
  2063             XMLBufferListener listener =(XMLBufferListener) listeners.get(i);
  2090             listener.refresh(loadPos);
  2064             listener.refresh(loadPos);
  2091         }
  2065         }
  2092     }
  2066     }
  2115             System.out.println();
  2089             System.out.println();
  2116         }
  2090         }
  2117 
  2091 
  2118         // load more characters, if needed
  2092         // load more characters, if needed
  2119         if (fCurrentEntity.position == fCurrentEntity.count) {
  2093         if (fCurrentEntity.position == fCurrentEntity.count) {
  2120             load(0, true);
  2094             load(0, true, false);
  2121         }
  2095         }
  2122 
  2096 
  2123         // skip spaces
  2097         // skip spaces
  2124         int c = fCurrentEntity.ch[fCurrentEntity.position];
  2098         int c = fCurrentEntity.ch[fCurrentEntity.position];
  2125         if (XMLChar.isSpace(c)) {
  2099         if (XMLChar.isSpace(c)) {
  2130                 if (c == '\n' || (external && c == '\r')) {
  2104                 if (c == '\n' || (external && c == '\r')) {
  2131                     fCurrentEntity.lineNumber++;
  2105                     fCurrentEntity.lineNumber++;
  2132                     fCurrentEntity.columnNumber = 1;
  2106                     fCurrentEntity.columnNumber = 1;
  2133                     if (fCurrentEntity.position == fCurrentEntity.count - 1) {
  2107                     if (fCurrentEntity.position == fCurrentEntity.count - 1) {
  2134                         fCurrentEntity.ch[0] = (char)c;
  2108                         fCurrentEntity.ch[0] = (char)c;
  2135                         entityChanged = load(1, true);
  2109                         entityChanged = load(1, true, false);
  2136                         if (!entityChanged)
  2110                         if (!entityChanged)
  2137                             // the load change the position to be 1,
  2111                             // the load change the position to be 1,
  2138                             // need to restore it when entity not changed
  2112                             // need to restore it when entity not changed
  2139                             fCurrentEntity.position = 0;
  2113                             fCurrentEntity.position = 0;
  2140                     }
  2114                     }
  2158                 }
  2132                 }
  2159                 // load more characters, if needed
  2133                 // load more characters, if needed
  2160                 if (!entityChanged)
  2134                 if (!entityChanged)
  2161                     fCurrentEntity.position++;
  2135                     fCurrentEntity.position++;
  2162                 if (fCurrentEntity.position == fCurrentEntity.count) {
  2136                 if (fCurrentEntity.position == fCurrentEntity.count) {
  2163                     load(0, true);
  2137                     load(0, true, false);
  2164                 }
  2138                 }
  2165             } while (XMLChar.isSpace(c = fCurrentEntity.ch[fCurrentEntity.position]));
  2139             } while (XMLChar.isSpace(c = fCurrentEntity.ch[fCurrentEntity.position]));
  2166             if (DEBUG_BUFFER) {
  2140             if (DEBUG_BUFFER) {
  2167                 System.out.print(")skipDeclSpaces: ");
  2141                 System.out.print(")skipDeclSpaces: ");
  2168                 //  XMLEntityManager.print(fCurrentEntity);
  2142                 //  XMLEntityManager.print(fCurrentEntity);