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

Print this page




  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;
  42 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
  43 import com.sun.org.apache.xerces.internal.xni.XMLString;
  44 import com.sun.org.apache.xerces.internal.xni.XNIException;
  45 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
  46 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
  47 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
  48 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
  49 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  50 import com.sun.org.apache.xerces.internal.xni.Augmentations;
  51 import com.sun.org.apache.xerces.internal.impl.Constants;
  52 import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
  53 import com.sun.org.apache.xerces.internal.util.SecurityManager;
  54 import com.sun.org.apache.xerces.internal.util.NamespaceSupport;

  55 import com.sun.org.apache.xerces.internal.xni.NamespaceContext;


  56 import javax.xml.stream.XMLStreamConstants;
  57 import javax.xml.stream.events.XMLEvent;
  58 
  59 /**
  60  *
  61  * This class is responsible for scanning the structure and content
  62  * of document fragments.
  63  *
  64  * This class has been modified as per the new design which is more suited to
  65  * efficiently build pull parser. Lot of improvements have been done and
  66  * the code has been added to support stax functionality/features.
  67  *
  68  * @author Neeraj Bajaj SUN Microsystems
  69  * @author K.Venugopal SUN Microsystems
  70  * @author Glenn Marcy, IBM
  71  * @author Andy Clark, IBM
  72  * @author Arnaud  Le Hors, IBM
  73  * @author Eric Ye, IBM
  74  * @author Sunitha Reddy, SUN Microsystems
  75  * @version $Id: XMLDocumentFragmentScannerImpl.java,v 1.19 2010-11-02 19:54:55 joehw Exp $


 142     //<book type="hard">foo</book>
 143     protected static final int SCANNER_STATE_START_ELEMENT_TAG = 38;
 144 
 145     //<book type="hard">foo</book> reading </book>
 146     protected static final int SCANNER_STATE_END_ELEMENT_TAG = 39;
 147 
 148     protected static final int SCANNER_STATE_CHAR_REFERENCE = 40;
 149     protected static final int SCANNER_STATE_BUILT_IN_REFS = 41;
 150 
 151     // feature identifiers
 152 
 153 
 154     /** Feature identifier: notify built-in refereces. */
 155     protected static final String NOTIFY_BUILTIN_REFS =
 156             Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
 157 
 158     /** Property identifier: entity resolver. */
 159     protected static final String ENTITY_RESOLVER =
 160             Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
 161 












 162     // recognized features and properties
 163 
 164     /** Recognized features. */
 165     private static final String[] RECOGNIZED_FEATURES = {
 166                 NAMESPACES,
 167                 VALIDATION,
 168                 NOTIFY_BUILTIN_REFS,
 169                 NOTIFY_CHAR_REFS,
 170                 Constants.STAX_REPORT_CDATA_EVENT
 171     };
 172 
 173     /** Feature defaults. */
 174     private static final Boolean[] FEATURE_DEFAULTS = {
 175                 Boolean.TRUE,
 176                 null,
 177                 Boolean.FALSE,
 178                 Boolean.FALSE,
 179                 Boolean.TRUE
 180     };
 181 
 182     /** Recognized properties. */
 183     private static final String[] RECOGNIZED_PROPERTIES = {
 184         SYMBOL_TABLE,
 185                 ERROR_REPORTER,
 186                 ENTITY_MANAGER,

 187     };
 188 
 189     /** Property defaults. */
 190     private static final Object[] PROPERTY_DEFAULTS = {
 191                 null,
 192                 null,
 193                 null,

 194     };
 195 
 196     private static final char [] cdata = {'[','C','D','A','T','A','['};
 197     private static final char [] endTag = {'<','/'};
 198 
 199     //this variable is also used by XMLDocumentScannerImpl in the same package
 200     static final char [] xmlDecl = {'<','?','x','m','l'};
 201 
 202     // debugging
 203 
 204     /** Debug scanner state. */
 205     private static final boolean DEBUG_SCANNER_STATE = false;
 206 
 207     /** Debug driver. */
 208     private static final boolean DEBUG_DISPATCHER = false;
 209 
 210     /** Debug content driver scanning. */
 211     protected static final boolean DEBUG_START_END_ELEMENT = false;
 212 
 213 


 280 
 281     //xxx do we need to create an extra XMLString object... look for using fTempString for collecting all the data values
 282     protected XMLString fPIData  = new XMLString();
 283 
 284     // features
 285 
 286 
 287     /** Notify built-in references. */
 288     protected boolean fNotifyBuiltInRefs = false;
 289 
 290     //STAX related properties
 291     //defaultValues.
 292     protected boolean fSupportDTD = true;
 293     protected boolean fReplaceEntityReferences = true;
 294     protected boolean fSupportExternalEntities = false;
 295     protected boolean fReportCdataEvent = false ;
 296     protected boolean fIsCoalesce = false ;
 297     protected String fDeclaredEncoding =  null;
 298     /** Xerces Feature: Disallow doctype declaration. */
 299     protected boolean fDisallowDoctype = false;





 300 






 301     // drivers
 302 
 303     /** Active driver. */
 304     protected Driver fDriver;
 305 
 306     /** Content driver. */
 307     protected Driver fContentDriver = createContentDriver();
 308 
 309     // temporary variables
 310 
 311     /** Element QName. */
 312     protected QName fElementQName = new QName();
 313 
 314     /** Attribute QName. */
 315     protected QName fAttributeQName = new QName();
 316 
 317     /**
 318      * CHANGED: Using XMLAttributesIteratorImpl instead of XMLAttributesImpl. This class
 319      * implements Iterator interface so we can directly give Attributes in the form of
 320      * iterator.


 396      */
 397     public void setInputSource(XMLInputSource inputSource) throws IOException {
 398         fEntityManager.setEntityHandler(this);
 399         fEntityManager.startEntity("$fragment$", inputSource, false, true);
 400         // fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId());
 401     } // setInputSource(XMLInputSource)
 402 
 403     /**
 404      * Scans a document.
 405      *
 406      * @param complete True if the scanner should scan the document
 407      *                 completely, pushing all events to the registered
 408      *                 document handler. A value of false indicates that
 409      *                 that the scanner should only scan the next portion
 410      *                 of the document and return. A scanner instance is
 411      *                 permitted to completely scan a document if it does
 412      *                 not support this "pull" scanning model.
 413      *
 414      * @return True if there is more to scan, false otherwise.
 415      */
 416    /* public boolean scanDocument(boolean complete)
 417     throws IOException, XNIException {
 418 
 419         // keep dispatching "events"
 420         fEntityManager.setEntityHandler(this);
 421 
 422         return true;
 423 
 424     } // scanDocument(boolean):boolean
 425     */
 426 
 427     public boolean scanDocument(boolean complete)
 428     throws IOException, XNIException {
 429 
 430         // keep dispatching "events"
 431         fEntityManager.setEntityHandler(this);
 432         //System.out.println(" get Document Handler in NSDocumentHandler " + fDocumentHandler );
 433 
 434         int event = next();
 435         do {
 436             switch (event) {
 437                 case XMLStreamConstants.START_DOCUMENT :
 438                     //fDocumentHandler.startDocument(fEntityManager.getEntityScanner(),fEntityManager.getEntityScanner().getVersion(),fNamespaceContext,null);// not able to get
 439                     break;
 440                 case XMLStreamConstants.START_ELEMENT :
 441                     //System.out.println(" in scann element");
 442                     //fDocumentHandler.startElement(getElementQName(),fAttributes,null);
 443                     break;
 444                 case XMLStreamConstants.CHARACTERS :
 445                     fDocumentHandler.characters(getCharacterData(),null);
 446                     break;


 562                 (ExternalSubsetResolver) resolver : null;
 563 
 564         // initialize vars
 565         fMarkupDepth = 0;
 566         fCurrentElement = null;
 567         fElementStack.clear();
 568         fHasExternalDTD = false;
 569         fStandaloneSet = false;
 570         fStandalone = false;
 571         fInScanContent = false;
 572         //skipping algorithm
 573         fShouldSkip = false;
 574         fAdd = false;
 575         fSkip = false;
 576 
 577         //attribute
 578         fReadingAttributes = false;
 579         //xxx: external entities are supported in Xerces
 580         // it would be good to define feature for this case
 581         fSupportExternalEntities = true;



 582         fReplaceEntityReferences = true;
 583         fIsCoalesce = false;
 584 
 585         // setup Driver
 586         setScannerState(SCANNER_STATE_CONTENT);
 587         setDriver(fContentDriver);
 588         fEntityStore = fEntityManager.getEntityStore();
 589 
 590         dtdGrammarUtil = null;
 591 



 592 
 593         //fEntityManager.test();
 594     } // reset(XMLComponentManager)
 595 
 596 
 597     public void reset(PropertyManager propertyManager){
 598 
 599         super.reset(propertyManager);
 600 
 601         // other settings
 602         // fDocumentSystemId = null;
 603         fNamespaces = ((Boolean)propertyManager.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE)).booleanValue();
 604         fNotifyBuiltInRefs = false ;
 605 
 606         // initialize vars
 607         fMarkupDepth = 0;
 608         fCurrentElement = null;
 609         fShouldSkip = false;
 610         fAdd = false;
 611         fSkip = false;


 622         fSupportExternalEntities = bo.booleanValue();
 623         Boolean cdata = (Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.STAX_REPORT_CDATA_EVENT) ;
 624         if(cdata != null)
 625             fReportCdataEvent = cdata.booleanValue() ;
 626         Boolean coalesce = (Boolean)propertyManager.getProperty(XMLInputFactory.IS_COALESCING) ;
 627         if(coalesce != null)
 628             fIsCoalesce = coalesce.booleanValue();
 629         fReportCdataEvent = fIsCoalesce ? false : (fReportCdataEvent && true) ;
 630         //if fIsCoalesce is set to true, set the value of fReplaceEntityReferences to true,
 631         //if fIsCoalesce is set to false, take the value of fReplaceEntityReferences as set by application
 632         fReplaceEntityReferences = fIsCoalesce ? true : fReplaceEntityReferences;
 633         // setup Driver
 634         //we dont need to do this -- nb.
 635         //setScannerState(SCANNER_STATE_CONTENT);
 636         //setDriver(fContentDriver);
 637         fEntityStore = fEntityManager.getEntityStore();
 638         //fEntityManager.test();
 639 
 640         dtdGrammarUtil = null;
 641 



 642     } // reset(XMLComponentManager)
 643 
 644     /**
 645      * Returns a list of feature identifiers that are recognized by
 646      * this component. This method may return null if no features
 647      * are recognized by this component.
 648      */
 649     public String[] getRecognizedFeatures() {
 650         return (String[])(RECOGNIZED_FEATURES.clone());
 651     } // getRecognizedFeatures():String[]
 652 
 653     /**
 654      * Sets the state of a feature. This method is called by the component
 655      * manager any time after reset when a feature changes state.
 656      * <p>
 657      * <strong>Note:</strong> Components should silently ignore features
 658      * that do not affect the operation of the component.
 659      *
 660      * @param featureId The feature identifier.
 661      * @param state     The state of the feature.


 718                 return;
 719             }
 720             if (suffixLength == Constants.ENTITY_RESOLVER_PROPERTY.length() &&
 721                     propertyId.endsWith(Constants.ENTITY_RESOLVER_PROPERTY)) {
 722                 fExternalSubsetResolver = (value instanceof ExternalSubsetResolver) ?
 723                     (ExternalSubsetResolver) value : null;
 724                 return;
 725             }
 726         }
 727 
 728 
 729                 // Xerces properties
 730         if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
 731             String property = propertyId.substring(Constants.XERCES_PROPERTY_PREFIX.length());
 732             if (property.equals(Constants.ENTITY_MANAGER_PROPERTY)) {
 733                 fEntityManager = (XMLEntityManager)value;
 734             }
 735             return;
 736         }
 737 








 738     } // setProperty(String,Object)
 739 
 740     /**
 741      * Returns the default state for a feature, or null if this
 742      * component does not want to report a default value for this
 743      * feature.
 744      *
 745      * @param featureId The feature identifier.
 746      *
 747      * @since Xerces 2.2.0
 748      */
 749     public Boolean getFeatureDefault(String featureId) {
 750         for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) {
 751             if (RECOGNIZED_FEATURES[i].equals(featureId)) {
 752                 return FEATURE_DEFAULTS[i];
 753             }
 754         }
 755         return null;
 756     } // getFeatureDefault(String):Boolean
 757 


