807 else if (b4[0] == 0x3C && b4[1] == 0x00 && b4[2] == 0x3F && b4[3] == 0x00) {
808 isBigEndian = Boolean.FALSE;
809 }
810 }
811 }
812
813 reader = createReader(stream, encoding, isBigEndian);
814 }
815
816 // read one character at a time so we don't jump too far
817 // ahead, converting characters from the byte stream in
818 // the wrong encoding
819 if (DEBUG_ENCODINGS) {
820 System.out.println("$$$ no longer wrapping reader in OneCharReader");
821 }
822 //reader = new OneCharReader(reader);
823 }
824
825 // We've seen a new Reader.
826 // Push it on the stack so we can close it later.
827 //fOwnReaders.add(reader);
828
829 // push entity on stack
830 if (fCurrentEntity != null) {
831 fEntityStack.push(fCurrentEntity);
832 }
833
834 // create entity
835 /* if encoding is specified externally, 'encoding' information present
836 * in the prolog of the XML document is not considered. Hence, prolog can
837 * be read in Chunks of data instead of byte by byte.
838 */
839 fCurrentEntity = new Entity.ScannedEntity(reference, name,
840 new XMLResourceIdentifierImpl(publicId, literalSystemId, baseSystemId, expandedSystemId),
841 stream, reader, encoding, literal, encodingExternallySpecified, isExternal);
842 fCurrentEntity.setEncodingExternallySpecified(encodingExternallySpecified);
843 fEntityScanner.setCurrentEntity(fCurrentEntity);
844 fResourceIdentifier.setValues(publicId, literalSystemId, baseSystemId, expandedSystemId);
845 if (fLimitAnalyzer != null) {
846 fLimitAnalyzer.startEntity(name);
847 }
1330 } // startEntity(String,XMLInputSource)
1331
1332 /**
1333 * Return the current entity being scanned. Current entity is SET using startEntity function.
1334 * @return Entity.ScannedEntity
1335 */
1336
1337 public Entity.ScannedEntity getCurrentEntity(){
1338 return fCurrentEntity ;
1339 }
1340
1341 /**
1342 * Return the top level entity handled by this manager, or null
1343 * if no entity was added.
1344 */
1345 public Entity.ScannedEntity getTopLevelEntity() {
1346 return (Entity.ScannedEntity)
1347 (fEntityStack.empty() ? null : fEntityStack.elementAt(0));
1348 }
1349
1350
1351 /**
1352 * Close all opened InputStreams and Readers opened by this parser.
1353 */
1354 public void closeReaders() {
1355 /** this call actually does nothing, readers are closed in the endEntity method
1356 * through the current entity.
1357 * The change seems to have happened during the jdk6 development with the
1358 * addition of StAX
1359 **/
1360 }
1361
1362 public void endEntity() throws IOException, XNIException {
1363
1364 // call handler
1365 if (DEBUG_BUFFER) {
1366 System.out.print("(endEntity: ");
1367 print();
1368 System.out.println();
1369 }
1370 //pop the entity from the stack
1371 Entity.ScannedEntity entity = fEntityStack.size() > 0 ? (Entity.ScannedEntity)fEntityStack.pop() : null ;
1372
1373 /** need to close the reader first since the program can end
1374 * prematurely (e.g. fEntityHandler.endEntity may throw exception)
1375 * leaving the reader open
1376 */
1377 //close the reader
1378 if(fCurrentEntity != null){
1379 //close the reader
1380 try{
1381 if (fLimitAnalyzer != null) {
1382 fLimitAnalyzer.endEntity(XMLSecurityManager.Limit.GENERAL_ENTITY_SIZE_LIMIT, fCurrentEntity.name);
1383 if (fCurrentEntity.name.equals("[xml]")) {
1384 fSecurityManager.debugPrint(fLimitAnalyzer);
1385 }
1386 }
1387 fCurrentEntity.close();
1388 }catch(IOException ex){
1389 throw new XNIException(ex);
1390 }
1391 }
1392
1393 if (fEntityHandler != null) {
1394 //so this is the last opened entity, signal it to current fEntityHandler using Augmentation
1395 if(entity == null){
1396 fEntityAugs.removeAllItems();
1397 fEntityAugs.putItem(Constants.LAST_ENTITY, Boolean.TRUE);
1398 fEntityHandler.endEntity(fCurrentEntity.name, fEntityAugs);
1399 fEntityAugs.removeAllItems();
1400 }else{
1401 fEntityHandler.endEntity(fCurrentEntity.name, null);
1402 }
1403 }
1404 //check if it is a document entity
1405 boolean documentEntity = fCurrentEntity.name == XMLEntity;
1406
1407 //set popped entity as current entity
1408 fCurrentEntity = entity;
1409 fEntityScanner.setCurrentEntity(fCurrentEntity);
1410
|
807 else if (b4[0] == 0x3C && b4[1] == 0x00 && b4[2] == 0x3F && b4[3] == 0x00) {
808 isBigEndian = Boolean.FALSE;
809 }
810 }
811 }
812
813 reader = createReader(stream, encoding, isBigEndian);
814 }
815
816 // read one character at a time so we don't jump too far
817 // ahead, converting characters from the byte stream in
818 // the wrong encoding
819 if (DEBUG_ENCODINGS) {
820 System.out.println("$$$ no longer wrapping reader in OneCharReader");
821 }
822 //reader = new OneCharReader(reader);
823 }
824
825 // We've seen a new Reader.
826 // Push it on the stack so we can close it later.
827 fReaderStack.push(reader);
828
829 // push entity on stack
830 if (fCurrentEntity != null) {
831 fEntityStack.push(fCurrentEntity);
832 }
833
834 // create entity
835 /* if encoding is specified externally, 'encoding' information present
836 * in the prolog of the XML document is not considered. Hence, prolog can
837 * be read in Chunks of data instead of byte by byte.
838 */
839 fCurrentEntity = new Entity.ScannedEntity(reference, name,
840 new XMLResourceIdentifierImpl(publicId, literalSystemId, baseSystemId, expandedSystemId),
841 stream, reader, encoding, literal, encodingExternallySpecified, isExternal);
842 fCurrentEntity.setEncodingExternallySpecified(encodingExternallySpecified);
843 fEntityScanner.setCurrentEntity(fCurrentEntity);
844 fResourceIdentifier.setValues(publicId, literalSystemId, baseSystemId, expandedSystemId);
845 if (fLimitAnalyzer != null) {
846 fLimitAnalyzer.startEntity(name);
847 }
1330 } // startEntity(String,XMLInputSource)
1331
1332 /**
1333 * Return the current entity being scanned. Current entity is SET using startEntity function.
1334 * @return Entity.ScannedEntity
1335 */
1336
1337 public Entity.ScannedEntity getCurrentEntity(){
1338 return fCurrentEntity ;
1339 }
1340
1341 /**
1342 * Return the top level entity handled by this manager, or null
1343 * if no entity was added.
1344 */
1345 public Entity.ScannedEntity getTopLevelEntity() {
1346 return (Entity.ScannedEntity)
1347 (fEntityStack.empty() ? null : fEntityStack.elementAt(0));
1348 }
1349
1350 // A stack containing all the open readers
1351 protected Stack<Reader> fReaderStack = new Stack<>();
1352
1353 /**
1354 * Close all opened InputStreams and Readers opened by this parser.
1355 */
1356 public void closeReaders() {
1357 // close all readers
1358 while (!fReaderStack.isEmpty()) {
1359 try {
1360 (fReaderStack.pop()).close();
1361 } catch (IOException e) {
1362 // ignore
1363 }
1364 }
1365 }
1366
1367 public void endEntity() throws IOException, XNIException {
1368
1369 // call handler
1370 if (DEBUG_BUFFER) {
1371 System.out.print("(endEntity: ");
1372 print();
1373 System.out.println();
1374 }
1375 //pop the entity from the stack
1376 Entity.ScannedEntity entity = fEntityStack.size() > 0 ? (Entity.ScannedEntity)fEntityStack.pop() : null ;
1377
1378 /** need to close the reader first since the program can end
1379 * prematurely (e.g. fEntityHandler.endEntity may throw exception)
1380 * leaving the reader open
1381 */
1382 //close the reader
1383 if(fCurrentEntity != null){
1384 //close the reader
1385 try{
1386 if (fLimitAnalyzer != null) {
1387 fLimitAnalyzer.endEntity(XMLSecurityManager.Limit.GENERAL_ENTITY_SIZE_LIMIT, fCurrentEntity.name);
1388 if (fCurrentEntity.name.equals("[xml]")) {
1389 fSecurityManager.debugPrint(fLimitAnalyzer);
1390 }
1391 }
1392 fCurrentEntity.close();
1393 }catch(IOException ex){
1394 throw new XNIException(ex);
1395 }
1396 }
1397
1398 // REVISIT: We should never encounter underflow if the calls
1399 // to startEntity and endEntity are balanced, but guard
1400 // against the EmptyStackException for now. -- mrglavas
1401 if (!fReaderStack.isEmpty()) {
1402 fReaderStack.pop();
1403 }
1404
1405 if (fEntityHandler != null) {
1406 //so this is the last opened entity, signal it to current fEntityHandler using Augmentation
1407 if(entity == null){
1408 fEntityAugs.removeAllItems();
1409 fEntityAugs.putItem(Constants.LAST_ENTITY, Boolean.TRUE);
1410 fEntityHandler.endEntity(fCurrentEntity.name, fEntityAugs);
1411 fEntityAugs.removeAllItems();
1412 }else{
1413 fEntityHandler.endEntity(fCurrentEntity.name, null);
1414 }
1415 }
1416 //check if it is a document entity
1417 boolean documentEntity = fCurrentEntity.name == XMLEntity;
1418
1419 //set popped entity as current entity
1420 fCurrentEntity = entity;
1421 fEntityScanner.setCurrentEntity(fCurrentEntity);
1422
|