You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by ig...@apache.org on 2004/02/21 01:42:51 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/dom SAXImpl.java

igorh       2004/02/20 16:42:51

  Modified:    java/src/org/apache/xml/dtm/ref/sax2dtm SAX2DTM2.java
               java/src/org/apache/xalan/xsltc/dom SAXImpl.java
  Log:
  Code cleaning and optimization for copy and copy-of.  Discussed with Henry
  
  Revision  Changes    Path
  1.9       +30 -32    xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM2.java
  
  Index: SAX2DTM2.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM2.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SAX2DTM2.java	17 Feb 2004 04:07:37 -0000	1.8
  +++ SAX2DTM2.java	21 Feb 2004 00:42:51 -0000	1.9
  @@ -30,6 +30,7 @@
   
   import javax.xml.transform.Source;
   import java.util.Vector;
  +import org.apache.xml.utils.IntStack;
   import org.xml.sax.*;
   
   /**
  @@ -3198,7 +3199,6 @@
         
           if (uri.length() == 0) {
               handler.startElement(name);
  -            copyNS(nodeID,handler);
               return name;           
           }
           else {
  @@ -3206,7 +3206,6 @@
       
               if (qnameIndex == 0) {
                   handler.startElement(name);
  -                copyNS(nodeID,handler);
                   handler.namespaceAfterStartElement(EMPTY_STR, uri);
                   return name;
               }
  @@ -3226,49 +3225,48 @@
               else {
                   prefix = null;
               }
  -            copyNS(nodeID,handler);
               handler.namespaceAfterStartElement(prefix, uri);
               return qName;           
           }        
                
       }
       
  -    /**
  +     /**
        * Copy  namespace nodes.
        *
        * @param nodeID The Element node identity
        * @param handler The SerializationHandler
  +     * @param inScope  true if all namespaces in scope should be copied,
  +     *  false if only the namespace declarations should be copied.
        */
   
  -   public void copyNS(final int nodeID, SerializationHandler handler)
  -        throws SAXException
  -    {
  -      int current =  DTM.NULL; 
  -      int eType = DTM.NULL;
  -      int type = DTM.NULL;
  -      try{
  -        for (int elementID = nodeID; elementID != DTM.ROOT_NODE; elementID = _parent2(elementID)){
  -              current =  elementID;    
  -              while (true){
  -                  current++;
  -                  eType = _exptype2(current);
  -                  type = _exptype2Type(eType);
  -             
  -                  if (type == DTM.ATTRIBUTE_NODE) {
  -                     continue;
  -                  }
  -                  else if (type == DTM.NAMESPACE_NODE) {
  -                      handler.startPrefixMapping(getNodeNameX(makeNodeHandle(current)), getNodeValue(makeNodeHandle(current)), false);                       
  -                  }
  -                  else
  -                      break;
  -                  }
  -              }
  -        }catch (Exception e) {
  -            throw new SAXException(e);
  -        }
  +  protected final void copyNS(final int nodeID, SerializationHandler handler, boolean inScope)
  +        throws SAXException{
  +       final int node = makeNodeHandle(nodeID);
  +       for(int current = getFirstNamespaceNode(node, inScope); current != DTM.NULL; 
  +           current = getNextNamespaceNode(node, current, inScope)){               
  +                handler.namespaceAfterStartElement(getNodeNameX(current), getNodeValue(current));                             
  +       }
  +      
  +    }
  +   
  +    /**
  +     * Copy  attribute nodes from an element .
  +     *
  +     * @param nodeID The Element node identity
  +     * @param handler The SerializationHandler
  +     */
  +protected final void copyAttributes(final int nodeID, SerializationHandler handler)
  +        throws SAXException{      
  +       
  +       for(int current = getFirstAttributeIdentity(nodeID); current != DTM.NULL; current = getNextAttributeIdentity(current)){               
  +            int eType = _exptype2(current);
  +            copyAttribute(current, eType, handler);
  +       }     
       }
   
  + 
  +  
       /**
        * Copy an Attribute node to a SerializationHandler
        *
  
  
  
  1.18      +19 -26    xml-xalan/java/src/org/apache/xalan/xsltc/dom/SAXImpl.java
  
  Index: SAXImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/SAXImpl.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SAXImpl.java	16 Feb 2004 22:54:59 -0000	1.17
  +++ SAXImpl.java	21 Feb 2004 00:42:51 -0000	1.18
  @@ -1306,7 +1306,14 @@
       public void copy(final int node, SerializationHandler handler)
           throws TransletException
       {
  -        int nodeID = makeNodeIdentity(node);
  +        copy(node, handler, false );
  +    }
  +
  +
  + private final void copy(final int node, SerializationHandler handler, boolean isChild)
  +        throws TransletException
  +    {
  +     int nodeID = makeNodeIdentity(node);
           int eType = _exptype2(nodeID);
           int type = _exptype2Type(eType);
   
  @@ -1316,7 +1323,7 @@
                   case DTM.ROOT_NODE:
                   case DTM.DOCUMENT_NODE:
                       for(int c = _firstch2(nodeID); c != DTM.NULL; c = _nextsib2(c)) {
  -                        copy(makeNodeHandle(c), handler);
  +                        copy(makeNodeHandle(c), handler, true);
                       }
                       break;
                   case DTM.PROCESSING_INSTRUCTION_NODE:
  @@ -1353,29 +1360,13 @@
                       {
                           // Start element definition
                           final String name = copyElement(nodeID, eType, handler);
  -          
  -                        // %OPT% Increase the element ID by 1 to iterate through all
  -                        // attribute and namespace nodes.
  -                        int current = nodeID;
  -                        while (true)
  -                        {
  -                            current++;
  -                            eType = _exptype2(current);
  -                            type = _exptype2Type(eType);
  -            
  -                            if (type == DTM.ATTRIBUTE_NODE) {
  -                                copyAttribute(current, eType, handler);
  -                            }
  -                            else if (type == DTM.NAMESPACE_NODE) {
  -                                handler.namespaceAfterStartElement(getNodeNameX(makeNodeHandle(current)), getNodeValue(makeNodeHandle(current)));            
  -                            }
  -                            else
  -                                break;
  -                        }
  -
  +                        //if(isChild) => not to copy any namespaces  from parents
  +                        // else copy all namespaces in scope
  +                        copyNS(nodeID, handler,!isChild);
  +                        copyAttributes(nodeID, handler);
                           // Copy element children
                           for (int c = _firstch2(nodeID); c != DTM.NULL; c = _nextsib2(c)) {
  -                            copy(makeNodeHandle(c), handler);
  +                            copy(makeNodeHandle(c), handler, true);
                           }
             
                           // Close element definition
  @@ -1396,8 +1387,8 @@
           catch (Exception e) {
               throw new TransletException(e);
           }
  +    
       }
  -
       /**
        * Copies a processing instruction node to an output handler
        */
  @@ -1428,7 +1419,9 @@
               switch(type)
               {
                   case DTM.ELEMENT_NODE:
  -                    return(copyElement(nodeID, exptype, handler));
  +                    final String name = copyElement(nodeID, exptype, handler);
  +                    copyNS(nodeID, handler, true);
  +                    return name;
                   case DTM.ROOT_NODE:
                   case DTM.DOCUMENT_NODE:
                       return EMPTYSTRING;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org