1829             handleCharacter('<', fLtSymbol, content);
1830             fScannerState = SCANNER_STATE_BUILT_IN_REFS;
1831             return ;
1832         } else if (name == fGtSymbol) {
1833             handleCharacter('>', fGtSymbol, content);
1834             fScannerState = SCANNER_STATE_BUILT_IN_REFS;
1835             return ;
1836         } else if (name == fQuotSymbol) {
1837             handleCharacter('"', fQuotSymbol, content);
1838             fScannerState = SCANNER_STATE_BUILT_IN_REFS;
1839             return ;
1840         } else if (name == fAposSymbol) {
1841             handleCharacter('\'', fAposSymbol, content);
1842             fScannerState = SCANNER_STATE_BUILT_IN_REFS;
1843             return ;
1844         }
1845 
1846         //1. if the entity is external and support to external entities is not required
1847         // 2. or entities should not be replaced
1848         //3. or if it is built in entity reference.
1849         if((fEntityStore.isExternalEntity(name) && !fSupportExternalEntities) || (!fEntityStore.isExternalEntity(name) && !fReplaceEntityReferences) || foundBuiltInRefs){

1850             fScannerState = SCANNER_STATE_REFERENCE;
1851             return ;
1852         }
1853         // start general entity
1854         if (!fEntityStore.isDeclaredEntity(name)) {
1855             //SUPPORT_DTD=false && ReplaceEntityReferences should throw exception
1856             if (!fSupportDTD && fReplaceEntityReferences) {
1857                 reportFatalError("EntityNotDeclared", new Object[]{name});
1858                 return;
1859             }
1860             //REVISIT: one more case needs to be included: external PE and standalone is no
1861             if ( fHasExternalDTD && !fStandalone) {
1862                 if (fValidation)
1863                     fErrorReporter.reportError(fEntityScanner, XMLMessageFormatter.XML_DOMAIN,"EntityNotDeclared",
1864                             new Object[]{name}, XMLErrorReporter.SEVERITY_ERROR);
1865             } else
1866                 reportFatalError("EntityNotDeclared", new Object[]{name});
1867         }
1868         //we are starting the entity even if the entity was not declared
1869         //if that was the case it its taken care in XMLEntityManager.startEntity()


