Java Code Examples for org.w3c.dom.Node#equals()

The following examples show how to use org.w3c.dom.Node#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeSet.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Searches for the first occurence of the given argument,
 * beginning the search at index, and testing for equality
 * using the equals method.
 *
 * @param elem Node to look for
 * @return the index of the first occurrence of the object
 * argument in this vector at position index or later in the
 * vector; returns -1 if the object is not found.
 */
public int indexOf(Node elem)
{
  runTo(-1);

  if (null == m_map)
    return -1;

  for (int i = 0; i < m_firstFree; i++)
  {
    Node node = m_map[i];

    if ((null != node) && node.equals(elem))
      return i;
  }

  return -1;
}
 
Example 2
Source File: NodeSet.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Searches for the first occurence of the given argument,
 * beginning the search at index, and testing for equality
 * using the equals method.
 *
 * @param elem Node to look for
 * @param index Index of where to start the search
 * @return the index of the first occurrence of the object
 * argument in this vector at position index or later in the
 * vector; returns -1 if the object is not found.
 */
public int indexOf(Node elem, int index)
{
  runTo(-1);

  if (null == m_map)
    return -1;

  for (int i = index; i < m_firstFree; i++)
  {
    Node node = m_map[i];

    if ((null != node) && node.equals(elem))
      return i;
  }

  return -1;
}
 
Example 3
Source File: DecisionTree.java    From android-galaxyzoo with GNU General Public License v3.0 6 votes vote down vote up
/**
 * getElementsByTagName() is recursive, but we do not want that.
 *
 * @param parentNode
 * @param tagName
 * @return
 */
@Nullable
private static Node getFirstChildByTagName(@NonNull final Element parentNode, @NonNull final String tagName) {
    final NodeList list = parentNode.getElementsByTagName(tagName);
    final int num = list.getLength();
    for (int i = 0; i < num; i++) {
        final Node node = list.item(i);
        if (node == null) {
            continue;
        }

        final Node itemParentNode = node.getParentNode();
        if (itemParentNode.equals(parentNode)) {
            return node;
        }
    }

    return null;
}
 
Example 4
Source File: NodeSet.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Searches for the first occurence of the given argument,
 * beginning the search at index, and testing for equality
 * using the equals method.
 *
 * @param elem Node to look for
 * @param index Index of where to start the search
 * @return the index of the first occurrence of the object
 * argument in this vector at position index or later in the
 * vector; returns -1 if the object is not found.
 */
public int indexOf(Node elem, int index)
{
  runTo(-1);

  if (null == m_map)
    return -1;

  for (int i = index; i < m_firstFree; i++)
  {
    Node node = m_map[i];

    if ((null != node) && node.equals(elem))
      return i;
  }

  return -1;
}
 
Example 5
Source File: NodeSet.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Searches for the first occurence of the given argument,
 * beginning the search at index, and testing for equality
 * using the equals method.
 *
 * @param elem Node to look for
 * @return the index of the first occurrence of the object
 * argument in this vector at position index or later in the
 * vector; returns -1 if the object is not found.
 */
public int indexOf(Node elem)
{
  runTo(-1);

  if (null == m_map)
    return -1;

  for (int i = 0; i < m_firstFree; i++)
  {
    Node node = m_map[i];

    if ((null != node) && node.equals(elem))
      return i;
  }

  return -1;
}
 
Example 6
Source File: NodeSet.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes the first occurrence of the argument from this vector.
 * If the object is found in this vector, each component in the vector
 * with an index greater or equal to the object's index is shifted
 * downward to have an index one smaller than the value it had
 * previously.
 *
 * @param s Node to remove from the list
 *
 * @return True if the node was successfully removed
 */
public boolean removeElement(Node s)
{
  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  if (null == m_map)
    return false;

  for (int i = 0; i < m_firstFree; i++)
  {
    Node node = m_map[i];

    if ((null != node) && node.equals(s))
    {
      if (i < m_firstFree - 1)
        System.arraycopy(m_map, i + 1, m_map, i, m_firstFree - i - 1);

      m_firstFree--;
      m_map[m_firstFree] = null;

      return true;
    }
  }

  return false;
}
 
Example 7
Source File: TreeWalker.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Perform a pre-order traversal non-recursive style.
 *
 * In contrast to the traverse() method this method will not issue
 * startDocument() and endDocument() events to the SAX listener.
 *
 * @param pos Node in the tree where to start traversal
 *
 * @throws TransformerException
 */
