You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@apache.org on 2001/04/18 19:42:32 UTC

cvs commit: xml-xalan/java/src/org/apache/xml/dtm/dom2dtm DOM2DTM.java UnitTest.java

sboag       01/04/18 10:42:32

  Modified:    java/src/org/apache/xml/dtm/dom2dtm Tag: DTM_EXP
                        DOM2DTM.java UnitTest.java
  Log:
  Periodic checkin.  Basic traversal works now.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.4   +37 -29    xml-xalan/java/src/org/apache/xml/dtm/dom2dtm/Attic/DOM2DTM.java
  
  Index: DOM2DTM.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/dom2dtm/Attic/DOM2DTM.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- DOM2DTM.java	2001/04/17 15:59:40	1.1.2.3
  +++ DOM2DTM.java	2001/04/18 17:42:29	1.1.2.4
  @@ -265,6 +265,9 @@
     
     /** Samed element for attribute iteration */
     private Node m_elementForAttrs;
  +  
  +  /** Samed element index for attribute iteration */
  +  private int m_elementForAttrsIndex;
   
     /**
      * This method iterates to the next node that will be added to the table.
  @@ -277,7 +280,9 @@
     {
   
       if (m_nodesAreProcessed)
  -      return null;
  +    {
  +      // return null;
  +    }
   
       Node top = m_root;  // tells us when to stop.
       Node pos = (null == m_pos) ? m_root : m_pos;
  @@ -293,6 +298,7 @@
         int currentIndexHandle = m_nodes.size()-1;
         int posInfo = currentIndexHandle * NODEINFOBLOCKSIZE;
         
  +      boolean shouldPushLevel = true;
         if (Node.ELEMENT_NODE == type)
         {
           m_attrs = pos.getAttributes();
  @@ -303,6 +309,7 @@
             if (m_attrsPos < m_attrs.getLength())
             {
               m_elementForAttrs = pos;
  +            m_elementForAttrsIndex = currentIndexHandle;
               nextNode = m_attrs.item(m_attrsPos);
             }
             else
  @@ -317,11 +324,16 @@
           m_attrsPos++;
   
           if (m_attrsPos < m_attrs.getLength())
  +        {
             nextNode = m_attrs.item(m_attrsPos);
  +          shouldPushLevel = false;
  +        }
           else
           {
             m_info.setElementAt(DTM.NULL, posInfo + OFFSET_NEXTSIBLING);
             pos = m_elementForAttrs;
  +          currentIndexHandle = m_elementForAttrsIndex;
  +          posInfo = currentIndexHandle * NODEINFOBLOCKSIZE;
             nextNode = pos.getFirstChild();
   
             m_levelInfo.quickPop(LEVELINFO_NPERLEVEL);
  @@ -330,7 +342,7 @@
         else
           nextNode = pos.getFirstChild();        
   
  -      if (null != nextNode)
  +      if (shouldPushLevel && (null != nextNode))
         {
           m_levelInfo.push(currentIndexHandle); // parent
           m_levelInfo.push(DTM.NULL); // previous sibling
  @@ -344,23 +356,31 @@
           }
           
           if (top.equals(pos))
  +        {
  +          m_info.setElementAt(DTM.NULL, posInfo + OFFSET_NEXTSIBLING);
             break;
  +        }
   
           nextNode = pos.getNextSibling();
   
           if (null == nextNode)
           {
             m_info.setElementAt(DTM.NULL, posInfo + OFFSET_NEXTSIBLING);
  +
  +          currentIndexHandle = m_info.elementAt(posInfo + OFFSET_PARENT);
  +          posInfo = currentIndexHandle * NODEINFOBLOCKSIZE;
  +          
  +          m_levelInfo.quickPop(LEVELINFO_NPERLEVEL);
             pos = pos.getParentNode();
   
             if ((null == pos) || (top.equals(pos)))
             {
  +            m_info.setElementAt(DTM.NULL, posInfo + OFFSET_NEXTSIBLING);
               nextNode = null;
  -
               break;
             }
   
  -          m_levelInfo.quickPop(LEVELINFO_NPERLEVEL);
  +          
           }
         }
   
  @@ -605,13 +625,12 @@
   
         while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
         {
  -        Node node = lookupNode(identity);
  -
           // Assume this can not be null.
  -        type = node.getNodeType();
  +        type = getNodeType(identity);
   
           if (type == DTM.ATTRIBUTE_NODE)
           {
  +          Node node = lookupNode(identity);
             String nodeuri = node.getNamespaceURI();
   
             if (null == nodeuri)
  @@ -624,7 +643,7 @@
           }
           else if (DTM.NAMESPACE_NODE != type)
           {
  -          break;  // should be no more attribute nodes.
  +          // ignore
           }
         }
       }
  @@ -643,20 +662,18 @@
   
       int type = getNodeType(nodeHandle);
   
  -    while (DTM.ELEMENT_NODE == type)
  +    if (DTM.ELEMENT_NODE == type)
       {
   
         // Assume that attributes and namespaces immediately follow the element.
         int identity = nodeHandle & m_mask;
   
  -      if (DTM.NULL != (identity = getNextNodeIdentity(identity)))
  +      while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
         {
  -        Node node = lookupNode(identity);
  -
           // Assume this can not be null.
  -        type = node.getNodeType();
  +        type = getNodeType(identity);
   
  -        if (node.getNodeType() == DTM.ATTRIBUTE_NODE)
  +        if (type == DTM.ATTRIBUTE_NODE)
           {
             return identity | m_dtmIdent;
           }
  @@ -688,20 +705,17 @@
   
       int type = getNodeType(nodeHandle);
   
  -    while (DTM.ELEMENT_NODE == type)
  +    if (DTM.ELEMENT_NODE == type)
       {
   
         // Assume that attributes and namespaces immediately follow the element.
         int identity = nodeHandle & m_mask;
   
  -      if (DTM.NULL != (identity = getNextNodeIdentity(identity)))
  +      while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
         {
  -        Node node = lookupNode(identity);
  +        type = getNodeType(identity);
   
  -        // Assume this can not be null.
  -        type = node.getNodeType();
  -
  -        if (node.getNodeType() == DTM.NAMESPACE_NODE)
  +        if (type == DTM.NAMESPACE_NODE)
           {
             return identity | m_dtmIdent;
           }
  @@ -772,10 +786,7 @@
   
         while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
         {
  -        Node node = lookupNode(identity);
  -
  -        // Assume this can not be null.
  -        type = node.getNodeType();
  +        type = getNodeType(identity);
   
           if (type == DTM.ATTRIBUTE_NODE)
           {
  @@ -813,10 +824,7 @@
   
         while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
         {
  -        Node node = lookupNode(identity);
  -
  -        // Assume this can not be null.
  -        type = node.getNodeType();
  +        type = getNodeType(identity);
   
           if (type == DTM.NAMESPACE_NODE)
           {
  
  
  
  1.1.2.2   +78 -4     xml-xalan/java/src/org/apache/xml/dtm/dom2dtm/Attic/UnitTest.java
  
  Index: UnitTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/dom2dtm/Attic/UnitTest.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- UnitTest.java	2001/04/17 16:00:15	1.1.2.1
  +++ UnitTest.java	2001/04/18 17:42:29	1.1.2.2
  @@ -20,7 +20,8 @@
     {
     }
     
  -  static String s_doc1String = 
  +  // No namespaces, only elements & attributes
  +  static String s_doc1String1 = 
                 "<?xml version=\"1.0\"?>" +
                 "<far-north>" +
                 " <north>" +
  @@ -41,6 +42,64 @@
                 "  </near-north>" +
                 " </north>" +
                 "</far-north>";
  +
  +  // With namespaces
  +  static String s_doc1String2 = 
  +              "<?xml version=\"1.0\"?>" +
  +              "<far-north>" +
  +              " <north xmlns:x='http://x.com'>" +
  +              "  <near-north>" +
  +              "   <far-west xmlns:y='http://y.com'/>" +
  +              "   <west/>" +
  +              "   <near-west near-west-attr1='near-west-attr1-value'/>" +
  +              "   <center xmlns:y='http://y.com'>" +
  +              "    <near-south xmlns:z='http://z.com' xmlns:v='http://v.com'>" +
  +              "     <south south-attr1='south-attr1-value' south-attr2='south-attr2-value'>" +
  +              "      <far-south/>" +
  +              "     </south>" +
  +              "    </near-south>" +
  +              "   </center>" +
  +              "   <near-east/>" +
  +              "   <east/>" +
  +              "   <far-east/>" +
  +              "  </near-north>" +
  +              " </north>" +
  +              "</far-north>";
  +              
  +    // Reproduces bug where things don't get processed after the last attribute.
  +  static String s_doc1String2a = 
  +              "<?xml version=\"1.0\"?>" +
  +              "<far-north>" +
  +                "<center>" +
  +                  "<near-south a='a' b='b'>" +
  +                    "<south c='c' d='d'/>" +
  +                  "</near-south>" +
  +                "</center>" +
  +                "<near-east/>" +
  +              "</far-north>";
  +                
  +  // namespaces and text
  +  static String s_doc1String3 = 
  +              "<?xml version=\"1.0\"?>" +
  +              "<far-north>a" +
  +              " <north xmlns:x='http://x.com'>b" +
  +              "  <near-north>c" +
  +              "   <far-west xmlns:y='http://y.com'>d</far-west>" +
  +              "   <west>e</west>" +
  +              "   <near-west near-west-attr1='near-west-attr1-value'>f</near-west>" +
  +              "   <center xmlns:y='http://y.com'>g" +
  +              "    <near-south xmlns:z='http://z.com' xmlns:v='http://v.com'>h" +
  +              "     <south south-attr1='south-attr1-value' south-attr2='south-attr2-value'>i" +
  +              "      <far-south>j</far-south>k" +
  +              "     </south>l" +
  +              "    </near-south>m" +
  +              "   </center>n" +
  +              "   <near-east>o</near-east>" +
  +              "   <east>p</east>" +
  +              "   <far-east>q</far-east>r" +
  +              "  </near-north>s" +
  +              " </north>t" +
  +              "</far-north>";
     
     protected int run(String[] args)
       throws Exception
  @@ -48,7 +107,7 @@
       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
       dbf.setNamespaceAware(true);
       DocumentBuilder db = dbf.newDocumentBuilder();
  -    StringReader sr = new StringReader(s_doc1String);
  +    StringReader sr = new StringReader(s_doc1String3);
       
       Document doc = db.parse(new InputSource(sr));
       
  @@ -77,9 +136,24 @@
         {
           System.out.print(' ');
         }
  +      
  +      System.out.print("node name: "+dtm.getNodeName(handle));
  +      System.out.println(", val: "+dtm.getStringValue(handle));
  +      
  +      for (int ns = dtm.getFirstNamespaceNode(handle, true); ns != DTM.NULL; 
  +           ns = dtm.getNextNamespaceNode(ns, true)) 
  +      {
  +        System.out.print("ns decl: "+dtm.getNodeName(ns));
  +        System.out.println(", val: "+dtm.getStringValue(ns));
  +      }
  +      for (int attr = dtm.getFirstAttribute(handle); attr != DTM.NULL; 
  +           attr = dtm.getNextAttribute(attr)) 
  +      {
  +        System.out.print("attr: "+dtm.getNodeName(attr));
  +        System.out.println(", val: "+dtm.getStringValue(attr));
  +      }
         
  -      System.out.println("node name: "+dtm.getNodeName(handle));
  -      outputChildren(handle, dtm, 0 /* indentAmount+2 */);
  +      outputChildren(handle, dtm, indentAmount+1);
       }
     }
     
  
  
  

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