1979     public String getDriverName(Driver driver) {
1980 
1981         if (DEBUG_DISPATCHER) {
1982             if (driver != null) {
1983                 String name = driver.getClass().getName();
1984                 int index = name.lastIndexOf('.');
1985                 if (index != -1) {
1986                     name = name.substring(index + 1);
1987                     index = name.lastIndexOf('$');
1988                     if (index != -1) {
1989                         name = name.substring(index + 1);
1990                     }
1991                 }
1992                 return name;
1993             }
1994         }
1995         return "null";
1996 
1997     } // getDriverName():String
1998 






1999     //
2000     // Classes
2001     //
2002 
2003     /**
2004      * @author Neeraj Bajaj, Sun Microsystems.
2005      */
2006     protected static final class Element {
2007 
2008         //
2009         // Data
2010         //
2011 
2012         /** Symbol. */
2013         public QName qname;
2014 
2015         //raw name stored as characters
2016         public char[] fRawname;
2017 
2018         /** The next Element entry. */




  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;
  42 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
  43 import com.sun.org.apache.xerces.internal.xni.XMLString;
  44 import com.sun.org.apache.xerces.internal.xni.XNIException;
  45 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
  46 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
  47 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
  48 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
  49 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  50 import com.sun.org.apache.xerces.internal.xni.Augmentations;
  51 import com.sun.org.apache.xerces.internal.impl.Constants;
  52 import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
  53 import com.sun.org.apache.xerces.internal.util.SecurityManager;
  54 import com.sun.org.apache.xerces.internal.util.NamespaceSupport;
  55 import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
  56 import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
  57 import com.sun.xml.internal.stream.Entity;
  58 import javax.xml.XMLConstants;
  59 import javax.xml.stream.XMLStreamConstants;
  60 import javax.xml.stream.events.XMLEvent;
  61 
  62 /**
  63  *
  64  * This class is responsible for scanning the structure and content
  65  * of document fragments.
  66  *
  67  * This class has been modified as per the new design which is more suited to
  68  * efficiently build pull parser. Lot of improvements have been done and
  69  * the code has been added to support stax functionality/features.
  70  *
  71  * @author Neeraj Bajaj SUN Microsystems
  72  * @author K.Venugopal SUN Microsystems
  73  * @author Glenn Marcy, IBM
  74  * @author Andy Clark, IBM
  75  * @author Arnaud  Le Hors, IBM
  76  * @author Eric Ye, IBM
  77  * @author Sunitha Reddy, SUN Microsystems
  78  * @version $Id: XMLDocumentFragmentScannerImpl.java,v 1.19 2010-11-02 19:54:55 joehw Exp $


 145     //<book type="hard">foo</book>
 146     protected static final int SCANNER_STATE_START_ELEMENT_TAG = 38;
 147 
 148     //<book type="hard">foo</book> reading </book>
 149     protected static final int SCANNER_STATE_END_ELEMENT_TAG = 39;
 150 
 151     protected static final int SCANNER_STATE_CHAR_REFERENCE = 40;
 152     protected static final int SCANNER_STATE_BUILT_IN_REFS = 41;
 153 
 154     // feature identifiers
 155 
 156 
 157     /** Feature identifier: notify built-in refereces. */
 158     protected static final String NOTIFY_BUILTIN_REFS =
 159             Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
 160 
 161     /** Property identifier: entity resolver. */
 162     protected static final String ENTITY_RESOLVER =
 163             Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
 164 
 165     /** Feature identifier: standard uri conformant */
 166     protected static final String STANDARD_URI_CONFORMANT =
 167             Constants.XERCES_FEATURE_PREFIX +Constants.STANDARD_URI_CONFORMANT_FEATURE;
 168 
 169     /** property identifier: access external dtd. */
 170     protected static final String ACCESS_EXTERNAL_DTD = XMLConstants.ACCESS_EXTERNAL_DTD;
 171 
 172     /** access external dtd: file protocol 
 173      *  For DOM/SAX, the secure feature is set to true by default
 174      */
 175     final static String EXTERNAL_ACCESS_DEFAULT = Constants.EXTERNAL_ACCESS_DEFAULT;
 176 
 177     // recognized features and properties
 178 
 179     /** Recognized features. */
 180     private static final String[] RECOGNIZED_FEATURES = {
 181                 NAMESPACES,
 182                 VALIDATION,
 183                 NOTIFY_BUILTIN_REFS,
 184                 NOTIFY_CHAR_REFS,
 185                 Constants.STAX_REPORT_CDATA_EVENT
 186     };
 187 
 188     /** Feature defaults. */
 189     private static final Boolean[] FEATURE_DEFAULTS = {
 190                 Boolean.TRUE,
 191                 null,
 192                 Boolean.FALSE,
 193                 Boolean.FALSE,
 194                 Boolean.TRUE
 195     };
 196 
 197     /** Recognized properties. */
 198     private static final String[] RECOGNIZED_PROPERTIES = {
 199         SYMBOL_TABLE,
 200                 ERROR_REPORTER,
 201                 ENTITY_MANAGER,
 202                 ACCESS_EXTERNAL_DTD
 203     };
 204 
 205     /** Property defaults. */
 206     private static final Object[] PROPERTY_DEFAULTS = {
 207                 null,
 208                 null,
 209                 null,
 210                 EXTERNAL_ACCESS_DEFAULT
 211     };
 212 
 213     private static final char [] cdata = {'[','C','D','A','T','A','['};
 214     private static final char [] endTag = {'<','/'};
 215 
 216     //this variable is also used by XMLDocumentScannerImpl in the same package
 217     static final char [] xmlDecl = {'<','?','x','m','l'};
 218 
 219     // debugging
 220 
 221     /** Debug scanner state. */
 222     private static final boolean DEBUG_SCANNER_STATE = false;
 223 
 224     /** Debug driver. */
 225     private static final boolean DEBUG_DISPATCHER = false;
 226 
 227     /** Debug content driver scanning. */
 228     protected static final boolean DEBUG_START_END_ELEMENT = false;
 229 
 230 


 297 
 298     //xxx do we need to create an extra XMLString object... look for using fTempString for collecting all the data values
 299     protected XMLString fPIData  = new XMLString();
 300 
 301     // features
 302 
 303 
 304     /** Notify built-in references. */
 305     protected boolean fNotifyBuiltInRefs = false;
 306 
 307     //STAX related properties
 308     //defaultValues.
 309     protected boolean fSupportDTD = true;
 310     protected boolean fReplaceEntityReferences = true;
 311     protected boolean fSupportExternalEntities = false;
 312     protected boolean fReportCdataEvent = false ;
 313     protected boolean fIsCoalesce = false ;
 314     protected String fDeclaredEncoding =  null;
 315     /** Xerces Feature: Disallow doctype declaration. */
 316     protected boolean fDisallowDoctype = false;
 317     /**
 318      * comma-delimited list of protocols that are allowed for the purpose
 319      * of accessing external dtd or entity references
 320      */
 321     protected String fAccessExternalDTD = EXTERNAL_ACCESS_DEFAULT;
 322 
 323     /**
 324      * standard uri conformant (strict uri).
 325      * http://apache.org/xml/features/standard-uri-conformant
 326      */
 327     protected boolean fStrictURI;
 328 
 329     // drivers
 330 
 331     /** Active driver. */
 332     protected Driver fDriver;
 333 
 334     /** Content driver. */
 335     protected Driver fContentDriver = createContentDriver();
 336 
 337     // temporary variables
 338 
 339     /** Element QName. */
 340     protected QName fElementQName = new QName();
 341 
 342     /** Attribute QName. */
 343     protected QName fAttributeQName = new QName();
 344 
 345     /**
 346      * CHANGED: Using XMLAttributesIteratorImpl instead of XMLAttributesImpl. This class
 347      * implements Iterator interface so we can directly give Attributes in the form of
 348      * iterator.


 424      */
 425     public void setInputSource(XMLInputSource inputSource) throws IOException {
 426         fEntityManager.setEntityHandler(this);
 427         fEntityManager.startEntity("$fragment$", inputSource, false, true);
 428         // fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId());
 429     } // setInputSource(XMLInputSource)
 430 
 431     /**
 432      * Scans a document.
 433      *
 434      * @param complete True if the scanner should scan the document
 435      *                 completely, pushing all events to the registered
 436      *                 document handler. A value of false indicates that
 437      *                 that the scanner should only scan the next portion
 438      *                 of the document and return. A scanner instance is
 439      *                 permitted to completely scan a document if it does
 440      *                 not support this "pull" scanning model.
 441      *
 442      * @return True if there is more to scan, false otherwise.
 443      */











 444     public boolean scanDocument(boolean complete)
 445     throws IOException, XNIException {
 446 
 447         // keep dispatching "events"
 448         fEntityManager.setEntityHandler(this);
 449         //System.out.println(" get Document Handler in NSDocumentHandler " + fDocumentHandler );
 450 
 451         int event = next();
 452         do {
 453             switch (event) {
 454                 case XMLStreamConstants.START_DOCUMENT :
 455                     //fDocumentHandler.startDocument(fEntityManager.getEntityScanner(),fEntityManager.getEntityScanner().getVersion(),fNamespaceContext,null);// not able to get
 456                     break;
 457                 case XMLStreamConstants.START_ELEMENT :
 458                     //System.out.println(" in scann element");
 459                     //fDocumentHandler.startElement(getElementQName(),fAttributes,null);
 460                     break;
 461                 case XMLStreamConstants.CHARACTERS :
 462                     fDocumentHandler.characters(getCharacterData(),null);
 463                     break;


 579                 (ExternalSubsetResolver) resolver : null;
 580 
 581         // initialize vars
 582         fMarkupDepth = 0;
 583         fCurrentElement = null;
 584         fElementStack.clear();
 585         fHasExternalDTD = false;
 586         fStandaloneSet = false;
 587         fStandalone = false;
 588         fInScanContent = false;
 589         //skipping algorithm
 590         fShouldSkip = false;
 591         fAdd = false;
 592         fSkip = false;
 593 
 594         //attribute
 595         fReadingAttributes = false;
 596         //xxx: external entities are supported in Xerces
 597         // it would be good to define feature for this case
 598         fSupportExternalEntities = true;
 599         fSupportExternalEntities = true;
 600         fSupportExternalEntities = true;
 601         fSupportExternalEntities = true;
 602         fReplaceEntityReferences = true;
 603         fIsCoalesce = false;
 604 
 605         // setup Driver
 606         setScannerState(SCANNER_STATE_CONTENT);
 607         setDriver(fContentDriver);
 608         fEntityStore = fEntityManager.getEntityStore();
 609 
 610         dtdGrammarUtil = null;
 611 
 612         // JAXP 1.5 features and properties
 613         fAccessExternalDTD = (String) componentManager.getProperty(ACCESS_EXTERNAL_DTD, EXTERNAL_ACCESS_DEFAULT);
 614         fStrictURI = componentManager.getFeature(STANDARD_URI_CONFORMANT, false);
 615 
 616         //fEntityManager.test();
 617     } // reset(XMLComponentManager)
 618 
 619 
 620     public void reset(PropertyManager propertyManager){
 621 
 622         super.reset(propertyManager);
 623 
 624         // other settings
 625         // fDocumentSystemId = null;
 626         fNamespaces = ((Boolean)propertyManager.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE)).booleanValue();
 627         fNotifyBuiltInRefs = false ;
 628 
 629         // initialize vars
 630         fMarkupDepth = 0;
 631         fCurrentElement = null;
 632         fShouldSkip = false;
 633         fAdd = false;
 634         fSkip = false;


 645         fSupportExternalEntities = bo.booleanValue();
 646         Boolean cdata = (Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.STAX_REPORT_CDATA_EVENT) ;
 647         if(cdata != null)
 648             fReportCdataEvent = cdata.booleanValue() ;
 649         Boolean coalesce = (Boolean)propertyManager.getProperty(XMLInputFactory.IS_COALESCING) ;
 650         if(coalesce != null)
 651             fIsCoalesce = coalesce.booleanValue();
 652         fReportCdataEvent = fIsCoalesce ? false : (fReportCdataEvent && true) ;
 653         //if fIsCoalesce is set to true, set the value of fReplaceEntityReferences to true,
 654         //if fIsCoalesce is set to false, take the value of fReplaceEntityReferences as set by application
 655         fReplaceEntityReferences = fIsCoalesce ? true : fReplaceEntityReferences;
 656         // setup Driver
 657         //we dont need to do this -- nb.
 658         //setScannerState(SCANNER_STATE_CONTENT);
 659         //setDriver(fContentDriver);
 660         fEntityStore = fEntityManager.getEntityStore();
 661         //fEntityManager.test();
 662 
 663         dtdGrammarUtil = null;
 664 
 665         // Oracle jdk feature
 666         fAccessExternalDTD = (String) propertyManager.getProperty(ACCESS_EXTERNAL_DTD);
 667 
 668     } // reset(XMLComponentManager)
 669 
 670     /**
 671      * Returns a list of feature identifiers that are recognized by
 672      * this component. This method may return null if no features
 673      * are recognized by this component.
 674      */
 675     public String[] getRecognizedFeatures() {
 676         return (String[])(RECOGNIZED_FEATURES.clone());
 677     } // getRecognizedFeatures():String[]
 678 
 679     /**
 680      * Sets the state of a feature. This method is called by the component
 681      * manager any time after reset when a feature changes state.
 682      * <p>
 683      * <strong>Note:</strong> Components should silently ignore features
 684      * that do not affect the operation of the component.
 685      *
 686      * @param featureId The feature identifier.
 687      * @param state     The state of the feature.


 744                 return;
 745             }
 746             if (suffixLength == Constants.ENTITY_RESOLVER_PROPERTY.length() &&
 747                     propertyId.endsWith(Constants.ENTITY_RESOLVER_PROPERTY)) {
 748                 fExternalSubsetResolver = (value instanceof ExternalSubsetResolver) ?
 749                     (ExternalSubsetResolver) value : null;
 750                 return;
 751             }
 752         }
 753 
 754 
 755                 // Xerces properties
 756         if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
 757             String property = propertyId.substring(Constants.XERCES_PROPERTY_PREFIX.length());
 758             if (property.equals(Constants.ENTITY_MANAGER_PROPERTY)) {
 759                 fEntityManager = (XMLEntityManager)value;
 760             }
 761             return;
 762         }
 763 
 764         //JAXP 1.5 properties
 765         if (propertyId.startsWith(Constants.JAXPAPI_PROPERTY_PREFIX)) {
 766             if (propertyId.equals(ACCESS_EXTERNAL_DTD))
 767             {
 768                 fAccessExternalDTD = (String)value;
 769             }
 770         }
 771 
 772     } // setProperty(String,Object)
 773 
 774     /**
 775      * Returns the default state for a feature, or null if this
 776      * component does not want to report a default value for this
 777      * feature.
 778      *
 779      * @param featureId The feature identifier.
 780      *
 781      * @since Xerces 2.2.0
 782      */
 783     public Boolean getFeatureDefault(String featureId) {
 784         for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) {
 785             if (RECOGNIZED_FEATURES[i].equals(featureId)) {
 786                 return FEATURE_DEFAULTS[i];
 787             }
 788         }
 789         return null;
 790     } // getFeatureDefault(String):Boolean
 791 


1863             handleCharacter('<', fLtSymbol, content);
1864             fScannerState = SCANNER_STATE_BUILT_IN_REFS;
1865             return ;
1866         } else if (name == fGtSymbol) {
1867             handleCharacter('>', fGtSymbol, content);
1868             fScannerState = SCANNER_STATE_BUILT_IN_REFS;
1869             return ;
1870         } else if (name == fQuotSymbol) {
1871             handleCharacter('"', fQuotSymbol, content);
1872             fScannerState = SCANNER_STATE_BUILT_IN_REFS;
1873             return ;
1874         } else if (name == fAposSymbol) {
1875             handleCharacter('\'', fAposSymbol, content);
1876             fScannerState = SCANNER_STATE_BUILT_IN_REFS;
1877             return ;
1878         }
1879 
1880         //1. if the entity is external and support to external entities is not required
1881         // 2. or entities should not be replaced
1882         //3. or if it is built in entity reference.
1883         boolean isEE = fEntityStore.isExternalEntity(name);
1884         if((isEE && !fSupportExternalEntities) || (!isEE && !fReplaceEntityReferences) || foundBuiltInRefs){
1885             fScannerState = SCANNER_STATE_REFERENCE;
1886             return ;
1887         }
1888         // start general entity
1889         if (!fEntityStore.isDeclaredEntity(name)) {
1890             //SUPPORT_DTD=false && ReplaceEntityReferences should throw exception
1891             if (!fSupportDTD && fReplaceEntityReferences) {
1892                 reportFatalError("EntityNotDeclared", new Object[]{name});
1893                 return;
1894             }
1895             //REVISIT: one more case needs to be included: external PE and standalone is no
1896             if ( fHasExternalDTD && !fStandalone) {
1897                 if (fValidation)
1898                     fErrorReporter.reportError(fEntityScanner, XMLMessageFormatter.XML_DOMAIN,"EntityNotDeclared",
1899                             new Object[]{name}, XMLErrorReporter.SEVERITY_ERROR);
1900             } else
1901                 reportFatalError("EntityNotDeclared", new Object[]{name});
1902         }
1903         //we are starting the entity even if the entity was not declared
1904         //if that was the case it its taken care in XMLEntityManager.startEntity()