public void traverseFragment(Node pos) throws org.xml.sax.SAXException
{
  Node top = pos;

  while (null != pos)
  {
    startNode(pos);

    Node nextNode = pos.getFirstChild();

    while (null == nextNode)
    {
      endNode(pos);

      if (top.equals(pos))
        break;

      nextNode = pos.getNextSibling();

      if (null == nextNode)
      {
        pos = pos.getParentNode();

        if ((null == pos) || (top.equals(pos)))
        {
          if (null != pos)
            endNode(pos);

          nextNode = null;

          break;
        }
      }
    }

    pos = nextNode;
  }
}
 
Example 8
Source File: NodeSet.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes the first occurrence of the argument from this vector.
 * If the object is found in this vector, each component in the vector
 * with an index greater or equal to the object's index is shifted
 * downward to have an index one smaller than the value it had
 * previously.
 *
 * @param s Node to remove from the list
 *
 * @return True if the node was successfully removed
 */
public boolean removeElement(Node s)
{
  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  if (null == m_map)
    return false;

  for (int i = 0; i < m_firstFree; i++)
  {
    Node node = m_map[i];

    if ((null != node) && node.equals(s))
    {
      if (i < m_firstFree - 1)
        System.arraycopy(m_map, i + 1, m_map, i, m_firstFree - i - 1);

      m_firstFree--;
      m_map[m_firstFree] = null;

      return true;
    }
  }

  return false;
}
 
Example 9
Source File: NodeSet.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the first occurrence of the argument from this vector.
 * If the object is found in this vector, each component in the vector
 * with an index greater or equal to the object's index is shifted
 * downward to have an index one smaller than the value it had
 * previously.
 *
 * @param s Node to remove from the list
 *
 * @return True if the node was successfully removed
 */
public boolean removeElement(Node s)
{
  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  if (null == m_map)
    return false;

  for (int i = 0; i < m_firstFree; i++)
  {
    Node node = m_map[i];

    if ((null != node) && node.equals(s))
    {
      if (i < m_firstFree - 1)
        System.arraycopy(m_map, i + 1, m_map, i, m_firstFree - i - 1);

      m_firstFree--;
      m_map[m_firstFree] = null;

      return true;
    }
  }

  return false;
}
 
Example 10
Source File: TreeWalker.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Perform a pre-order traversal non-recursive style.
 *
 * In contrast to the traverse() method this method will not issue
 * startDocument() and endDocument() events to the SAX listener.
 *
 * @param pos Node in the tree where to start traversal
 *
 * @throws TransformerException
 */
public void traverseFragment(Node pos) throws org.xml.sax.SAXException
{
  Node top = pos;

  while (null != pos)
  {
    startNode(pos);

    Node nextNode = pos.getFirstChild();

    while (null == nextNode)
    {
      endNode(pos);

      if (top.equals(pos))
        break;

      nextNode = pos.getNextSibling();

      if (null == nextNode)
      {
        pos = pos.getParentNode();

        if ((null == pos) || (top.equals(pos)))
        {
          if (null != pos)
            endNode(pos);

          nextNode = null;

          break;
        }
      }
    }

    pos = nextNode;
  }
}
 
Example 11
Source File: NodeSet.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes the first occurrence of the argument from this vector.
 * If the object is found in this vector, each component in the vector
 * with an index greater or equal to the object's index is shifted
 * downward to have an index one smaller than the value it had
 * previously.
 *
 * @param s Node to remove from the list
 *
 * @return True if the node was successfully removed
 */
public boolean removeElement(Node s)
{
  if (!m_mutable)
    throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

  if (null == m_map)
    return false;

  for (int i = 0; i < m_firstFree; i++)
  {
    Node node = m_map[i];

    if ((null != node) && node.equals(s))
    {
      if (i < m_firstFree - 1)
        System.arraycopy(m_map, i + 1, m_map, i, m_firstFree - i - 1);

      m_firstFree--;
      m_map[m_firstFree] = null;

      return true;
    }
  }

  return false;
}
 
Example 12
Source File: TreeWalker.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Perform a pre-order traversal non-recursive style.

 * Note that TreeWalker assumes that the subtree is intended to represent
 * a complete (though not necessarily well-formed) document and, during a
 * traversal, startDocument and endDocument will always be issued to the
 * SAX listener.
 *
 * @param pos Node in the tree where to start traversal
 * @param top Node in the tree where to end traversal
 *
 * @throws TransformerException
 */
public void traverse(Node pos, Node top) throws org.xml.sax.SAXException
{

  this.m_contentHandler.startDocument();

  while (null != pos)
  {
    startNode(pos);

    Node nextNode = pos.getFirstChild();

    while (null == nextNode)
    {
      endNode(pos);

      if ((null != top) && top.equals(pos))
        break;

      nextNode = pos.getNextSibling();

      if (null == nextNode)
      {
        pos = pos.getParentNode();

        if ((null == pos) || ((null != top) && top.equals(pos)))
        {
          nextNode = null;

          break;
        }
      }
    }

    pos = nextNode;
  }
  this.m_contentHandler.endDocument();
}
 
