FileDocCategorySizeDatePackage
XMLDocumentFragmentScannerImpl.javaAPI DocJava SE 6 API133826Tue Jun 10 00:22:38 BST 2008com.sun.org.apache.xerces.internal.impl

XMLDocumentFragmentScannerImpl

public class XMLDocumentFragmentScannerImpl extends XMLScanner implements XMLBufferListener, XMLEntityHandler, XMLDocumentScanner, XMLComponent
This class is responsible for scanning the structure and content of document fragments. This class has been modified as per the new design which is more suited to efficiently build pull parser. Lot of improvements have been done and the code has been added to support stax functionality/features.
author
Neeraj Bajaj SUN Microsystems
author
K.Venugopal SUN Microsystems
author
Glenn Marcy, IBM
author
Andy Clark, IBM
author
Arnaud Le Hors, IBM
author
Eric Ye, IBM
author
Sunitha Reddy, SUN Microsystems
version
$Id: XMLDocumentFragmentScannerImpl.java,v 1.13 2007/05/09 15:23:31 ndw Exp $

Fields Summary
protected int
fElementAttributeLimit
protected ExternalSubsetResolver
fExternalSubsetResolver
External subset resolver.
protected static final int
SCANNER_STATE_START_OF_MARKUP
Scanner state: start of markup.
protected static final int
SCANNER_STATE_CONTENT
Scanner state: content.
protected static final int
SCANNER_STATE_PI
Scanner state: processing instruction.
protected static final int
SCANNER_STATE_DOCTYPE
Scanner state: DOCTYPE.
protected static final int
SCANNER_STATE_XML_DECL
Scanner state: XML Declaration
protected static final int
SCANNER_STATE_ROOT_ELEMENT
Scanner state: root element.
protected static final int
SCANNER_STATE_COMMENT
Scanner state: comment.
protected static final int
SCANNER_STATE_REFERENCE
Scanner state: reference.
protected static final int
SCANNER_STATE_ATTRIBUTE
protected static final int
SCANNER_STATE_ATTRIBUTE_VALUE
protected static final int
SCANNER_STATE_END_OF_INPUT
Scanner state: end of input.
protected static final int
SCANNER_STATE_TERMINATED
Scanner state: terminated.
protected static final int
SCANNER_STATE_CDATA
Scanner state: CDATA section.
protected static final int
SCANNER_STATE_TEXT_DECL
Scanner state: Text declaration.
protected static final int
SCANNER_STATE_CHARACTER_DATA
Scanner state: Text declaration.
protected static final int
SCANNER_STATE_START_ELEMENT_TAG
protected static final int
SCANNER_STATE_END_ELEMENT_TAG
protected static final int
SCANNER_STATE_CHAR_REFERENCE
protected static final int
SCANNER_STATE_BUILT_IN_REFS
protected static final String
NOTIFY_BUILTIN_REFS
Feature identifier: notify built-in refereces.
protected static final String
ENTITY_RESOLVER
Property identifier: entity resolver.
private static final String[]
RECOGNIZED_FEATURES
Recognized features.
private static final Boolean[]
FEATURE_DEFAULTS
Feature defaults.
private static final String[]
RECOGNIZED_PROPERTIES
Recognized properties.
private static final Object[]
PROPERTY_DEFAULTS
Property defaults.
protected static final char[]
cdata
protected static final char[]
xmlDecl
protected static final char[]
endTag
private static final boolean
DEBUG_SCANNER_STATE
Debug scanner state.
private static final boolean
DEBUG_DISPATCHER
Debug driver.
protected static final boolean
DEBUG_START_END_ELEMENT
Debug content driver scanning.
protected static final boolean
DEBUG_NEXT
Debug driver next
protected static final boolean
DEBUG
Debug driver next
protected static final boolean
DEBUG_COALESCE
protected XMLDocumentHandler
fDocumentHandler
Document handler.
protected int
fScannerLastState
protected XMLEntityStorage
fEntityStore
Entity Storage
protected int[]
fEntityStack
Entity stack.
protected int
fMarkupDepth
Markup depth.
protected boolean
fEmptyElement
protected boolean
fReadingAttributes
protected int
fScannerState
Scanner state.
protected boolean
fInScanContent
SubScanner state: inside scanContent method.
protected boolean
fLastSectionWasCData
protected boolean
fLastSectionWasEntityReference
protected boolean
fLastSectionWasCharacterData
protected boolean
fHasExternalDTD
has external dtd
protected boolean
fStandalone
Standalone.
protected String
fVersion
protected QName
fCurrentElement
Current element.
protected ElementStack
fElementStack
Element stack.
protected ElementStack2
fElementStack2
protected String
fPITarget
Document system identifier. REVISIT: So what's this used for? - NG protected String fDocumentSystemId;
protected XMLString
fPIData
protected boolean
fNotifyBuiltInRefs
Notify built-in references.
protected boolean
fReplaceEntityReferences
protected boolean
fSupportExternalEntities
protected boolean
fReportCdataEvent
protected boolean
fIsCoalesce
protected String
fDeclaredEncoding
protected boolean
fDisallowDoctype
Disallow doctype declaration.
protected Driver
fDriver
Active driver.
protected Driver
fContentDriver
Content driver.
protected QName
fElementQName
Element QName.
protected QName
fAttributeQName
Attribute QName.
protected XMLAttributesIteratorImpl
fAttributes
CHANGED: Using XMLAttributesIteratorImpl instead of XMLAttributesImpl. This class implements Iterator interface so we can directly give Attributes in the form of iterator.
protected XMLString
fTempString
String.
protected XMLString
fTempString2
String.
private String[]
fStrings
Array of 3 strings.
protected XMLStringBuffer
fStringBuffer
Making the buffer accesible to derived class -- String buffer.
protected XMLStringBuffer
fStringBuffer2
Making the buffer accesible to derived class -- String buffer.
protected XMLStringBuffer
fContentBuffer
Making the buffer accesible to derived class -- stores PI data
private final char[]
fSingleChar
Single character array.
private String
fCurrentEntityName
protected boolean
fScanToEnd
protected DTDGrammarUtil
dtdGrammarUtil
protected boolean
fAddDefaultAttr
protected boolean
foundBuiltInRefs
protected SecurityManager
fSecurityManager
static final short
MAX_DEPTH_LIMIT
static final short
ELEMENT_ARRAY_LENGTH
static final short
MAX_POINTER_AT_A_DEPTH
static final boolean
DEBUG_SKIP_ALGORITHM
String[]
fElementArray
short
fLastPointerLocation
short
fElementPointer
short[]
fPointerInfo
protected String
fElementRawname
protected boolean
fShouldSkip
protected boolean
fAdd
protected boolean
fSkip
private Augmentations
fTempAugmentations
Reusable Augmentations.
protected boolean
fUsebuffer
Constructors Summary
public XMLDocumentFragmentScannerImpl()
Default constructor.

    //
    // Constructors
    //
    
       
      
    