2014     public String getDriverName(Driver driver) {
2015 
2016         if (DEBUG_DISPATCHER) {
2017             if (driver != null) {
2018                 String name = driver.getClass().getName();
2019                 int index = name.lastIndexOf('.');
2020                 if (index != -1) {
2021                     name = name.substring(index + 1);
2022                     index = name.lastIndexOf('$');
2023                     if (index != -1) {
2024                         name = name.substring(index + 1);
2025                     }
2026                 }
2027                 return name;
2028             }
2029         }
2030         return "null";
2031 
2032     } // getDriverName():String
2033 
2034     String checkAccess(String systemId, String allowedProtocols) throws IOException {
2035         String baseSystemId = fEntityScanner.getBaseSystemId();
2036         String expandedSystemId = fEntityManager.expandSystemId(systemId, baseSystemId,fStrictURI);
2037         return SecuritySupport.checkAccess(expandedSystemId, allowedProtocols, Constants.ACCESS_EXTERNAL_ALL);
2038     }
2039 
2040     //
2041     // Classes
2042     //
2043 
2044     /**
2045      * @author Neeraj Bajaj, Sun Microsystems.
2046      */
2047     protected static final class Element {
2048 
2049         //
2050         // Data
2051         //
2052 
2053         /** Symbol. */
2054         public QName qname;
2055 
2056         //raw name stored as characters
2057         public char[] fRawname;
2058 
2059         /** The next Element entry. */