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

The following are Jave code examples for showing how to use equals() of the org.w3c.dom.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: convertigo-eclipse   File: XpathEvaluatorComposite.java   Source Code and License Vote up 6 votes
private boolean canGenerateSelectionXpath(boolean overwrite, Node node) {
	boolean bSelectionMenu = (currentAnchor == null);
	
	if (bSelectionMenu && !overwrite) {
		Node curNode = node instanceof Attr ? ((Attr) node).getOwnerElement() : node;
		Node root = node.getOwnerDocument().getFirstChild();
		if (curNode.equals(root)) {
			bSelectionMenu = false;
		} else {
			NodeList nodeList = root.getChildNodes();
			for (int i = 0; i < nodeList.getLength() && bSelectionMenu; i++) {
				bSelectionMenu = !nodeList.item(i).equals(curNode);
			}
		}
	}
	return bSelectionMenu;
}
 
Example 2
Project: openjdk-jdk10   File: NodeSet.java   Source Code and License Vote up 6 votes
/**
 * Tell if the table contains the given node.
 *
 * @param s Node to look for
 *
 * @return True if the given node was found.
 */
public boolean contains(Node s)
{
  runTo(-1);

  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))
      return true;
  }

  return false;
}
 
Example 3
Project: OpenJSharp   File: NodeSet.java   Source Code and License Vote up 6 votes
/**
 * Tell if the table contains the given node.
 *
 * @param s Node to look for
 *
 * @return True if the given node was found.
 */
public boolean contains(Node s)
{
  runTo(-1);

  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))
      return true;
  }

  return false;
}
 
Example 4
Project: OpenJSharp   File: NodeSet.java   Source Code and License Vote up 6 votes
/**
 * 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
Project: OpenJSharp   File: NodeSet.java   Source Code and License Vote up 6 votes
/**
 * 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
Project: openjdk-jdk10   File: NodeSet.java   Source Code and License Vote up 6 votes
/**
 * 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 7
Project: openjdk-jdk10   File: NodeSet.java   Source Code and License Vote up 6 votes
/**
 * 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 8
Project: openjdk-jdk10   File: NodeSet.java   Source Code and License Vote up 5 votes
/**
 * 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
Project: OpenJSharp   File: TreeWalker.java   Source Code and License Vote up 5 votes
/**
 * 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 10
Project: OpenJSharp   File: TreeWalker.java   Source Code and License Vote up 5 votes
/**
 * 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 11
Project: OpenJSharp   File: NodeSet.java   Source Code and License Vote up 5 votes
/**
 * 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
Project: openjdk-jdk10   File: TreeWalker.java   Source Code and License Vote up 5 votes
/**
 * 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
Project: incubator-netbeans   File: ReadOnlyAccess.java   Source Code and License Vote up 4 votes
@Override
public boolean areSameNodes(Node n1, Node n2) {
    return n1.equals(n2);
}
 
Example 14
Project: convertigo-engine   File: XMLUtils.java   Source Code and License Vote up 4 votes
/**
 * Compute the xpath of a node relative to an anchor.
 * 
 * @param node
 *            node to find the xpath from.
 * @param anchor
 *            the relative point to fid from.
 * @return the computed xpath.
 */
public static String calcXpath(Node node, Node anchor) {
	String xpath = "";
	Node current = null;

	if (node == null || node.equals(anchor))
		return "";

	// add attribute to xpath
	if (node instanceof Attr) {
		Attr attr = (Attr) node;
		node = attr.getOwnerElement();
		xpath = '@' + attr.getName() + '/';
	}

	while ((current = node.getParentNode()) != anchor) {
		Engine.logEngine.trace("Calc Xpath : current node : " + current.getNodeName());
		NodeList childs = current.getChildNodes();
		int index = 0;
		for (int i = 0; i < childs.getLength(); i++) {
			if (childs.item(i).getNodeType() != Node.ELEMENT_NODE
					&& !childs.item(i).getNodeName().equalsIgnoreCase("#text"))
				continue;

			Engine.logEngine.trace("Calc Xpath : ==== > Child node : " + childs.item(i).getNodeName());

			// Bump the index if we have the same tag names..
			if (childs.item(i).getNodeName().equalsIgnoreCase(node.getNodeName())) {
				// tag names are equal ==> bump the index.
				index++;
				// is our node the one that is listed ?
				if (childs.item(i).equals(node))
					// We found our node in the parent node list
					break;
			}
		}
		// count the number of elements having the same tag
		int nbElements = 0;
		for (int i = 0; i < childs.getLength(); i++) {
			if (childs.item(i).getNodeName().equalsIgnoreCase(node.getNodeName())) {
				nbElements++;
			}
		}

		String name = node.getNodeName();
		if (name.equalsIgnoreCase("#text"))
			name = "text()";
		name = xpathEscapeColon(name);

		if (nbElements > 1) {
			xpath = name + "[" + index + "]/" + xpath;
		} else {
			// only one element had the same tag ==> do not compute the [xx]
			// syntax..
			xpath = name + "/" + xpath;
		}
		node = current;
	}
	if (xpath.length() > 0)
		// remove the trailing '/'
		xpath = xpath.substring(0, xpath.length() - 1);

	return xpath;
}
 
Example 15
Project: OpenJSharp   File: CoreDocumentImpl.java   Source Code and License Vote up 4 votes
/**
 * 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
Project: OpenJSharp   File: TreeWalker.java   Source Code and License Vote up 4 votes
/**
 * 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 17
Project: openjdk-jdk10   File: CoreDocumentImpl.java   Source Code and License Vote up 4 votes
/**
 * 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 18
Project: openjdk-jdk10   File: DOM3TreeWalker.java   Source Code and License Vote up 4 votes
/**
 * 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 19
Project: openjdk-jdk10   File: DOM3TreeWalker.java   Source Code and License Vote up 4 votes
/**
 * 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 20
Project: openjdk-jdk10   File: TreeWalker.java   Source Code and License Vote up 4 votes
/**
 * 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();
}