Methods Summary
voidaddElement(java.lang.String rawname)

        if(fElementPointer < ELEMENT_ARRAY_LENGTH){
            //storing element raw name in a linear list of array
            fElementArray[fElementPointer] = rawname ;
            //storing elemnetPointer for particular element depth
            
            if(DEBUG_SKIP_ALGORITHM){
                StringBuffer sb = new StringBuffer() ;
                sb.append(" Storing element information ") ;
                sb.append(" fElementPointer = " + fElementPointer) ;
                sb.append(" fElementRawname = " + fElementQName.rawname) ;
                sb.append(" fElementStack.fDepth = " + fElementStack.fDepth);
                System.out.println(sb.toString()) ;
            }
            
            //store pointer information only when element depth is less MAX_DEPTH_LIMIT
            if(fElementStack.fDepth < MAX_DEPTH_LIMIT){
                short column = storePointerForADepth(fElementPointer);
                if(column > 0){
                    short pointer = getElementPointer((short)fElementStack.fDepth, (short)(column - 1) );
                    //identity comparison shouldn't take much time and we can rely on this
                    //since its guaranteed to have same object id for same string.
                    if(rawname == fElementArray[pointer]){
                        fShouldSkip = true ;
                        fLastPointerLocation = pointer ;
                        //reset the things and return.
                        resetPointer((short)fElementStack.fDepth , column) ;
                        fElementArray[fElementPointer] = null ;
                        return ;
                    }else{
                        fShouldSkip = false ;
                    }
                }
            }
            fElementPointer++ ;
        }
    
booleancanStore(short depth, short column)

        //colum = 0 , means first element at particular depth
        //column = 1, means second element at particular depth
        //        calle should make sure that it doesn't call for value outside allowed co-ordinates
        return fPointerInfo[depth][column] == 0 ? true : false ;
    
protected com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$DrivercreateContentDriver()
Creates a content Driver.

        return new FragmentContentDriver();
    
public voidendEntity(java.lang.String name, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
This method notifies the end of an entity. The DTD has the pseudo-name of "[dtd]" parameter entity names start with '%'; and general entities are just specified by their name.

param
name The name of the entity.
throws
XNIException Thrown by handler to signal an error.

        
        /**
         * // flush possible pending output buffer - see scanContent
         * if (fInScanContent && fStringBuffer.length != 0
         * && fDocumentHandler != null) {
         * fDocumentHandler.characters(fStringBuffer, null);
         * fStringBuffer.length = 0; // make sure we know it's been flushed
         * }
         */
        super.endEntity(name, augs);
        
        // make sure markup is properly balanced
        if (fMarkupDepth != fEntityStack[fEntityDepth]) {
            reportFatalError("MarkupEntityMismatch", null);
        }
        
        /**/
        // call handler
        if (fDocumentHandler != null && !fScanningAttribute) {
            if (!name.equals("[xml]")) {
                fDocumentHandler.endGeneralEntity(name, null);
            }
        }
        
        
    
public com.sun.org.apache.xerces.internal.util.XMLAttributesIteratorImplgetAttributeIterator()
return the attribute iterator implementation

        if(dtdGrammarUtil != null && fAddDefaultAttr){
            dtdGrammarUtil.addDTDDefaultAttrs(fElementQName,fAttributes);
            fAddDefaultAttr = false;
        }
        return fAttributes;
    
public com.sun.org.apache.xerces.internal.xni.XMLStringgetCharacterData()

        if(fUsebuffer){
            return fContentBuffer ;
        }else{
            return fTempString;
        }
        
    
public java.lang.StringgetComment()

        return fContentBuffer.toString();
    
public com.sun.org.apache.xerces.internal.xni.XMLDocumentHandlergetDocumentHandler()
Returns the document handler

        return fDocumentHandler;
    
public java.lang.StringgetDriverName(com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$Driver driver)
Returns the driver name.

        
        if (DEBUG_DISPATCHER) {
            if (driver != null) {
                String name = driver.getClass().getName();
                int index = name.lastIndexOf('.");
                if (index != -1) {
                    name = name.substring(index + 1);
                    index = name.lastIndexOf('$");
                    if (index != -1) {
                        name = name.substring(index + 1);
                    }
                }
                return name;
            }
        }
        return "null";
        
    
shortgetElementPointer(short depth, short column)

        //colum = 0 , means first element at particular depth
        //column = 1, means second element at particular depth
        //        calle should make sure that it doesn't call for value outside allowed co-ordinates
        return fPointerInfo[depth][column] ;
    
public com.sun.org.apache.xerces.internal.xni.QNamegetElementQName()

        if(fScannerLastState == XMLEvent.END_ELEMENT){
            fElementQName.setValues(fElementStack.getLastPoppedElement());
        }
        return fElementQName ;
    
public java.lang.StringgetEntityName()

        //return the cached name
        return fCurrentEntityName;
    
public java.lang.BooleangetFeatureDefault(java.lang.String featureId)
Returns the default state for a feature, or null if this component does not want to report a default value for this feature.

param
featureId The feature identifier.
since
Xerces 2.2.0

        for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) {
            if (RECOGNIZED_FEATURES[i].equals(featureId)) {
                return FEATURE_DEFAULTS[i];
            }
        }
        return null;
    
public com.sun.org.apache.xerces.internal.util.XMLStringBuffergetPIData()

        return fContentBuffer ;
    
public java.lang.StringgetPITarget()

        return fPITarget ;
    
public java.lang.ObjectgetPropertyDefault(java.lang.String propertyId)
Returns the default state for a property, or null if this component does not want to report a default value for this property.

param
propertyId The property identifier.
since
Xerces 2.2.0

        for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) {
            if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) {
                return PROPERTY_DEFAULTS[i];
            }
        }
        return null;
    
public java.lang.String[]getRecognizedFeatures()
Returns a list of feature identifiers that are recognized by this component. This method may return null if no features are recognized by this component.

        return (String[])(RECOGNIZED_FEATURES.clone());
    
public java.lang.String[]getRecognizedProperties()
Returns a list of property identifiers that are recognized by this component. This method may return null if no properties are recognized by this component.

        return (String[])(RECOGNIZED_PROPERTIES.clone());
    
