src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 
   5 /*
   6  * Copyright 2005 The Apache Software Foundation.
   7  *
   8  * Licensed under the Apache License, Version 2.0 (the "License");
   9  * you may not use this file except in compliance with the License.
  10  * You may obtain a copy of the License at

  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 
  22 package com.sun.org.apache.xerces.internal.impl;
  23 
  24 import com.sun.xml.internal.stream.XMLBufferListener;
  25 import com.sun.xml.internal.stream.XMLEntityStorage;
  26 import com.sun.xml.internal.stream.XMLInputFactoryImpl;
  27 import com.sun.xml.internal.stream.dtd.DTDGrammarUtil;
  28 
  29 import java.io.EOFException;
  30 import java.io.IOException;
  31 import javax.xml.stream.XMLInputFactory;
  32 import javax.xml.stream.events.XMLEvent;
  33 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
  34 import com.sun.org.apache.xerces.internal.util.AugmentationsImpl;
  35 import com.sun.org.apache.xerces.internal.util.XMLAttributesIteratorImpl;
  36 import com.sun.org.apache.xerces.internal.util.XMLChar;
  37 import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
  38 import com.sun.org.apache.xerces.internal.util.XMLSymbols;
  39 import com.sun.org.apache.xerces.internal.xni.QName;
  40 import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
  41 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;


 386     /** Built-in reference character event */
 387     protected boolean builtInRefCharacterHandled = false;
 388 
 389     //skip element algorithm
 390     static final short MAX_DEPTH_LIMIT = 5 ;
 391     static final short ELEMENT_ARRAY_LENGTH = 200 ;
 392     static final short MAX_POINTER_AT_A_DEPTH = 4 ;
 393     static final boolean DEBUG_SKIP_ALGORITHM = false;
 394     //create a elemnet array of length equal to ELEMENT_ARRAY_LENGTH
 395     String [] fElementArray = new String[ELEMENT_ARRAY_LENGTH] ;
 396     //pointer location where last element was skipped
 397     short fLastPointerLocation = 0 ;
 398     short fElementPointer = 0 ;
 399     //2D array to store pointer info
 400     short [] [] fPointerInfo = new short[MAX_DEPTH_LIMIT] [MAX_POINTER_AT_A_DEPTH] ;
 401     protected String fElementRawname ;
 402     protected boolean fShouldSkip = false;
 403     protected boolean fAdd = false ;
 404     protected boolean fSkip = false;
 405 



 406     /** Reusable Augmentations. */
 407     private Augmentations fTempAugmentations = null;
 408     //
 409     // Constructors
 410     //
 411 
 412     /** Default constructor. */
 413     public XMLDocumentFragmentScannerImpl() {
 414     } // <init>()
 415 
 416     //
 417     // XMLDocumentScanner methods
 418     //
 419 
 420     /**
 421      * Sets the input source.
 422      *
 423      * @param inputSource The input source.
 424      *
 425      * @throws IOException Thrown on i/o error.


 490                     fDocumentHandler.endCDATA(null);
 491                     //System.out.println(" in CDATA of the XMLNSDocumentScannerImpl");
 492                     break;
 493                 case XMLStreamConstants.NOTATION_DECLARATION :
 494                     break;
 495                 case XMLStreamConstants.ENTITY_DECLARATION :
 496                     break;
 497                 case XMLStreamConstants.NAMESPACE :
 498                     break;
 499                 case XMLStreamConstants.ATTRIBUTE :
 500                     break;
 501                 case XMLStreamConstants.END_ELEMENT :
 502                     //do not give callback here.
 503                     //this callback is given in scanEndElement function.
 504                     //fDocumentHandler.endElement(getElementQName(),null);
 505                     break;
 506                 default :
 507                     throw new InternalError("processing event: " + event);
 508 
 509             }
 510             //System.out.println("here in before calling next");



 511             event = next();
 512             //System.out.println("here in after calling next");
 513         } while (event!=XMLStreamConstants.END_DOCUMENT && complete);
 514 
 515         if(event == XMLStreamConstants.END_DOCUMENT) {
 516             fDocumentHandler.endDocument(null);
 517             return false;
 518         }
 519 
 520         return true;
 521 
 522     } // scanDocument(boolean):boolean
 523 







 524 

















 525 
 526     public com.sun.org.apache.xerces.internal.xni.QName getElementQName(){
 527         if(fScannerLastState == XMLEvent.END_ELEMENT){
 528             fElementQName.setValues(fElementStack.getLastPoppedElement());
 529         }
 530         return fElementQName ;
 531     }
 532 
 533     /** return the next state on the input
 534      * @return int
 535      */
 536 
 537     public int next() throws IOException, XNIException {
 538         return fDriver.next();
 539     }
 540 
 541     //
 542     // XMLComponent methods
 543     //
 544 


 638                 propertyManager.getProperty(XML_SECURITY_PROPERTY_MANAGER);
 639         fAccessExternalDTD = spm.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD);
 640 
 641         fSecurityManager = (XMLSecurityManager)propertyManager.getProperty(Constants.SECURITY_MANAGER);
 642         resetCommon();
 643     } // reset(XMLComponentManager)
 644 
 645     void resetCommon() {
 646         // initialize vars
 647         fMarkupDepth = 0;
 648         fCurrentElement = null;
 649         fElementStack.clear();
 650         fHasExternalDTD = false;
 651         fStandaloneSet = false;
 652         fStandalone = false;
 653         fInScanContent = false;
 654         //skipping algorithm
 655         fShouldSkip = false;
 656         fAdd = false;
 657         fSkip = false;

 658 
 659         fEntityStore = fEntityManager.getEntityStore();
 660         dtdGrammarUtil = null;
 661 
 662         if (fSecurityManager != null) {
 663             fElementAttributeLimit = fSecurityManager.getLimit(XMLSecurityManager.Limit.ELEMENT_ATTRIBUTE_LIMIT);
 664         } else {
 665             fElementAttributeLimit = 0;
 666         }
 667         fLimitAnalyzer = new XMLLimitAnalyzer();
 668         fEntityManager.setLimitAnalyzer(fLimitAnalyzer);
 669     }
 670 
 671     /**
 672      * Returns a list of feature identifiers that are recognized by
 673      * this component. This method may return null if no features
 674      * are recognized by this component.
 675      */
 676     public String[] getRecognizedFeatures() {
 677         return (String[])(RECOGNIZED_FEATURES.clone());


   1 /*
   2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 

  22 package com.sun.org.apache.xerces.internal.impl;
  23 
  24 import com.sun.xml.internal.stream.XMLBufferListener;
  25 import com.sun.xml.internal.stream.XMLEntityStorage;
  26 import com.sun.xml.internal.stream.XMLInputFactoryImpl;
  27 import com.sun.xml.internal.stream.dtd.DTDGrammarUtil;
  28 
  29 import java.io.EOFException;
  30 import java.io.IOException;
  31 import javax.xml.stream.XMLInputFactory;
  32 import javax.xml.stream.events.XMLEvent;
  33 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
  34 import com.sun.org.apache.xerces.internal.util.AugmentationsImpl;
  35 import com.sun.org.apache.xerces.internal.util.XMLAttributesIteratorImpl;
  36 import com.sun.org.apache.xerces.internal.util.XMLChar;
  37 import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
  38 import com.sun.org.apache.xerces.internal.util.XMLSymbols;
  39 import com.sun.org.apache.xerces.internal.xni.QName;
  40 import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
  41 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;


 386     /** Built-in reference character event */
 387     protected boolean builtInRefCharacterHandled = false;
 388 
 389     //skip element algorithm
 390     static final short MAX_DEPTH_LIMIT = 5 ;
 391     static final short ELEMENT_ARRAY_LENGTH = 200 ;
 392     static final short MAX_POINTER_AT_A_DEPTH = 4 ;
 393     static final boolean DEBUG_SKIP_ALGORITHM = false;
 394     //create a elemnet array of length equal to ELEMENT_ARRAY_LENGTH
 395     String [] fElementArray = new String[ELEMENT_ARRAY_LENGTH] ;
 396     //pointer location where last element was skipped
 397     short fLastPointerLocation = 0 ;
 398     short fElementPointer = 0 ;
 399     //2D array to store pointer info
 400     short [] [] fPointerInfo = new short[MAX_DEPTH_LIMIT] [MAX_POINTER_AT_A_DEPTH] ;
 401     protected String fElementRawname ;
 402     protected boolean fShouldSkip = false;
 403     protected boolean fAdd = false ;
 404     protected boolean fSkip = false;
 405 
 406     //indicates whether the parsing process should be stopped
 407     private boolean stopProcess = false;
 408 
 409     /** Reusable Augmentations. */
 410     private Augmentations fTempAugmentations = null;
 411     //
 412     // Constructors
 413     //
 414 
 415     /** Default constructor. */
 416     public XMLDocumentFragmentScannerImpl() {
 417     } // <init>()
 418 
 419     //
 420     // XMLDocumentScanner methods
 421     //
 422 
 423     /**
 424      * Sets the input source.
 425      *
 426      * @param inputSource The input source.
 427      *
 428      * @throws IOException Thrown on i/o error.


 493                     fDocumentHandler.endCDATA(null);
 494                     //System.out.println(" in CDATA of the XMLNSDocumentScannerImpl");
 495                     break;
 496                 case XMLStreamConstants.NOTATION_DECLARATION :
 497                     break;
 498                 case XMLStreamConstants.ENTITY_DECLARATION :
 499                     break;
 500                 case XMLStreamConstants.NAMESPACE :
 501                     break;
 502                 case XMLStreamConstants.ATTRIBUTE :
 503                     break;
 504                 case XMLStreamConstants.END_ELEMENT :
 505                     //do not give callback here.
 506                     //this callback is given in scanEndElement function.
 507                     //fDocumentHandler.endElement(getElementQName(),null);
 508                     break;
 509                 default :
 510                     throw new InternalError("processing event: " + event);
 511 
 512             }
 513 
 514             if (stopProcess) {
 515                 break;
 516             }
 517             event = next();

 518         } while (event!=XMLStreamConstants.END_DOCUMENT && complete);
 519 
 520         if(event == XMLStreamConstants.END_DOCUMENT) {
 521             fDocumentHandler.endDocument(null);
 522             return false;
 523         }
 524 
 525         return true;
 526 
 527     } // scanDocument(boolean):boolean
 528 
 529     /**
 530      * Stops the parsing process.
 531      */
 532     @Override
 533     public boolean stop() {
 534         return stopProcess = true;
 535     }
 536 
 537     /**
 538      * Resumes parsing after it was stopped by calling the stop method.
 539      */
 540     @Override
 541     public boolean resume() {
 542         //resume only if the process was stopped.
 543         if (stopProcess) {
 544             stopProcess = false;
 545             try {
 546                 scanDocument(true);
 547                 return true;
 548             } catch (IOException | XNIException ex) {
 549                 //can not resume the parsing process, do nothing.
 550             }
 551         }
 552         return false;
 553     }
 554 
 555     public com.sun.org.apache.xerces.internal.xni.QName getElementQName(){
 556         if(fScannerLastState == XMLEvent.END_ELEMENT){
 557             fElementQName.setValues(fElementStack.getLastPoppedElement());
 558         }
 559         return fElementQName ;
 560     }
 561 
 562     /** return the next state on the input
 563      * @return int
 564      */
 565 
 566     public int next() throws IOException, XNIException {
 567         return fDriver.next();
 568     }
 569 
 570     //
 571     // XMLComponent methods
 572     //
 573 


 667                 propertyManager.getProperty(XML_SECURITY_PROPERTY_MANAGER);
 668         fAccessExternalDTD = spm.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD);
 669 
 670         fSecurityManager = (XMLSecurityManager)propertyManager.getProperty(Constants.SECURITY_MANAGER);
 671         resetCommon();
 672     } // reset(XMLComponentManager)
 673 
 674     void resetCommon() {
 675         // initialize vars
 676         fMarkupDepth = 0;
 677         fCurrentElement = null;
 678         fElementStack.clear();
 679         fHasExternalDTD = false;
 680         fStandaloneSet = false;
 681         fStandalone = false;
 682         fInScanContent = false;
 683         //skipping algorithm
 684         fShouldSkip = false;
 685         fAdd = false;
 686         fSkip = false;
 687         stopProcess = false;
 688 
 689         fEntityStore = fEntityManager.getEntityStore();
 690         dtdGrammarUtil = null;
 691 
 692         if (fSecurityManager != null) {
 693             fElementAttributeLimit = fSecurityManager.getLimit(XMLSecurityManager.Limit.ELEMENT_ATTRIBUTE_LIMIT);
 694         } else {
 695             fElementAttributeLimit = 0;
 696         }
 697         fLimitAnalyzer = new XMLLimitAnalyzer();
 698         fEntityManager.setLimitAnalyzer(fLimitAnalyzer);
 699     }
 700 
 701     /**
 702      * Returns a list of feature identifiers that are recognized by
 703      * this component. This method may return null if no features
 704      * are recognized by this component.
 705      */
 706     public String[] getRecognizedFeatures() {
 707         return (String[])(RECOGNIZED_FEATURES.clone());