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

Print this page




 366     /** Making the buffer accesible to derived class -- String buffer. */
 367     protected XMLStringBuffer fStringBuffer2 = new XMLStringBuffer();
 368 
 369     /** stores character data. */
 370     /** Making the buffer accesible to derived class -- stores PI data */
 371     protected XMLStringBuffer fContentBuffer = new XMLStringBuffer();
 372 
 373     /** Single character array. */
 374     private final char[] fSingleChar = new char[1];
 375     private String fCurrentEntityName = null;
 376 
 377     // New members
 378     protected boolean fScanToEnd = false;
 379 
 380     protected DTDGrammarUtil dtdGrammarUtil= null;
 381 
 382     protected boolean fAddDefaultAttr = false;
 383 
 384     protected boolean foundBuiltInRefs = false;
 385 


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


1932      * built-in entity resolution.
1933      *
1934      * @param c
1935      * @param entity built-in name
1936      * @param XMLStringBuffer append the character to buffer
1937      *
1938      * we really dont need to call this function -- this function is only required when
1939      * we integrate with rest of Xerces2. SO maintaining the current behavior and still
1940      * calling this function to hanlde built-in entity reference.
1941      *
1942      */
1943     private void handleCharacter(char c, String entity, XMLStringBuffer content) throws XNIException {
1944         foundBuiltInRefs = true;
1945         content.append(c);
1946         if (fDocumentHandler != null) {
1947             fSingleChar[0] = c;
1948             if (fNotifyBuiltInRefs) {
1949                 fDocumentHandler.startGeneralEntity(entity, null, null, null);
1950             }
1951             fTempString.setValues(fSingleChar, 0, 1);
1952             //fDocumentHandler.characters(fTempString, null);



1953 
1954             if (fNotifyBuiltInRefs) {
1955                 fDocumentHandler.endGeneralEntity(entity, null);
1956             }
1957         }
1958     } // handleCharacter(char)
1959 
1960     // helper methods
1961 
1962     /**
1963      * Sets the scanner state.
1964      *
1965      * @param state The new scanner state.
1966      */
1967     protected final void setScannerState(int state) {
1968 
1969         fScannerState = state;
1970         if (DEBUG_SCANNER_STATE) {
1971             System.out.print("### setScannerState: ");
1972             //System.out.print(fScannerState);


3051                         }//if we dont need to coalesce clear the buffer
3052                         else{
3053                             fContentBuffer.clear();
3054                         }
3055                         fUsebuffer = true ;
3056                         //take care of character reference
3057                         if (fEntityScanner.skipChar('#')) {
3058                             scanCharReferenceValue(fContentBuffer, null);
3059                             fMarkupDepth--;
3060                             if(!fIsCoalesce){
3061                                 setScannerState(SCANNER_STATE_CONTENT);
3062                                 return XMLEvent.CHARACTERS;
3063                             }
3064                         } else {
3065                             // this function also starts new entity
3066                             scanEntityReference(fContentBuffer);
3067                             //if there was built-in entity reference & coalesce is not true
3068                             //return CHARACTERS
3069                             if(fScannerState == SCANNER_STATE_BUILT_IN_REFS && !fIsCoalesce){
3070                                 setScannerState(SCANNER_STATE_CONTENT);




3071                                 return XMLEvent.CHARACTERS;
3072                             }

3073 
3074                             //if there was a text declaration, call next() it will be taken care.
3075                             if(fScannerState == SCANNER_STATE_TEXT_DECL){
3076                                 fLastSectionWasEntityReference = true ;
3077                                 continue;
3078                             }
3079 
3080                             if(fScannerState == SCANNER_STATE_REFERENCE){
3081                                 setScannerState(SCANNER_STATE_CONTENT);
3082                                 if (fReplaceEntityReferences && fEntityStore.isDeclaredEntity(fCurrentEntityName)) {
3083                                     // Skip the entity reference, we don't care
3084                                     continue;
3085                                 }
3086                                 return XMLEvent.ENTITY_REFERENCE;
3087                             }
3088                         }
3089                         //Wether it was character reference, entity reference or built-in entity
3090                         //set the next possible state to SCANNER_STATE_CONTENT
3091                         setScannerState(SCANNER_STATE_CONTENT);
3092                         fLastSectionWasEntityReference = true ;




 366     /** Making the buffer accesible to derived class -- String buffer. */
 367     protected XMLStringBuffer fStringBuffer2 = new XMLStringBuffer();
 368 
 369     /** stores character data. */
 370     /** Making the buffer accesible to derived class -- stores PI data */
 371     protected XMLStringBuffer fContentBuffer = new XMLStringBuffer();
 372 
 373     /** Single character array. */
 374     private final char[] fSingleChar = new char[1];
 375     private String fCurrentEntityName = null;
 376 
 377     // New members
 378     protected boolean fScanToEnd = false;
 379 
 380     protected DTDGrammarUtil dtdGrammarUtil= null;
 381 
 382     protected boolean fAddDefaultAttr = false;
 383 
 384     protected boolean foundBuiltInRefs = false;
 385 
 386     /** Built-in reference character event */
 387     protected boolean builtInRefCharacterHandled = false;
 388 
 389     //skip element algorithm
 390     static final short MAX_DEPTH_LIMIT = 5 ;
 391     static final short ELEMENT_ARRAY_LENGTH = 200 ;
 392     static final short MAX_POINTER_AT_A_DEPTH = 4 ;
 393     static final boolean DEBUG_SKIP_ALGORITHM = false;
 394     //create a elemnet array of length equal to ELEMENT_ARRAY_LENGTH
 395     String [] fElementArray = new String[ELEMENT_ARRAY_LENGTH] ;
 396     //pointer location where last element was skipped
 397     short fLastPointerLocation = 0 ;
 398     short fElementPointer = 0 ;
 399     //2D array to store pointer info
 400     short [] [] fPointerInfo = new short[MAX_DEPTH_LIMIT] [MAX_POINTER_AT_A_DEPTH] ;
 401     protected String fElementRawname ;
 402     protected boolean fShouldSkip = false;
 403     protected boolean fAdd = false ;
 404     protected boolean fSkip = false;
 405 
 406     /** Reusable Augmentations. */
 407     private Augmentations fTempAugmentations = null;


1934      * built-in entity resolution.
1935      *
1936      * @param c
1937      * @param entity built-in name
1938      * @param XMLStringBuffer append the character to buffer
1939      *
1940      * we really dont need to call this function -- this function is only required when
1941      * we integrate with rest of Xerces2. SO maintaining the current behavior and still
1942      * calling this function to hanlde built-in entity reference.
1943      *
1944      */
1945     private void handleCharacter(char c, String entity, XMLStringBuffer content) throws XNIException {
1946         foundBuiltInRefs = true;
1947         content.append(c);
1948         if (fDocumentHandler != null) {
1949             fSingleChar[0] = c;
1950             if (fNotifyBuiltInRefs) {
1951                 fDocumentHandler.startGeneralEntity(entity, null, null, null);
1952             }
1953             fTempString.setValues(fSingleChar, 0, 1);
1954             if(!fIsCoalesce){
1955                 fDocumentHandler.characters(fTempString, null);
1956                 builtInRefCharacterHandled = true;
1957             }            
1958 
1959             if (fNotifyBuiltInRefs) {
1960                 fDocumentHandler.endGeneralEntity(entity, null);
1961             }
1962         }
1963     } // handleCharacter(char)
1964 
1965     // helper methods
1966 
1967     /**
1968      * Sets the scanner state.
1969      *
1970      * @param state The new scanner state.
1971      */
1972     protected final void setScannerState(int state) {
1973 
1974         fScannerState = state;
1975         if (DEBUG_SCANNER_STATE) {
1976             System.out.print("### setScannerState: ");
1977             //System.out.print(fScannerState);


3056                         }//if we dont need to coalesce clear the buffer
3057                         else{
3058                             fContentBuffer.clear();
3059                         }
3060                         fUsebuffer = true ;
3061                         //take care of character reference
3062                         if (fEntityScanner.skipChar('#')) {
3063                             scanCharReferenceValue(fContentBuffer, null);
3064                             fMarkupDepth--;
3065                             if(!fIsCoalesce){
3066                                 setScannerState(SCANNER_STATE_CONTENT);
3067                                 return XMLEvent.CHARACTERS;
3068                             }
3069                         } else {
3070                             // this function also starts new entity
3071                             scanEntityReference(fContentBuffer);
3072                             //if there was built-in entity reference & coalesce is not true
3073                             //return CHARACTERS
3074                             if(fScannerState == SCANNER_STATE_BUILT_IN_REFS && !fIsCoalesce){
3075                                 setScannerState(SCANNER_STATE_CONTENT);
3076                                 if (builtInRefCharacterHandled) {
3077                                     builtInRefCharacterHandled = false;
3078                                     return XMLEvent.ENTITY_REFERENCE;
3079                                 } else {
3080                                     return XMLEvent.CHARACTERS;
3081                                 }
3082                             }
3083 
3084                             //if there was a text declaration, call next() it will be taken care.
3085                             if(fScannerState == SCANNER_STATE_TEXT_DECL){
3086                                 fLastSectionWasEntityReference = true ;
3087                                 continue;
3088                             }
3089 
3090                             if(fScannerState == SCANNER_STATE_REFERENCE){
3091                                 setScannerState(SCANNER_STATE_CONTENT);
3092                                 if (fReplaceEntityReferences && fEntityStore.isDeclaredEntity(fCurrentEntityName)) {
3093                                     // Skip the entity reference, we don't care
3094                                     continue;
3095                                 }
3096                                 return XMLEvent.ENTITY_REFERENCE;
3097                             }
3098                         }
3099                         //Wether it was character reference, entity reference or built-in entity
3100                         //set the next possible state to SCANNER_STATE_CONTENT
3101                         setScannerState(SCANNER_STATE_CONTENT);
3102                         fLastSectionWasEntityReference = true ;