protected java.lang.StringgetScannerStateName(int state)
Returns the scanner state name.

        
        switch (state) {
            case SCANNER_STATE_DOCTYPE: return "SCANNER_STATE_DOCTYPE";
            case SCANNER_STATE_ROOT_ELEMENT: return "SCANNER_STATE_ROOT_ELEMENT";
            case SCANNER_STATE_START_OF_MARKUP: return "SCANNER_STATE_START_OF_MARKUP";
            case SCANNER_STATE_COMMENT: return "SCANNER_STATE_COMMENT";
            case SCANNER_STATE_PI: return "SCANNER_STATE_PI";
            case SCANNER_STATE_CONTENT: return "SCANNER_STATE_CONTENT";
            case SCANNER_STATE_REFERENCE: return "SCANNER_STATE_REFERENCE";
            case SCANNER_STATE_END_OF_INPUT: return "SCANNER_STATE_END_OF_INPUT";
            case SCANNER_STATE_TERMINATED: return "SCANNER_STATE_TERMINATED";
            case SCANNER_STATE_CDATA: return "SCANNER_STATE_CDATA";
            case SCANNER_STATE_TEXT_DECL: return "SCANNER_STATE_TEXT_DECL";
            case SCANNER_STATE_ATTRIBUTE: return "SCANNER_STATE_ATTRIBUTE";
            case SCANNER_STATE_ATTRIBUTE_VALUE: return "SCANNER_STATE_ATTRIBUTE_VALUE";
            case SCANNER_STATE_START_ELEMENT_TAG: return "SCANNER_STATE_START_ELEMENT_TAG";
            case SCANNER_STATE_END_ELEMENT_TAG: return "SCANNER_STATE_END_ELEMENT_TAG";
            case SCANNER_STATE_CHARACTER_DATA: return "SCANNER_STATE_CHARACTER_DATA" ;
        }
        
        return "??? ("+state+')";
        
    
protected com.sun.org.apache.xerces.internal.xni.XMLStringgetString()
this function gets an XMLString (which is used to store the attribute value) from the special pool maintained for attributes. fAttributeCacheUsedCount tracks the number of attributes that has been consumed from the pool. if all the attributes has been consumed, it adds a new XMLString inthe pool and returns the same XMLString.

return
XMLString XMLString used to store an attribute value.

        if(fAttributeCacheUsedCount < initialCacheCount || fAttributeCacheUsedCount < attributeValueCache.size()){
            return (XMLString)attributeValueCache.get(fAttributeCacheUsedCount++);
        } else{
            XMLString str = new XMLString();
            fAttributeCacheUsedCount++;
            attributeValueCache.add(str);
            return str;
        }
    
private voidhandleCharacter(char c, java.lang.String entity, com.sun.org.apache.xerces.internal.util.XMLStringBuffer content)
Calls document handler with a single character resulting from built-in entity resolution.

param
c
param
entity built-in name
param
XMLStringBuffer append the character to buffer we really dont need to call this function -- this function is only required when we integrate with rest of Xerces2. SO maintaining the current behavior and still calling this function to hanlde built-in entity reference.

        foundBuiltInRefs = true;
        content.append(c);
        if (fDocumentHandler != null) {
            fSingleChar[0] = c;
            if (fNotifyBuiltInRefs) {
                fDocumentHandler.startGeneralEntity(entity, null, null, null);
            }
            fTempString.setValues(fSingleChar, 0, 1);
            //fDocumentHandler.characters(fTempString, null);
            
            if (fNotifyBuiltInRefs) {
                fDocumentHandler.endGeneralEntity(entity, null);
            }
        }
    
public booleanhasAttributes()

        return fAttributes.getLength() > 0 ? true : false ;
    
public booleanisStandAlone()
return if the doucment is standalone

        return fStandalone ;
    
public intnext()
return the next state on the input

return
int

        return fDriver.next();
    
static voidpr(java.lang.String str)

        System.out.println(str) ;
    
public voidrefresh()
Implements XMLBufferListener interface.

        refresh(0);
    
public voidrefresh(int refreshPosition)
receives callbacks from {@link XMLEntityReader } when buffer is being changed.

param
refreshPosition

        //If you are reading attributes and you got a callback
        //cache available attributes.
        if(fReadingAttributes){
            fAttributes.refresh();
        }
        if(fScannerState == SCANNER_STATE_CHARACTER_DATA){
            //since fTempString directly matches to the underlying main buffer
            //store the data into buffer
            fContentBuffer.append(fTempString);
            //clear the XMLString so that data can't be added again.
            fTempString.length = 0;
            fUsebuffer = true;
        }
    
public voidreset(com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager componentManager)
Resets the component. The component can query the component manager about any features and properties that affect the operation of the component.

param
componentManager The component manager.
throws
SAXException Thrown by component on initialization error. For example, if a feature or property is required for the operation of the component, the component manager may throw a SAXNotRecognizedException or a SAXNotSupportedException.

        
        super.reset(componentManager);
        
        // other settings
        // fDocumentSystemId = null;
                
        // sax features
        //fAttributes.setNamespaces(fNamespaces);
                
        // xerces features
        try{
            fReportCdataEvent = componentManager.getFeature(Constants.STAX_REPORT_CDATA_EVENT);
        } catch (XMLConfigurationException e) {
            e.printStackTrace();
            //note that default value of this feature is true in stax configuration
            fReportCdataEvent = true;
        }
        
        try {
            fSecurityManager = (SecurityManager)componentManager.getProperty(Constants.SECURITY_MANAGER);
        } catch (XMLConfigurationException e) {
            fSecurityManager = null;
        }
        fElementAttributeLimit = (fSecurityManager != null)?fSecurityManager.getElementAttrLimit():0;
        
        try {
            fNotifyBuiltInRefs = componentManager.getFeature(NOTIFY_BUILTIN_REFS);
        } catch (XMLConfigurationException e) {
            fNotifyBuiltInRefs = false;
        }
        
        try {
            Object resolver = componentManager.getProperty(ENTITY_RESOLVER);
            fExternalSubsetResolver = (resolver instanceof ExternalSubsetResolver) ?
                (ExternalSubsetResolver) resolver : null;
        } catch (XMLConfigurationException e) {
            fExternalSubsetResolver = null;
        }
                        
        // initialize vars
        fMarkupDepth = 0;
        fCurrentElement = null;
        fElementStack.clear();
        fHasExternalDTD = false;
        fStandalone = false;
        fInScanContent = false;
        //skipping algorithm
        fShouldSkip = false;
        fAdd = false;
        fSkip = false;
        
        //attribute
        fReadingAttributes = false;
        //xxx: external entities are supported in Xerces
        // it would be good to define feature for this case
        fSupportExternalEntities = true;
        fReplaceEntityReferences = true;
        fIsCoalesce = false;
        
        // setup Driver
        setScannerState(SCANNER_STATE_CONTENT);
        setDriver(fContentDriver);
        fEntityStore = fEntityManager.getEntityStore();
        
        dtdGrammarUtil = null;
                
        
        //fEntityManager.test();
    
