You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by dl...@apache.org on 2002/03/22 15:47:23 UTC

cvs commit: xml-xalan/java/src/org/apache/xpath DOMHelper.java

dleslie     02/03/22 06:47:23

  Modified:    java/src/org/apache/xpath DOMHelper.java
  Log:
  The Node identity test in isNodeAfter()
  (ie., node1 == node2) does not work in some cases,
  so I added a routine to use DTMNodeProxy equals()
  if that test fails.
  This was required to support the new EXSLT
  leading() and trailing() extension functions.
  
  Revision  Changes    Path
  1.29      +26 -8     xml-xalan/java/src/org/apache/xpath/DOMHelper.java
  
  Index: DOMHelper.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/DOMHelper.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- DOMHelper.java	15 Jun 2001 05:15:17 -0000	1.28
  +++ DOMHelper.java	22 Mar 2002 14:47:22 -0000	1.29
  @@ -75,6 +75,8 @@
   import javax.xml.parsers.DocumentBuilderFactory;
   import javax.xml.parsers.ParserConfigurationException;
   
  +import org.apache.xml.dtm.ref.DTMNodeProxy;
  +
   /**
    * @deprecated Since the introduction of the DTM, this class will be removed.
    * This class provides a front-end to DOM implementations, providing
  @@ -204,17 +206,17 @@
      */
     public static boolean isNodeAfter(Node node1, Node node2)
     {
  -    if (node1 == node2)
  +    if (node1 == node2 || isNodeTheSame(node1, node2))
         return true;
   
           // Default return value, if there is no defined ordering
       boolean isNodeAfter = true;
           
       Node parent1 = getParentOfNode(node1);
  -    Node parent2 = getParentOfNode(node2);
  +    Node parent2 = getParentOfNode(node2);          
   
       // Optimize for most common case
  -    if (parent1 == parent2)  // then we know they are siblings
  +    if (parent1 == parent2 || isNodeTheSame(parent1, parent2))  // then we know they are siblings
       {
         if (null != parent1)
           isNodeAfter = isNodeAfterSibling(parent1, node1, node2);
  @@ -291,7 +293,7 @@
         // Loop up the ancestor chain looking for common parent
         while (null != startNode1)
         {
  -        if (startNode1 == startNode2)  // common parent?
  +        if (startNode1 == startNode2 || isNodeTheSame(startNode1, startNode2))  // common parent?
           {
             if (null == prevChild1)  // first time in loop?
             {
  @@ -331,6 +333,22 @@
     }  // end isNodeAfter(Node node1, Node node2)
   
     /**
  +   * Use DTMNodeProxy to determine whether two nodes are the same.
  +   * 
  +   * @param node1 The first DOM node to compare.
  +   * @param node2 The second DOM node to compare.
  +   * @return true if the two nodes are the same, false if not or if
  +   * the nodes are not DTMNodeProxy.
  +   */
  +  public static boolean isNodeTheSame(Node node1, Node node2)
  +  {
  +    if (node1 instanceof DTMNodeProxy && node2 instanceof DTMNodeProxy)
  +      return ((DTMNodeProxy)node1).equals((DTMNodeProxy)node2);
  +    else
  +      return false;
  +  }
  +
  +  /**
      * Figure out if child2 is after child1 in document order.
      * <p>
      * Warning: Some aspects of "document order" are not well defined.
  @@ -377,7 +395,7 @@
         {
           Node child = children.item(i);
   
  -        if (child1 == child)
  +        if (child1 == child || isNodeTheSame(child1, child))
           {
             if (found2)
             {
  @@ -388,7 +406,7 @@
   
             found1 = true;
           }
  -        else if (child2 == child)
  +        else if (child2 == child || isNodeTheSame(child2, child))
           {
             if (found1)
             {
  @@ -421,7 +439,7 @@
         {
   
           // Node child = children.item(i);
  -        if (child1 == child)
  +        if (child1 == child || isNodeTheSame(child1, child))
           {
             if (found2)
             {
  @@ -432,7 +450,7 @@
   
             found1 = true;
           }
  -        else if (child2 == child)
  +        else if (child2 == child || isNodeTheSame(child2, child))
           {
             if (found1)
             {
  
  
  

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