Example 13
Source File: DOM3TreeWalker.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Perform a pre-order traversal non-recursive style.
 *
 * Note that TreeWalker assumes that the subtree is intended to represent
 * a complete (though not necessarily well-formed) document and, during a
 * traversal, startDocument and endDocument will always be issued to the
 * SAX listener.
 *
 * @param pos Node in the tree where to start traversal
 *
 * @throws TransformerException
 */
public void traverse(Node pos) throws org.xml.sax.SAXException {
    this.fSerializer.startDocument();

    // Determine if the Node is a DOM Level 3 Core Node.
    if (pos.getNodeType() != Node.DOCUMENT_NODE) {
        Document ownerDoc = pos.getOwnerDocument();
        if (ownerDoc != null
            && ownerDoc.getImplementation().hasFeature("Core", "3.0")) {
            fIsLevel3DOM = true;
        }
    } else {
        if (((Document) pos)
            .getImplementation()
            .hasFeature("Core", "3.0")) {
            fIsLevel3DOM = true;
        }
    }

    if (fSerializer instanceof LexicalHandler) {
        fLexicalHandler = ((LexicalHandler) this.fSerializer);
    }

    if (fFilter != null)
        fWhatToShowFilter = fFilter.getWhatToShow();

    Node top = pos;

    while (null != pos) {
        startNode(pos);

        Node nextNode = null;

        nextNode = pos.getFirstChild();

        while (null == nextNode) {
            endNode(pos);

            if (top.equals(pos))
                break;

            nextNode = pos.getNextSibling();

            if (null == nextNode) {
                pos = pos.getParentNode();

                if ((null == pos) || (top.equals(pos))) {
                    if (null != pos)
                        endNode(pos);

                    nextNode = null;

                    break;
                }
            }
        }

        pos = nextNode;
    }
    this.fSerializer.endDocument();
}
 
Example 14
Source File: CoreDocumentImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Traverses the DOM Tree and expands deferred nodes and their
 * children.
 *
 */
protected void undeferChildren(Node node) {

    Node top = node;

    while (null != node) {

        if (((NodeImpl)node).needsSyncData()) {
            ((NodeImpl)node).synchronizeData();
        }

        NamedNodeMap attributes = node.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            for (int i = 0; i < length; ++i) {
                undeferChildren(attributes.item(i));
            }
        }

        Node nextNode = null;
        nextNode = node.getFirstChild();

        while (null == nextNode) {

            if (top.equals(node))
                break;

            nextNode = node.getNextSibling();

            if (null == nextNode) {
                node = node.getParentNode();

                if ((null == node) || (top.equals(node))) {
                    nextNode = null;
                    break;
                }
            }
        }

        node = nextNode;
    }
}
 
Example 15
Source File: ReadOnlyAccess.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean areSameNodes(Node n1, Node n2) {
    return n1.equals(n2);
}
 
Example 16
Source File: DOM3TreeWalker.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Perform a pre-order traversal non-recursive style.

 * Note that TreeWalker assumes that the subtree is intended to represent
 * a complete (though not necessarily well-formed) document and, during a
 * traversal, startDocument and endDocument will always be issued to the
 * SAX listener.
 *
 * @param pos Node in the tree where to start traversal
 * @param top Node in the tree where to end traversal
 *
 * @throws TransformerException
 */
public void traverse(Node pos, Node top) throws org.xml.sax.SAXException {

    this.fSerializer.startDocument();

    // Determine if the Node is a DOM Level 3 Core Node.
    if (pos.getNodeType() != Node.DOCUMENT_NODE) {
        Document ownerDoc = pos.getOwnerDocument();
        if (ownerDoc != null
            && ownerDoc.getImplementation().hasFeature("Core", "3.0")) {
            fIsLevel3DOM = true;
        }
    } else {
        if (((Document) pos)
            .getImplementation()
            .hasFeature("Core", "3.0")) {
            fIsLevel3DOM = true;
        }
    }

    if (fSerializer instanceof LexicalHandler) {
        fLexicalHandler = ((LexicalHandler) this.fSerializer);
    }

    if (fFilter != null)
        fWhatToShowFilter = fFilter.getWhatToShow();

    while (null != pos) {
        startNode(pos);

        Node nextNode = null;

        nextNode = pos.getFirstChild();

        while (null == nextNode) {
            endNode(pos);

            if ((null != top) && top.equals(pos))
                break;

            nextNode = pos.getNextSibling();

            if (null == nextNode) {
                pos = pos.getParentNode();

                if ((null == pos) || ((null != top) && top.equals(pos))) {
                    nextNode = null;

                    break;
                }
            }
        }

        pos = nextNode;
    }
    this.fSerializer.endDocument();
}
 