public voidreset(com.sun.org.apache.xerces.internal.impl.PropertyManager propertyManager)

        
        super.reset(propertyManager);
        
        // other settings
        // fDocumentSystemId = null;
        fNamespaces = ((Boolean)propertyManager.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE)).booleanValue();
        fNotifyBuiltInRefs = false ;
                
        // initialize vars
        fMarkupDepth = 0;
        fCurrentElement = null;
        fShouldSkip = false;
        fAdd = false;
        fSkip = false;
        fElementStack.clear();
        //fElementStack2.clear();
        fHasExternalDTD = false;
        fStandalone = false;
        //fReplaceEntityReferences = true;
        //fSupportExternalEntities = true;
        Boolean bo = (Boolean)propertyManager.getProperty(XMLInputFactoryImpl.IS_REPLACING_ENTITY_REFERENCES);
        fReplaceEntityReferences = bo.booleanValue();
        bo = (Boolean)propertyManager.getProperty(XMLInputFactoryImpl.IS_SUPPORTING_EXTERNAL_ENTITIES);
        fSupportExternalEntities = bo.booleanValue();
        Boolean cdata = (Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.STAX_REPORT_CDATA_EVENT) ;
        if(cdata != null)
            fReportCdataEvent = cdata.booleanValue() ;
        Boolean coalesce = (Boolean)propertyManager.getProperty(XMLInputFactory.IS_COALESCING) ;
        if(coalesce != null)
            fIsCoalesce = coalesce.booleanValue();
        fReportCdataEvent = fIsCoalesce ? false : (fReportCdataEvent && true) ;
        //if fIsCoalesce is set to true, set the value of fReplaceEntityReferences to true,
        //if fIsCoalesce is set to false, take the value of fReplaceEntityReferences as set by application
        fReplaceEntityReferences = fIsCoalesce ? true : fReplaceEntityReferences;
        // setup Driver
        //we dont need to do this -- nb.
        //setScannerState(SCANNER_STATE_CONTENT);
        //setDriver(fContentDriver);
        fEntityStore = fEntityManager.getEntityStore();
        //fEntityManager.test();
        
        dtdGrammarUtil = null;
                
    
voidresetPointer(short depth, short column)

        fPointerInfo[depth] [column] = (short)0;
    
protected voidscanAttribute(com.sun.org.apache.xerces.internal.xni.XMLAttributes attributes)
Scans an attribute name value pair.

[41] Attribute ::= Name Eq AttValue

Note: This method assumes that the next character on the stream is the first character of the attribute name.

Note: This method uses the fAttributeQName and fQName variables. The contents of these variables will be destroyed.

param
attributes The attributes list for the scanned attribute.

        if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() +">>> scanAttribute()");
        
        // name
        if (fNamespaces) {
            fEntityScanner.scanQName(fAttributeQName);
        } else {
            String name = fEntityScanner.scanName();
            fAttributeQName.setValues(null, name, name, null);
        }
        
        // equals
        fEntityScanner.skipSpaces();
        if (!fEntityScanner.skipChar('=")) {
            reportFatalError("EqRequiredInAttribute",
                new Object[] {fCurrentElement.rawname, fAttributeQName.rawname});
        }
        fEntityScanner.skipSpaces();
        
        int attIndex = 0 ;
        //REVISIT: one more case needs to be included: external PE and standalone is no
        boolean isVC =  fHasExternalDTD && !fStandalone;
        //fTempString would store attribute value
        ///fTempString2 would store attribute non-normalized value
        
        //this function doesn't use 'attIndex'. We are adding the attribute later
        //after we have figured out that current attribute is not namespace declaration
        //since scanAttributeValue doesn't use attIndex parameter therefore we
        //can safely add the attribute later..
        XMLString tmpStr = getString();
        
        scanAttributeValue(tmpStr, fTempString2,
                fAttributeQName.rawname, attributes,
                attIndex, isVC);

        // content
        int oldLen = attributes.getLength();
        //if the attribute name already exists.. new value is replaced with old value
        attIndex = attributes.addAttribute(fAttributeQName, XMLSymbols.fCDATASymbol, null);
        
        // WFC: Unique Att Spec
        //attributes count will be same if the current attribute  name already exists for this element name.
        //this means there are two duplicate attributes.
        if (oldLen == attributes.getLength()) {
            reportFatalError("AttributeNotUnique",
                    new Object[]{fCurrentElement.rawname,
                            fAttributeQName.rawname});
        }
        
        //tmpString contains attribute value
        //we are passing null as the attribute value
        attributes.setValue(attIndex, null, tmpStr);

        ///xxx: nonNormalizedValue is not being set as it is not required by SAX & DOM
        //attributes.setNonNormalizedValue(oldLen, fTempString2.toString());
        attributes.setSpecified(attIndex, true);
        
        if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() +"<<< scanAttribute()");
        
    
protected booleanscanCDATASection(com.sun.org.apache.xerces.internal.util.XMLStringBuffer contentBuffer, boolean complete)
Scans a CDATA section.

Note: This method uses the fTempString and fStringBuffer variables.

param
complete True if the CDATA section is to be scanned completely.
return
True if CDATA is completely scanned.

        
        // call handler
        if (fDocumentHandler != null) {
            //fDocumentHandler.startCDATA(null);
        }
        
        while (true) {
            //scanData will fill the contentBuffer
            if (!fEntityScanner.scanData("]]>", contentBuffer)) {
                break ;
                /** We dont need all this code if we pass ']]>' as delimeter..
                 * int brackets = 2;
                 * while (fEntityScanner.skipChar(']')) {
                 * brackets++;
                 * }
                 *
                 * //When we find more than 2 square brackets
                 * if (fDocumentHandler != null && brackets > 2) {
                 * //we dont need to clear the buffer..
                 * //contentBuffer.clear();
                 * for (int i = 2; i < brackets; i++) {
                 * contentBuffer.append(']');
                 * }
                 * fDocumentHandler.characters(contentBuffer, null);
                 * }
                 *
                 * if (fEntityScanner.skipChar('>')) {
                 * break;
                 * }
                 * if (fDocumentHandler != null) {
                 * //we dont need to clear the buffer now..
                 * //contentBuffer.clear();
                 * contentBuffer.append("]]");
                 * fDocumentHandler.characters(contentBuffer, null);
                 * }
                 **/
            } else {
                int c = fEntityScanner.peekChar();
                if (c != -1 && isInvalidLiteral(c)) {
                    if (XMLChar.isHighSurrogate(c)) {
                        //contentBuffer.clear();
                        //scan surrogates if any....
                        scanSurrogates(contentBuffer);
                    } else {
                        reportFatalError("InvalidCharInCDSect",
                                new Object[]{Integer.toString(c,16)});
                                fEntityScanner.scanChar();
                    }
                }
                //by this time we have also read surrogate contents if any...
                if (fDocumentHandler != null) {
                    //fDocumentHandler.characters(contentBuffer, null);
                }
            }
        }
        fMarkupDepth--;
        
        if (fDocumentHandler != null && contentBuffer.length > 0) {
            //fDocumentHandler.characters(contentBuffer, null);
        }
        
        // call handler
        if (fDocumentHandler != null) {
            //fDocumentHandler.endCDATA(null);
        }
        
        return true;
        
    
protected voidscanCharReference()
Scans a character reference.

