rahuls      2002/08/14 08:15:42

  Modified:    java/src/org/apache/xerces/dom Tag: jaxp-ri-1_2_0-fcs-branch
                        TextImpl.java
               java/src/org/apache/xerces/impl Tag:
                        jaxp-ri-1_2_0-fcs-branch XMLDTDScannerImpl.java
                        XMLDocumentScannerImpl.java
               java/src/org/apache/xerces/parsers Tag:
                        jaxp-ri-1_2_0-fcs-branch AbstractDOMParser.java
  Log:
  Patch from Gopal for improving performance of DTDScanner, DocumentScanner and DOM 
building.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.13.2.1  +19 -1     xml-xerces/java/src/org/apache/xerces/dom/TextImpl.java
  
  Index: TextImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/TextImpl.java,v
  retrieving revision 1.13
  retrieving revision 1.13.2.1
  diff -u -r1.13 -r1.13.2.1
  --- TextImpl.java     29 Jan 2002 01:15:07 -0000      1.13
  +++ TextImpl.java     14 Aug 2002 15:15:41 -0000      1.13.2.1
  @@ -192,4 +192,22 @@
   
       } // splitText(int):Text
   
  +        
  +    /**
  +     * NON-DOM (used by DOMParser): Reset data for the node. 
  +     */
  +    public void replaceData (String value){
  +       data = value;
  +    }
  +
  +    /**
  +     * NON-DOM (used by DOMParser: Sets data to empty string. 
  +     *  Returns the value the data was set to.
  +     */
  +    public String removeData (){
  +        String olddata=data;
  +        data = "";
  +        return olddata;
  +   }
  +
   } // class TextImpl
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.18.2.1  +2 -2      
xml-xerces/java/src/org/apache/xerces/impl/XMLDTDScannerImpl.java
  
  Index: XMLDTDScannerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDTDScannerImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.18.2.1
  diff -u -r1.18 -r1.18.2.1
  --- XMLDTDScannerImpl.java    29 Jan 2002 20:44:02 -0000      1.18
  +++ XMLDTDScannerImpl.java    14 Aug 2002 15:15:41 -0000      1.18.2.1
  @@ -655,7 +655,7 @@
                   }
               }
           }
  -
  +        fEntityManager.fCurrentEntity.mayReadChunks = true;
           return textDecl;
       
       } // scanTextDecl(boolean):boolean
  
  
  
  1.15.2.2  +2 -2      
xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentScannerImpl.java
  
  Index: XMLDocumentScannerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentScannerImpl.java,v
  retrieving revision 1.15.2.1
  retrieving revision 1.15.2.2
  diff -u -r1.15.2.1 -r1.15.2.2
  --- XMLDocumentScannerImpl.java       8 Aug 2002 10:50:47 -0000       1.15.2.1
  +++ XMLDocumentScannerImpl.java       14 Aug 2002 15:15:41 -0000      1.15.2.2
  @@ -587,7 +587,7 @@
                   reportFatalError("PrematureEOF", null);
                   throw e;
               }
  -
  +            fEntityManager.fCurrentEntity.mayReadChunks = true;
               // if no XMLDecl, then scan piece of prolog
               return true;
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.42.2.3  +78 -11    
xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java
  
  Index: AbstractDOMParser.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java,v
  retrieving revision 1.42.2.2
  retrieving revision 1.42.2.3
  diff -u -r1.42.2.2 -r1.42.2.3
  --- AbstractDOMParser.java    8 Aug 2002 12:54:39 -0000       1.42.2.2
  +++ AbstractDOMParser.java    14 Aug 2002 15:15:41 -0000      1.42.2.3
  @@ -205,11 +205,15 @@
       /** Current node. */
       protected Node fCurrentNode;
       protected CDATASection fCurrentCDATASection;
  -
  +    
  +    /** Character buffer */
  +    protected final StringBuffer fStringBuffer = new StringBuffer(50);
  +  
       // internal subset
   
       /** Internal subset buffer. */
       protected StringBuffer fInternalSubset;
  +    
   
       // deferred expansion data
   
  @@ -231,6 +235,9 @@
   
       /** True if inside CDATA section. */
       protected boolean fInCDATASection;
  +    
  +    /** True if saw the first chunk of characters */
  +    protected boolean fFirstChunk = false;
   
       // data
   
  @@ -381,12 +388,16 @@
           fDocumentTypeIndex = -1;
           fDeferredDocumentImpl = null;
           fCurrentNode = null;
  +        
  +        // reset string buffer
  +        fStringBuffer.setLength(0);
   
           // reset state information
           fInDocument = false;
           fInDTD = false;
           fInDTDExternalSubset = false;
           fInCDATASection = false;
  +        fFirstChunk = false;
           fCurrentCDATASection = null;
           fCurrentCDATASectionIndex = -1;
   
  @@ -422,6 +433,7 @@
           }
           if (fCreateEntityRefNodes) {
               if (!fDeferNodeExpansion) {
  +                setCharacterData();
                   EntityReference er = fDocument.createEntityReference(name);
                   // we don't need synchronization now, because entity ref will be
                   // expanded anyway. Synch only needed when user creates entityRef 
node
  @@ -505,10 +517,19 @@
        */
       public void comment(XMLString text, Augmentations augs) throws XNIException {
           
  -        if (!fIncludeComments || fInDTD) {
  -              return;
  -        }
  +     if (fInDTD) {        
  +            if (fInternalSubset != null && !fInDTDExternalSubset) {
  +                fInternalSubset.append("<!-- ");
  +                fInternalSubset.append(text.toString());
  +                fInternalSubset.append(" -->");
  +            }
  +            return;
  +     }
  +     if (!fIncludeComments) {
  +            return;
  +     }
           if (!fDeferNodeExpansion) {
  +            setCharacterData();
               Comment comment = fDocument.createComment(text.toString());
               fCurrentNode.appendChild(comment);
           }
  @@ -539,8 +560,20 @@
        */
       public void processingInstruction(String target, XMLString data, Augmentations 
augs)
           throws XNIException {
  +        
  +        if (fInDTD) {        
  +            if (fInternalSubset != null && !fInDTDExternalSubset) {
  +                fInternalSubset.append("<?");
  +                fInternalSubset.append(target.toString());
  +                fInternalSubset.append(' ');
  +                fInternalSubset.append(data.toString());
  +                fInternalSubset.append("?>");
  +
  +            }
  +        }
   
           if (!fDeferNodeExpansion) {
  +            setCharacterData();
               ProcessingInstruction pi =
                   fDocument.createProcessingInstruction(target, data.toString());
               fCurrentNode.appendChild(pi);
  @@ -734,6 +767,7 @@
                   }
                   // REVISIT: Handle entities in attribute value.
               }
  +            setCharacterData();
               fCurrentNode.appendChild(el);
               fCurrentNode = el;
           }
  @@ -816,12 +850,21 @@
                   }
                   Node child = fCurrentNode.getLastChild();
                   if (child != null && child.getNodeType() == Node.TEXT_NODE) {
  -                    Text textNode = (Text)child;
  -                    textNode.appendData(value);
  +                //    Text textNode = (Text)child;
  +                //    textNode.appendData(value);
  +                // collect all the data into the string buffer. 
  +                   if (fFirstChunk) {                    
  +                       fStringBuffer.append(((TextImpl)child).removeData());
  +                       fFirstChunk = false;
  +                   }
  +                   fStringBuffer.append(value);                
                   }
                   else {
  -                    Text textNode = fDocument.createTextNode(value);
  -                    fCurrentNode.appendChild(textNode);
  +                //    Text textNode = fDocument.createTextNode(value);
  +                //    fCurrentNode.appendChild(textNode);
  +                   fFirstChunk = true;
  +                   Text textNode = fDocument.createTextNode(value);
  +                   fCurrentNode.appendChild(textNode);                
                   }
               }
           }
  @@ -931,6 +974,7 @@
               System.out.println("==>endElement ("+element.rawname+")");
           }
           if (!fDeferNodeExpansion) {
  +            setCharacterData();
               fCurrentNode = fCurrentNode.getParentNode();
           }
           else {
  @@ -960,7 +1004,7 @@
        * @throws XNIException Thrown by handler to signal an error.
        */
       public void startCDATA(Augmentations augs) throws XNIException {
  -
  +     setCharacterData();
           fInCDATASection = true;
       } // startCDATA()
   
  @@ -1026,11 +1070,12 @@
        *                   Thrown by handler to signal an error.
        */
       public void endGeneralEntity(String name, Augmentations augs) throws 
XNIException {
  -        if (DEBUG_EVENTS || DEBUG_ENTITY_REF) {
  +        if (DEBUG_EVENTS ) {
               System.out.println("==>endGeneralEntity: ("+name+")");
           }
           if (fCreateEntityRefNodes) {
               if (!fDeferNodeExpansion) {
  +             setCharacterData();
                   if (fDocumentType != null) {
                       NamedNodeMap entities = fDocumentType.getEntities();
                       NodeImpl entity = (NodeImpl)entities.getNamedItem(name);
  @@ -1425,6 +1470,7 @@
           String literalSystemId = identifier.getLiteralSystemId();
           if (fInternalSubset != null && !fInDTDExternalSubset) {
               fInternalSubset.append("<!NOTATION ");
  +            fInternalSubset.append(name);
               if (publicId != null) {
                   fInternalSubset.append("PUBLIC '");
                   fInternalSubset.append(publicId);
  @@ -1694,5 +1740,26 @@
           
           return attr;
       }
  +    
  +   // If data rececived in more than one chunk, the data
  +   // is stored in StringBuffer.      
  +   // This function is called then the state is changed and the 
  +   // data needs to be appended to the current node
  +   protected void  setCharacterData(){
  +       // handle character data
  +       fFirstChunk = false;
  +       if (fStringBuffer.length() > 0) {
  +           // if we have data in the buffer we must have created
  +           // a text node already.
  +           Node child = fCurrentNode.getLastChild();
  +           // REVISIT: should this check be performed?
  +           if (child != null && child.getNodeType() == Node.TEXT_NODE) {
  +               ((TextImpl)child).replaceData(fStringBuffer.toString());
  +           }
  +           // reset string buffer
  +            fStringBuffer.setLength(0);
  +       }
  +   }
  +
       
   } // class AbstractDOMParser
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to