Example 17
Source File: DOM3TreeWalker.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Perform a pre-order traversal non-recursive style.  
 *
 * Note that TreeWalker assumes that the subtree is intended to represent 
 * a complete (though not necessarily well-formed) document and, during a 
 * traversal, startDocument and endDocument will always be issued to the 
 * SAX listener.
 *  
 * @param pos Node in the tree where to start traversal
 *
 * @throws TransformerException
 */
public void traverse(Node pos) throws org.xml.sax.SAXException {
    this.fSerializer.startDocument();

    // Determine if the Node is a DOM Level 3 Core Node.
    if (pos.getNodeType() != Node.DOCUMENT_NODE) {
        Document ownerDoc = pos.getOwnerDocument();
        if (ownerDoc != null
            && ownerDoc.getImplementation().hasFeature("Core", "3.0")) {
            fIsLevel3DOM = true;
        }
    } else {
        if (((Document) pos)
            .getImplementation()
            .hasFeature("Core", "3.0")) {
            fIsLevel3DOM = true;
        }
    }

    if (fSerializer instanceof LexicalHandler) {
        fLexicalHandler = ((LexicalHandler) this.fSerializer);
    }

    if (fFilter != null)
        fWhatToShowFilter = fFilter.getWhatToShow();

    Node top = pos;

    while (null != pos) {
        startNode(pos);

        Node nextNode = null;

        nextNode = pos.getFirstChild();

        while (null == nextNode) {
            endNode(pos);

            if (top.equals(pos))
                break;

            nextNode = pos.getNextSibling();

            if (null == nextNode) {
                pos = pos.getParentNode();

                if ((null == pos) || (top.equals(pos))) {
                    if (null != pos)
                        endNode(pos);

                    nextNode = null;

                    break;
                }
            }
        }

        pos = nextNode;
    }
    this.fSerializer.endDocument();
}
 
Example 18
Source File: CoreDocumentImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Traverses the DOM Tree and expands deferred nodes and their
 * children.
 *
 */
protected void undeferChildren(Node node) {

    Node top = node;

    while (null != node) {

        if (((NodeImpl)node).needsSyncData()) {
            ((NodeImpl)node).synchronizeData();
        }

        NamedNodeMap attributes = node.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            for (int i = 0; i < length; ++i) {
                undeferChildren(attributes.item(i));
            }
        }

        Node nextNode = null;
        nextNode = node.getFirstChild();

        while (null == nextNode) {

            if (top.equals(node))
                break;

            nextNode = node.getNextSibling();

            if (null == nextNode) {
                node = node.getParentNode();

                if ((null == node) || (top.equals(node))) {
                    nextNode = null;
                    break;
                }
            }
        }

        node = nextNode;
    }
}
 
Example 19
Source File: TreeWalker.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Perform a pre-order traversal non-recursive style.
 *
 * Note that TreeWalker assumes that the subtree is intended to represent
 * a complete (though not necessarily well-formed) document and, during a
 * traversal, startDocument and endDocument will always be issued to the
 * SAX listener.
 *
 * @param pos Node in the tree where to start traversal
 *
 * @throws TransformerException
 */
public void traverse(Node pos) throws org.xml.sax.SAXException
{

  this.m_contentHandler.startDocument();

  Node top = pos;

  while (null != pos)
  {
    startNode(pos);

    Node nextNode = pos.getFirstChild();

    while (null == nextNode)
    {
      endNode(pos);

      if (top.equals(pos))
        break;

      nextNode = pos.getNextSibling();

      if (null == nextNode)
      {
        pos = pos.getParentNode();

        if ((null == pos) || (top.equals(pos)))
        {
          if (null != pos)
            endNode(pos);

          nextNode = null;

          break;
        }
      }
    }

    pos = nextNode;
  }
  this.m_contentHandler.endDocument();
}
 
Example 20
Source File: CoreDocumentImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Traverses the DOM Tree and expands deferred nodes and their
 * children.
 *
 */
protected void undeferChildren(Node node) {

    Node top = node;

    while (null != node) {

        if (((NodeImpl)node).needsSyncData()) {
            ((NodeImpl)node).synchronizeData();
        }

        NamedNodeMap attributes = node.getAttributes();
        if (attributes != null) {
            int length = attributes.getLength();
            for (int i = 0; i < length; ++i) {
                undeferChildren(attributes.item(i));
            }
        }

        Node nextNode = null;
        nextNode = node.getFirstChild();

        while (null == nextNode) {

            if (top.equals(node))
                break;

            nextNode = node.getNextSibling();

            if (null == nextNode) {
                node = node.getParentNode();

                if ((null == node) || (top.equals(node))) {
                    nextNode = null;
                    break;
                }
            }
        }

        node = nextNode;
    }
}