[66] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'

        
        fStringBuffer2.clear();
        int ch = scanCharReferenceValue(fStringBuffer2, null);
        fMarkupDepth--;
        if (ch != -1) {
            // call handler
            
            if (fDocumentHandler != null) {
                if (fNotifyCharRefs) {
                    fDocumentHandler.startGeneralEntity(fCharRefLiteral, null, null, null);
                }
                Augmentations augs = null;
                if (fValidation && ch <= 0x20) {
                    if (fTempAugmentations != null) { 
                        fTempAugmentations.removeAllItems();
                    }
                    else {
                        fTempAugmentations = new AugmentationsImpl();
                    }
                    augs = fTempAugmentations;
                    augs.putItem(Constants.CHAR_REF_PROBABLE_WS, Boolean.TRUE);
                }
                //xxx: How do we deal with this - how to return charReferenceValues
                //now this is being commented because this is taken care in scanDocument()
                //fDocumentHandler.characters(fStringBuffer2, null);
                if (fNotifyCharRefs) {
                    fDocumentHandler.endGeneralEntity(fCharRefLiteral, null);
                }
            }
        }
        
    
protected voidscanComment()
Scans a comment.

[15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'

Note: Called after scanning past '<!--'

        fContentBuffer.clear();
        scanComment(fContentBuffer);
        //getTextCharacters can also be called for reading comments
        fUsebuffer = true;
        fMarkupDepth--;
        
    
protected intscanContent(com.sun.org.apache.xerces.internal.util.XMLStringBuffer content)
Scans element content.

return
Returns the next character on the stream.

        //set the fTempString length to 0 before passing it on to scanContent
        //scanContent sets the correct co-ordinates as per the content read
        fTempString.length = 0;
        int c = fEntityScanner.scanContent(fTempString);
        content.append(fTempString);
        fTempString.length = 0;
        if (c == '\r") {
            // happens when there is the character reference 
            //xxx: We know the next chracter.. we should just skip it and add ']' directlry
            fEntityScanner.scanChar();
            content.append((char)c);
            c = -1;
        } else if (c == ']") {
            //fStringBuffer.clear();
            //xxx: We know the next chracter.. we should just skip it and add ']' directlry
            content.append((char)fEntityScanner.scanChar());
            // remember where we are in case we get an endEntity before we
            // could flush the buffer out - this happens when we're parsing an
            // entity which ends with a ]
            fInScanContent = true;
            //
            // We work on a single character basis to handle cases such as:
            // ']]]>' which we might otherwise miss.
            //
            if (fEntityScanner.skipChar(']")) {
                content.append(']");
                while (fEntityScanner.skipChar(']")) {
                    content.append(']");
                }
                if (fEntityScanner.skipChar('>")) {
                    reportFatalError("CDEndInContent", null);
                }
            }
            fInScanContent = false;
            c = -1;
        }
        if (fDocumentHandler != null && content.length > 0) {
            //fDocumentHandler.characters(content, null);
        }
        return c;
        
    
public booleanscanDocument(boolean complete)
Scans a document.

param
complete True if the scanner should scan the document completely, pushing all events to the registered document handler. A value of false indicates that that the scanner should only scan the next portion of the document and return. A scanner instance is permitted to completely scan a document if it does not support this "pull" scanning model.
return
True if there is more to scan, false otherwise.

        
        // keep dispatching "events"
        fEntityManager.setEntityHandler(this);
        //System.out.println(" get Document Handler in NSDocumentHandler " + fDocumentHandler );
        
        int event = next();
        do {
            switch (event) {
                case XMLStreamConstants.START_DOCUMENT :
                    //fDocumentHandler.startDocument(fEntityManager.getEntityScanner(),fEntityManager.getEntityScanner().getVersion(),fNamespaceContext,null);// not able to get
                    break;
                case XMLStreamConstants.START_ELEMENT :
                    //System.out.println(" in scann element");
                    //fDocumentHandler.startElement(getElementQName(),fAttributes,null);
                    break;
                case XMLStreamConstants.CHARACTERS :
                    fDocumentHandler.characters(getCharacterData(),null);
                    break;
                case XMLStreamConstants.SPACE:
                    //check if getCharacterData() is the right function to retrieve ignorableWhitespace information.
                    //System.out.println("in the space");
                    //fDocumentHandler.ignorableWhitespace(getCharacterData(), null);
                    break;
                case XMLStreamConstants.ENTITY_REFERENCE :
                    //entity reference callback are given in startEntity
                    break;
                case XMLStreamConstants.PROCESSING_INSTRUCTION :
                    fDocumentHandler.processingInstruction(getPITarget(),getPIData(),null);
                    break;
                case XMLStreamConstants.COMMENT :
                    //System.out.println(" in COMMENT of the XMLNSDocumentScannerImpl");
                    fDocumentHandler.comment(getCharacterData(),null);
                    break;
                case XMLStreamConstants.DTD :
                    //all DTD related callbacks are handled in DTDScanner.
                    //1. Stax doesn't define DTD states as it does for XML Document.
                    //therefore we don't need to take care of anything here. So Just break;
                    break;
                case XMLStreamConstants.CDATA:
                    fDocumentHandler.startCDATA(null);
                    //xxx: check if CDATA values comes from getCharacterData() function
                    fDocumentHandler.characters(getCharacterData(),null);
                    fDocumentHandler.endCDATA(null);
                    //System.out.println(" in CDATA of the XMLNSDocumentScannerImpl");
                    break;
                case XMLStreamConstants.NOTATION_DECLARATION :
                    break;
                case XMLStreamConstants.ENTITY_DECLARATION :
                    break;
                case XMLStreamConstants.NAMESPACE :
                    break;
                case XMLStreamConstants.ATTRIBUTE :
                    break;
                case XMLStreamConstants.END_ELEMENT :
                    //do not give callback here. 
                    //this callback is given in scanEndElement function.
                    //fDocumentHandler.endElement(getElementQName(),null);
                    break;
                default :
                    throw new InternalError("processing event: " + event);
                    
            }
            //System.out.println("here in before calling next");
            event = next();
            //System.out.println("here in after calling next");
        } while (event!=XMLStreamConstants.END_DOCUMENT && complete);
        
        if(event == XMLStreamConstants.END_DOCUMENT) {            
            fDocumentHandler.endDocument(null);
            return false;
        }
        
        return true;
        
    
protected intscanEndElement()
Scans an end element.

[42] ETag ::= '</' Name S? '>'

Note: This method uses the fElementQName variable. The contents of this variable will be destroyed. The caller should copy the needed information out of this variable before calling this method.

return
The element depth.

        if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() +">>> scanEndElement()");
        
        // pop context
        QName endElementName = fElementStack.popElement();
        
        String rawname = endElementName.rawname;
        if(DEBUG)System.out.println("endElementName = " + endElementName.toString());
        // Take advantage of the fact that next string _should_ be "fElementQName.rawName",
        //In scanners most of the time is consumed on checks done for XML characters, we can
        // optimize on it and avoid the checks done for endElement,
        //we will also avoid symbol table lookup - neeraj.bajaj@sun.com
        
        // this should work both for namespace processing true or false...
        
        //REVISIT: if the string is not the same as expected.. we need to do better error handling..
        //We can skip this for now... In any case if the string doesn't match -- document is not well formed.
        
        if (!fEntityScanner.skipString(endElementName.rawname)) {
             reportFatalError("ETagRequired", new Object[]{rawname});
        }
        
        // end
        fEntityScanner.skipSpaces();
        if (!fEntityScanner.skipChar('>")) {
            reportFatalError("ETagUnterminated",
                    new Object[]{rawname});
        }
        fMarkupDepth--;
        
        //we have increased the depth for two markup "<" characters
        fMarkupDepth--;
        
        // check that this element was opened in the same entity
        if (fMarkupDepth < fEntityStack[fEntityDepth - 1]) {
            reportFatalError("ElementEntityMismatch",
                    new Object[]{rawname});
        }
        
        //We should not be popping out the context here in endELement becaause the namespace context is still
        //valid when parser is at the endElement state.
        
        //if (fNamespaces) {
        //  fNamespaceContext.popContext();
        //}
        
        // call handler
        if (fDocumentHandler != null ) {            
            //end element is scanned in this function so we can send a callback
            //here.
            //<strong>we shouldn't be sending callback in scanDocument()</strong>                
            
            fDocumentHandler.endElement(endElementName, null);
        }
        if(dtdGrammarUtil != null)
            dtdGrammarUtil.endElement(endElementName);
        
        return fMarkupDepth;
        
    
protected voidscanEntityReference(com.sun.org.apache.xerces.internal.util.XMLStringBuffer content)
Scans an entity reference.

return
returns true if the new entity is started. If it was built-in entity 'false' is returned.
throws
IOException Thrown if i/o error occurs.
throws
XNIException Thrown if handler throws exception upon notification.

        String name = fEntityScanner.scanName();
        if (name == null) {
            reportFatalError("NameRequiredInReference", null);
        }
        if (!fEntityScanner.skipChar(';")) {
            reportFatalError("SemicolonRequiredInReference", new Object []{name});
        }
        if (fEntityStore.isUnparsedEntity(name)) {
            reportFatalError("ReferenceToUnparsedEntity", new Object[]{name});
        }
        fMarkupDepth--;
        fCurrentEntityName = name;
        
        // handle built-in entities
        if (name == fAmpSymbol) {
            handleCharacter('&", fAmpSymbol, content);
            fScannerState = SCANNER_STATE_BUILT_IN_REFS;
            return ;
        } else if (name == fLtSymbol) {
            handleCharacter('<", fLtSymbol, content);
            fScannerState = SCANNER_STATE_BUILT_IN_REFS;
            return ;
        } else if (name == fGtSymbol) {
            handleCharacter('>", fGtSymbol, content);
            fScannerState = SCANNER_STATE_BUILT_IN_REFS;
            return ;
        } else if (name == fQuotSymbol) {
            handleCharacter('"", fQuotSymbol, content);
            fScannerState = SCANNER_STATE_BUILT_IN_REFS;
            return ;
        } else if (name == fAposSymbol) {
            handleCharacter('\'", fAposSymbol, content);
            fScannerState = SCANNER_STATE_BUILT_IN_REFS;
            return ;
        }
        
        //1. if the entity is external and support to external entities is not required
        // 2. or entities should not be replaced
        //3. or if it is built in entity reference.
        if((fEntityStore.isExternalEntity(name) && !fSupportExternalEntities) || (!fEntityStore.isExternalEntity(name) && !fReplaceEntityReferences) || foundBuiltInRefs){
            fScannerState = SCANNER_STATE_REFERENCE;
            return ;
        }
        // start general entity
        if (!fEntityStore.isDeclaredEntity(name)) {
            //SUPPORT_DTD=false && ReplaceEntityReferences should throw exception
            if (fDisallowDoctype && fReplaceEntityReferences) {
                reportFatalError("EntityNotDeclared", new Object[]{name});
                return;
            }
            //REVISIT: one more case needs to be included: external PE and standalone is no
            if ( fHasExternalDTD && !fStandalone) {
                if (fValidation)
                    fErrorReporter.reportError(fEntityScanner, XMLMessageFormatter.XML_DOMAIN,"EntityNotDeclared",
                            new Object[]{name}, XMLErrorReporter.SEVERITY_ERROR);
            } else
                reportFatalError("EntityNotDeclared", new Object[]{name});
        }
        //we are starting the entity even if the entity was not declared
        //if that was the case it its taken care in XMLEntityManager.startEntity()
        //we immediately call the endEntity. Application gets to know if there was
        //any entity that was not declared.
        fEntityManager.startEntity(name, false);
        //set the scaner state to content.. parser will automatically revive itself at any point of time.
        //setScannerState(SCANNER_STATE_CONTENT);
        //return true ;
    
protected voidscanPIData(java.lang.String target, com.sun.org.apache.xerces.internal.util.XMLStringBuffer data)
Scans a processing data. This is needed to handle the situation where a document starts with a processing instruction whose target name starts with "xml". (e.g. xmlfoo)

param
target The PI target
param
data The XMLStringBuffer to fill in with the data

        
        super.scanPIData(target, data);
        
        //set the PI target and values
        fPITarget = target ;
        
        fMarkupDepth--;
        
    
protected booleanscanStartElement()
Scans a start element. This method will handle the binding of namespace information and notifying the handler of the start of the element.

[44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
[40] STag ::= '<' Name (S Attribute)* S? '>'

Note: This method assumes that the leading '<' character has been consumed.

Note: This method uses the fElementQName and fAttributes variables. The contents of these variables will be destroyed. The caller should copy important information out of these variables before calling this method. NB: Content in fAttributes is valid only till the state of the parser is XMLEvent.START_ELEMENT

return
True if element is empty. (i.e. It matches production [44].

        
        if (DEBUG_START_END_ELEMENT) System.out.println( this.getClass().toString() + ">>> scanStartElement()");
        //when skipping is true and no more elements should be added
        if(fSkip && !fAdd){
            //get the stored element -- if everything goes right this should match the
            //token in the buffer
            
            QName name = fElementStack.getNext();
            
            if(DEBUG_SKIP_ALGORITHM){
                System.out.println("Trying to skip String = " + name.rawname);
            }
            
            //Be conservative -- if skipping fails -- stop.
            fSkip = fEntityScanner.skipString(name.rawname);
                        
            if(fSkip){
                if(DEBUG_SKIP_ALGORITHM){
                    System.out.println("Element SUCESSFULLY skipped = " + name.rawname);
                }
                fElementStack.push();
                fElementQName = name;
            }else{
                //if skipping fails reposition the stack or fallback to normal way of processing
                fElementStack.reposition();
                if(DEBUG_SKIP_ALGORITHM){
                    System.out.println("Element was NOT skipped, REPOSITIONING stack" );
                }
            }
        }
        
        //we are still at the stage of adding elements
        //the elements were not matched or
        //fSkip is not set to true
        if(!fSkip || fAdd){
            //get the next element from the stack
            fElementQName = fElementStack.nextElement();
            // name
            if (fNamespaces) {
                fEntityScanner.scanQName(fElementQName);
            } else {
                String name = fEntityScanner.scanName();
                fElementQName.setValues(null, name, name, null);
            }
            
            if(DEBUG)System.out.println("Element scanned in start element is " + fElementQName.toString());
            if(DEBUG_SKIP_ALGORITHM){
                if(fAdd){
                    System.out.println("Elements are being ADDED -- elemet added is = " + fElementQName.rawname + " at count = " + fElementStack.fCount);
                }
            }
            
        }
        
        //when the elements are being added , we need to check if we are set for skipping the elements
        if(fAdd){
            //this sets the value of fAdd variable
            fElementStack.matchElement(fElementQName);
        }
        
        
        //xxx: We dont need another pointer, fCurrentElement, we can use fElementQName
        fCurrentElement = fElementQName;
                
        String rawname = fElementQName.rawname;
        
        fEmptyElement = false;
        
        fAttributes.removeAllAttributes();
        
        if(!seekCloseOfStartTag()){
            fReadingAttributes = true;
            fAttributeCacheUsedCount =0;
            fStringBufferIndex =0;
            fAddDefaultAttr = true;
            do {
                scanAttribute(fAttributes);
                if (fSecurityManager != null && fAttributes.getLength() > fElementAttributeLimit){  
                    fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
                                                 "ElementAttributeLimit",
                                                 new Object[]{rawname, new Integer(fAttributes.getLength()) },
                                                 XMLErrorReporter.SEVERITY_FATAL_ERROR );
                }
                
            } while (!seekCloseOfStartTag());
            fReadingAttributes=false;
        }
        
        if (fEmptyElement) {
            //decrease the markup depth..
            fMarkupDepth--;
            
            // check that this element was opened in the same entity
            if (fMarkupDepth < fEntityStack[fEntityDepth - 1]) {
                reportFatalError("ElementEntityMismatch",
                        new Object[]{fCurrentElement.rawname});
            }
            // call handler
            if (fDocumentHandler != null) {
                fDocumentHandler.emptyElement(fElementQName, fAttributes, null);
            }
            
            //We should not be popping out the context here in endELement becaause the namespace context is still
            //valid when parser is at the endElement state.            
            //if (fNamespaces) {
            //  fNamespaceContext.popContext();
            //}
            
            //pop the element off the stack..
            fElementStack.popElement();
            
        } else {
            
            if(dtdGrammarUtil != null)
                dtdGrammarUtil.startElement(fElementQName, fAttributes); 
            if(fDocumentHandler != null){
                //complete element and attributes are traversed in this function so we can send a callback
                //here.
                //<strong>we shouldn't be sending callback in scanDocument()</strong>                                
                fDocumentHandler.startElement(fElementQName, fAttributes, null);
            }
        }
        
        
        if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() + "<<< scanStartElement(): "+fEmptyElement);
        return fEmptyElement;
        
    
protected voidscanXMLDeclOrTextDecl(boolean scanningTextDecl)
Scans an XML or text declaration.

[23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
[24] VersionInfo ::= S 'version' Eq (' VersionNum ' | " VersionNum ")
[80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" )
[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
[32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'")
| ('"' ('yes' | 'no') '"'))

[77] TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>'

param
scanningTextDecl True if a text declaration is to be scanned instead of an XML declaration.

        
        // scan decl
        super.scanXMLDeclOrTextDecl(scanningTextDecl, fStrings);
        fMarkupDepth--;
        
        // pseudo-attribute values
        String version = fStrings[0];
        String encoding = fStrings[1];
        String standalone = fStrings[2];
        fDeclaredEncoding = encoding;
        // set standalone
        fStandalone = standalone != null && standalone.equals("yes");
        ///xxx see where its used.. this is not used anywhere. it may be useful for entity to store this information
        //but this information is only related with Document Entity.
        fEntityManager.setStandalone(fStandalone);
        
        
        // call handler
        if (fDocumentHandler != null) {
            if (scanningTextDecl) {
                fDocumentHandler.textDecl(version, encoding, null);
            } else {
                fDocumentHandler.xmlDecl(version, encoding, standalone, null);
            }
        }
       
        if(version != null){
            fEntityScanner.setVersion(version);
            fEntityScanner.setXMLVersion(version);
        }
        // set encoding on reader, only if encoding was not specified by the application explicitly
        if (encoding != null && !fEntityScanner.getCurrentEntity().isEncodingExternallySpecified()) {
             fEntityScanner.setEncoding(encoding);
        }
        
    
protected booleanseekCloseOfStartTag()
Looks for the close of start tag, i.e. if it finds '>' or '/>' Characters are consumed.

        // spaces
        boolean sawSpace = fEntityScanner.skipSpaces();
        
        // end tag?
        final int c = fEntityScanner.peekChar();
        if (c == '>") {
            fEntityScanner.scanChar();
            return true;
        } else if (c == '/") {
            fEntityScanner.scanChar();
            if (!fEntityScanner.skipChar('>")) {
                reportFatalError("ElementUnterminated",
                        new Object[]{fElementQName.rawname});
            }
            fEmptyElement = true;
            return true;
        } else if (!isValidNameStartChar(c) || !sawSpace) {
            reportFatalError("ElementUnterminated", new Object[]{fElementQName.rawname});
        }
        
        return false;
    
public voidsetDocumentHandler(com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler documentHandler)
setDocumentHandler

param
documentHandler

        fDocumentHandler = documentHandler;
        //System.out.println(" In Set DOCUMENT HANDLER" + fDocumentHandler + " scanner =" + this);
    
protected final voidsetDriver(com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$Driver driver)
Sets the Driver.

param
Driver The new Driver.

        fDriver = driver;
        if (DEBUG_DISPATCHER) {
            System.out.print("%%% setDriver: ");
            System.out.print(getDriverName(driver));
            System.out.println();
        }
    
public voidsetFeature(java.lang.String featureId, boolean state)
Sets the state of a feature. This method is called by the component manager any time after reset when a feature changes state.

Note: Components should silently ignore features that do not affect the operation of the component.

param
featureId The feature identifier.
param
state The state of the feature.
throws
SAXNotRecognizedException The component should not throw this exception.
throws
SAXNotSupportedException The component should not throw this exception.

        
        super.setFeature(featureId, state);
        
        // Xerces properties
        if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
            String feature = featureId.substring(Constants.XERCES_FEATURE_PREFIX.length());
            if (feature.equals(Constants.NOTIFY_BUILTIN_REFS_FEATURE)) {
                fNotifyBuiltInRefs = state;
            }
        }
        
    
public voidsetInputSource(com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource inputSource)
Sets the input source.

param
inputSource The input source.
throws
IOException Thrown on i/o error.

        fEntityManager.setEntityHandler(this);
        fEntityManager.startEntity("$fragment$", inputSource, false, true);
        // fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId());
    
public voidsetProperty(java.lang.String propertyId, java.lang.Object value)
Sets the value of a property. This method is called by the component manager any time after reset when a property changes value.

Note: Components should silently ignore properties that do not affect the operation of the component.

param
propertyId The property identifier.
param
value The value of the property.
throws
SAXNotRecognizedException The component should not throw this exception.
throws
SAXNotSupportedException The component should not throw this exception.

        
        super.setProperty(propertyId, value);
        
        // Xerces properties
        if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
            final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
            if (suffixLength == Constants.ENTITY_MANAGER_PROPERTY.length() &&
                    propertyId.endsWith(Constants.ENTITY_MANAGER_PROPERTY)) {
                fEntityManager = (XMLEntityManager)value;
                return;
            }
            if (suffixLength == Constants.ENTITY_RESOLVER_PROPERTY.length() &&
                    propertyId.endsWith(Constants.ENTITY_RESOLVER_PROPERTY)) {
                fExternalSubsetResolver = (value instanceof ExternalSubsetResolver) ?
                    (ExternalSubsetResolver) value : null;
                return;
            }
        }
        
        
                // Xerces properties
        if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
            String property = propertyId.substring(Constants.XERCES_PROPERTY_PREFIX.length());
            if (property.equals(Constants.ENTITY_MANAGER_PROPERTY)) {
                fEntityManager = (XMLEntityManager)value;
            }
            return;
        }
        
    
protected final voidsetScannerState(int state)
Sets the scanner state.

param
state The new scanner state.

        
        fScannerState = state;
        if (DEBUG_SCANNER_STATE) {
            System.out.print("### setScannerState: ");
            //System.out.print(fScannerState);
            System.out.print(getScannerStateName(state));
            System.out.println();
        }
        
    
protected booleanskipElement()

        
        if(!fShouldSkip) return false ;
        
        if(fLastPointerLocation != 0){
            //Look at the next element stored in the array list.. we might just get a match.
            String rawname = fElementArray[fLastPointerLocation + 1] ;
            if(rawname != null && skipFromTheBuffer(rawname)){
                fLastPointerLocation++ ;
                if(DEBUG_SKIP_ALGORITHM){
                    System.out.println("Element " + fElementRawname + " was SKIPPED at pointer location = " + fLastPointerLocation);
                }
                return true ;
            } else{
                //reset it back to zero... we haven't got the correct subset yet.
                fLastPointerLocation = 0 ;
                
            }
        }
        //xxx: we can put some logic here as from what column it should start looking
        //for now we always start at 0
        //fallback to tolerant algorithm, it would look for differnt element stored at different
        //depth and get us the pointer location.
        return fShouldSkip && skipElement((short)0);
        
    
booleanskipElement(short column)

        short depth = (short)fElementStack.fDepth ;
        
        if(depth > MAX_DEPTH_LIMIT){
            return fShouldSkip = false ;
        }
        for(short i = column ; i < MAX_POINTER_AT_A_DEPTH ; i++){
            short pointer = getElementPointer(depth , i ) ;
            
            if(pointer == 0){
                return fShouldSkip = false ;
            }
            
            if(fElementArray[pointer] != null && skipFromTheBuffer(fElementArray[pointer])){
                if(DEBUG_SKIP_ALGORITHM){
                    System.out.println();
                    System.out.println("Element " + fElementRawname + " was SKIPPED at depth = " + fElementStack.fDepth + " column = " + column );
                    System.out.println();
                }
                fLastPointerLocation = pointer ;
                return fShouldSkip = true ;
            }
        }
        return fShouldSkip = false ;
    
booleanskipFromTheBuffer(java.lang.String rawname)

        if(fEntityScanner.skipString(rawname)){
            char c = (char)fEntityScanner.peekChar() ;
            //If the start element was completely skipped we should encounter either ' '(space),
            //or '/' (in case of empty element)  or '>'
            if( c == ' " || c == '/" || c == '>"){
                fElementRawname = rawname ;
                return true ;
            } else{
                return false;
            }
        } else
            return false ;
    
booleanskipQElement(java.lang.String rawname)

        
        final int c = fEntityScanner.getChar(rawname.length());
        //if this character is still valid element name -- this means string can't match
        if(XMLChar.isName(c)){
            return false;
        }else{
            return fEntityScanner.skipString(rawname);
        }
    
public voidstartEntity(java.lang.String name, com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier identifier, java.lang.String encoding, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
This method notifies of the start of an entity. The DTD has the pseudo-name of "[dtd]" parameter entity names start with '%'; and general entities are just specified by their name.

param
name The name of the entity.
param
identifier The resource identifier.
param
encoding The auto-detected IANA encoding name of the entity stream. This value will be null in those situations where the entity encoding is not auto-detected (e.g. internal entities or a document entity that is parsed from a java.io.Reader).
throws
XNIException Thrown by handler to signal an error.

        
        // keep track of this entity before fEntityDepth is increased
        if (fEntityDepth == fEntityStack.length) {
            int[] entityarray = new int[fEntityStack.length * 2];
            System.arraycopy(fEntityStack, 0, entityarray, 0, fEntityStack.length);
            fEntityStack = entityarray;
        }
        fEntityStack[fEntityDepth] = fMarkupDepth;
        
        super.startEntity(name, identifier, encoding, augs);
        
        // WFC:  entity declared in external subset in standalone doc
        if(fStandalone && fEntityStore.isEntityDeclInExternalSubset(name)) {
            reportFatalError("MSG_REFERENCE_TO_EXTERNALLY_DECLARED_ENTITY_WHEN_STANDALONE",
                    new Object[]{name});
        }
        
        /** we are not calling the handlers yet.. */
        // call handler
        if (fDocumentHandler != null && !fScanningAttribute) {
            if (!name.equals("[xml]")) {
                fDocumentHandler.startGeneralEntity(name, identifier, encoding, null);
            }
        }
        
    
shortstorePointerForADepth(short elementPointer)

        short depth = (short) fElementStack.fDepth ;
        
        //Stores element pointer locations at particular depth , only 4 pointer locations
        //are stored at particular depth for now.
        for(short i = 0 ; i < MAX_POINTER_AT_A_DEPTH ; i++){
            
            if(canStore(depth, i)){
                fPointerInfo[depth][i] = elementPointer ;
                if(DEBUG_SKIP_ALGORITHM){
                    StringBuffer sb = new StringBuffer() ;
                    sb.append(" Pointer information ") ;
                    sb.append(" fElementPointer = " + fElementPointer) ;
                    sb.append(" fElementStack.fDepth = " + fElementStack.fDepth);
                    sb.append(" column = " + i ) ;
                    System.out.println(sb.toString()) ;
                }
                return i;
            }
            //else
            //pointer was not stored because we reached the limit
        }
        return -1 ;