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

The following examples show how to use org.w3c.dom.Node#equals() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * 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 Project: j2objc   File: NodeSet.java    License: 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
/**
 * 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 Project: JDKSourceCode1.8   File: NodeSet.java    License: 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 5
/**
 * 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 6
/**
 * 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 7
/**
 * 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 8
Source Project: Bytecoder   File: NodeSet.java    License: 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 9
/**
 * 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 10
Source Project: openjdk-8   File: NodeSet.java    License: 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 11
Source Project: Bytecoder   File: TreeWalker.java    License: 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 12
/**
 * 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 13
/**
 * 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 14
/**
 * 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 15
/**
 * 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 16
Source Project: j2objc   File: DOM3TreeWalker.java    License: 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 17
/**
 * 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 18
Source Project: netbeans   File: ReadOnlyAccess.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean areSameNodes(Node n1, Node n2) {
    return n1.equals(n2);
}
 
Example 19
/**
 * 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 20
/**
 * 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();
}