Java Code Examples for org.w3c.dom.traversal.NodeFilter#FILTER_ACCEPT

The following examples show how to use org.w3c.dom.traversal.NodeFilter#FILTER_ACCEPT . 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: GenericTreeWalker.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Internal function. Return the last child Node, from the input node after
 * applying filter, whatToshow. The current node is not consulted or set.
 */
private Node getLastChild(Node node) {

	if (node == null)
		return null;

	Node newNode = node.getLastChild();
	if (newNode == null)
		return null;

	int accept = acceptNode(newNode);
	if (accept == NodeFilter.FILTER_ACCEPT)
		return newNode;
	else if (accept == NodeFilter.FILTER_SKIP && newNode.hasChildNodes())
		return getLastChild(newNode);

	// if (accept == NodeFilter.REJECT_NODE)
	return getPreviousSibling(newNode);

}
 
Example 2
Source File: TreeWalkerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** Internal function.
 *  Return the parent Node, from the input node
 *  after applying filter, whatToshow.
 *  The current node is not consulted or set.
 */
Node getParentNode(Node node) {

    if (node == null || node == fRoot) return null;

    Node newNode = node.getParentNode();
    if (newNode == null)  return null;

    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    //if (accept == NodeFilter.SKIP_NODE) // and REJECT too.
    {
        return getParentNode(newNode);
    }


}
 
Example 3
Source File: TreeWalkerImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Internal function.
 *  Return the parent Node, from the input node
 *  after applying filter, whatToshow.
 *  The current node is not consulted or set.
 */
Node getParentNode(Node node) {

    if (node == null || node == fRoot) return null;

    Node newNode = node.getParentNode();
    if (newNode == null)  return null;

    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    //if (accept == NodeFilter.SKIP_NODE) // and REJECT too.
    {
        return getParentNode(newNode);
    }


}
 
Example 4
Source File: GenericTreeWalker.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Internal function. The node whatToShow and the filter are combined into
 * one result.
 */
private short acceptNode(Node node) {
	/***
	 * 7.1.2.4. Filters and whatToShow flags
	 * 
	 * Iterator and TreeWalker apply whatToShow flags before applying
	 * Filters. If a node is rejected by the active whatToShow flags, a
	 * Filter will not be called to evaluate that node. When a node is
	 * rejected by the active whatToShow flags, children of that node will
	 * still be considered, and Filters may be called to evaluate them.
	 ***/

	if ((whatToShow & (1 << node.getNodeType() - 1)) != 0)
		return NodeFilter.FILTER_ACCEPT;
	else
		return NodeFilter.FILTER_SKIP;
}
 
Example 5
Source File: TreeWalkerImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/** Internal function.
 *  The node whatToShow and the filter are combined into one result. */
short acceptNode(Node node) {
    /***
     7.1.2.4. Filters and whatToShow flags

     Iterator and TreeWalker apply whatToShow flags before applying Filters. If a node is rejected by the
     active whatToShow flags, a Filter will not be called to evaluate that node. When a node is rejected by
     the active whatToShow flags, children of that node will still be considered, and Filters may be called to
     evaluate them.
     ***/

    if (fNodeFilter == null) {
        if ( ( fWhatToShow & (1 << node.getNodeType()-1)) != 0) {
            return NodeFilter.FILTER_ACCEPT;
        } else {
            return NodeFilter.FILTER_SKIP;
        }
    } else {
        if ((fWhatToShow & (1 << node.getNodeType()-1)) != 0 ) {
            return fNodeFilter.acceptNode(node);
        } else {
            // What to show has failed. See above excerpt from spec.
            // Equivalent to FILTER_SKIP.
            return NodeFilter.FILTER_SKIP;
        }
    }
}
 
Example 6
Source File: TreeWalkerImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Internal function.
 *  Return the last child Node, from the input node
 *  after applying filter, whatToshow.
 *  The current node is not consulted or set.
 */
Node getLastChild(Node node) {

    if (node == null) return null;

    if ( !fEntityReferenceExpansion
         && node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
        return null;

    Node newNode = node.getLastChild();
    if (newNode == null)  return null;

    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    if (accept == NodeFilter.FILTER_SKIP
        && newNode.hasChildNodes())
    {
        Node lChild = getLastChild(newNode);
        if (lChild == null) {
            return getPreviousSibling(newNode, node);
        }
        return lChild;
    }
    else
    //if (accept == NodeFilter.REJECT_NODE)
    {
        return getPreviousSibling(newNode, node);
    }


}
 
Example 7
Source File: TreeWalkerImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/** Internal function.
 *  Return the previousSibling Node, from the input node
 *  after applying filter, whatToshow.
     *  NEVER TRAVERSES ABOVE THE SPECIFIED ROOT NODE.
 *  The current node is not consulted or set.
 */
Node getPreviousSibling(Node node, Node root) {

    if (node == null || node == root) return null;

    Node newNode = node.getPreviousSibling();
    if (newNode == null) {

        newNode = node.getParentNode();
        if (newNode == null || newNode == root)  return null;

        int parentAccept = acceptNode(newNode);

        if (parentAccept==NodeFilter.FILTER_SKIP) {
            return getPreviousSibling(newNode, root);
        }

        return null;
    }

    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    if (accept == NodeFilter.FILTER_SKIP) {
        Node fChild =  getLastChild(newNode);
        if (fChild == null) {
            return getPreviousSibling(newNode, root);
        }
        return fChild;
    }
    else
    //if (accept == NodeFilter.REJECT_NODE)
    {
        return getPreviousSibling(newNode, root);
    }

}
 
Example 8
Source File: NodeIteratorImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** The node is accepted if it passes the whatToShow and the filter. */
boolean acceptNode(Node node) {

    if (fNodeFilter == null) {
        return ( fWhatToShow & (1 << node.getNodeType()-1)) != 0 ;
    } else {
        return ((fWhatToShow & (1 << node.getNodeType()-1)) != 0 )
            && fNodeFilter.acceptNode(node) == NodeFilter.FILTER_ACCEPT;
    }
}
 
Example 9
Source File: TreeWalkerImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/** Internal function.
 *  Return the last child Node, from the input node
 *  after applying filter, whatToshow.
 *  The current node is not consulted or set.
 */
Node getLastChild(Node node) {

    if (node == null) return null;

    if ( !fEntityReferenceExpansion
         && node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
        return null;

    Node newNode = node.getLastChild();
    if (newNode == null)  return null;

    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    if (accept == NodeFilter.FILTER_SKIP
        && newNode.hasChildNodes())
    {
        Node lChild = getLastChild(newNode);
        if (lChild == null) {
            return getPreviousSibling(newNode, node);
        }
        return lChild;
    }
    else
    //if (accept == NodeFilter.REJECT_NODE)
    {
        return getPreviousSibling(newNode, node);
    }


}
 
Example 10
Source File: NodeIteratorImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/** The node is accepted if it passes the whatToShow and the filter. */
boolean acceptNode(Node node) {

    if (fNodeFilter == null) {
        return ( fWhatToShow & (1 << node.getNodeType()-1)) != 0 ;
    } else {
        return ((fWhatToShow & (1 << node.getNodeType()-1)) != 0 )
            && fNodeFilter.acceptNode(node) == NodeFilter.FILTER_ACCEPT;
    }
}
 
Example 11
Source File: NodeIteratorImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/** The node is accepted if it passes the whatToShow and the filter. */
boolean acceptNode(Node node) {

    if (fNodeFilter == null) {
        return ( fWhatToShow & (1 << node.getNodeType()-1)) != 0 ;
    } else {
        return ((fWhatToShow & (1 << node.getNodeType()-1)) != 0 )
            && fNodeFilter.acceptNode(node) == NodeFilter.FILTER_ACCEPT;
    }
}
 
Example 12
Source File: GetSpringImportsFilter.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
@Override
public short startElement(Element element) {
    if (DomUtils.nodeNameEquals(element, "import")) {
        String resourceLocation = element.getAttribute("resource");

        if (StringUtils.hasText(resourceLocation)) {
            if (resourceLocation.startsWith("classpath:")) {
                resourceLocation = resourceLocation.substring("classpath:".length());
            } else if (resourceLocation.startsWith("file:")) {
                resourceLocation = resourceLocation.substring("file:".length());
            }

            try {
                File importedFile = new FileSystemResource(parentConfigFile.getParentFile().getCanonicalPath() +
                        File.separator + resourceLocation).getFile();

                if (importedFile.exists()) {
                    importedFiles.add(importedFile);
                }
            } catch (IOException e) {
                log.warn("Unable to resolve imported file resource location", e);
            }
        }
    }

    return NodeFilter.FILTER_ACCEPT;
}
 
Example 13
Source File: TreeWalkerImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Internal function.
 *  Return the first child Node, from the input node
 *  after applying filter, whatToshow.
 *  The current node is not consulted or set.
 */
Node getFirstChild(Node node) {
    if (node == null) return null;

    if ( !fEntityReferenceExpansion
         && node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
        return null;
    Node newNode = node.getFirstChild();
    if (newNode == null)  return null;
    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    if (accept == NodeFilter.FILTER_SKIP
        && newNode.hasChildNodes())
    {
        Node fChild = getFirstChild(newNode);

        if (fChild == null) {
            return getNextSibling(newNode, node);
        }
        return fChild;
    }
    else
    //if (accept == NodeFilter.REJECT_NODE)
    {
        return getNextSibling(newNode, node);
    }


}
 
Example 14
Source File: NodeIteratorImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/** The node is accepted if it passes the whatToShow and the filter. */
boolean acceptNode(Node node) {

    if (fNodeFilter == null) {
        return ( fWhatToShow & (1 << node.getNodeType()-1)) != 0 ;
    } else {
        return ((fWhatToShow & (1 << node.getNodeType()-1)) != 0 )
            && fNodeFilter.acceptNode(node) == NodeFilter.FILTER_ACCEPT;
    }
}
 
Example 15
Source File: TreeWalkerImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/** Internal function.
 *  Return the last child Node, from the input node
 *  after applying filter, whatToshow.
 *  The current node is not consulted or set.
 */
Node getLastChild(Node node) {

    if (node == null) return null;

    if ( !fEntityReferenceExpansion
         && node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
        return null;

    Node newNode = node.getLastChild();
    if (newNode == null)  return null;

    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    if (accept == NodeFilter.FILTER_SKIP
        && newNode.hasChildNodes())
    {
        Node lChild = getLastChild(newNode);
        if (lChild == null) {
            return getPreviousSibling(newNode, node);
        }
        return lChild;
    }
    else
    //if (accept == NodeFilter.REJECT_NODE)
    {
        return getPreviousSibling(newNode, node);
    }


}
 
Example 16
Source File: TreeWalkerImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/** Internal function.
 *  Return the last child Node, from the input node
 *  after applying filter, whatToshow.
 *  The current node is not consulted or set.
 */
Node getLastChild(Node node) {

    if (node == null) return null;

    if ( !fEntityReferenceExpansion
         && node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
        return null;

    Node newNode = node.getLastChild();
    if (newNode == null)  return null;

    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    if (accept == NodeFilter.FILTER_SKIP
        && newNode.hasChildNodes())
    {
        Node lChild = getLastChild(newNode);
        if (lChild == null) {
            return getPreviousSibling(newNode, node);
        }
        return lChild;
    }
    else
    //if (accept == NodeFilter.REJECT_NODE)
    {
        return getPreviousSibling(newNode, node);
    }


}
 
Example 17
Source File: TreeWalkerImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/** Internal function.
 *  Return the first child Node, from the input node
 *  after applying filter, whatToshow.
 *  The current node is not consulted or set.
 */
Node getFirstChild(Node node) {
    if (node == null) return null;

    if ( !fEntityReferenceExpansion
         && node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
        return null;
    Node newNode = node.getFirstChild();
    if (newNode == null)  return null;
    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    if (accept == NodeFilter.FILTER_SKIP
        && newNode.hasChildNodes())
    {
        Node fChild = getFirstChild(newNode);

        if (fChild == null) {
            return getNextSibling(newNode, node);
        }
        return fChild;
    }
    else
    //if (accept == NodeFilter.REJECT_NODE)
    {
        return getNextSibling(newNode, node);
    }


}
 
Example 18
Source File: TreeWalkerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** Internal function.
 *  Return the first child Node, from the input node
 *  after applying filter, whatToshow.
 *  The current node is not consulted or set.
 */
Node getFirstChild(Node node) {
    if (node == null) return null;

    if ( !fEntityReferenceExpansion
         && node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
        return null;
    Node newNode = node.getFirstChild();
    if (newNode == null)  return null;
    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    if (accept == NodeFilter.FILTER_SKIP
        && newNode.hasChildNodes())
    {
        Node fChild = getFirstChild(newNode);

        if (fChild == null) {
            return getNextSibling(newNode, node);
        }
        return fChild;
    }
    else
    //if (accept == NodeFilter.REJECT_NODE)
    {
        return getNextSibling(newNode, node);
    }


}
 
Example 19
Source File: TreeWalkerImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/** Internal function.
 *  Return the nextSibling Node, from the input node
 *  after applying filter, whatToshow.
 *  NEVER TRAVERSES ABOVE THE SPECIFIED ROOT NODE.
 *  The current node is not consulted or set.
 */
Node getNextSibling(Node node, Node root) {

    if (node == null || node == root) return null;

    Node newNode = node.getNextSibling();
    if (newNode == null) {

        newNode = node.getParentNode();

        if (newNode == null || newNode == root)  return null;

        int parentAccept = acceptNode(newNode);

        if (parentAccept==NodeFilter.FILTER_SKIP) {
            return getNextSibling(newNode, root);
        }

        return null;
    }

    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    if (accept == NodeFilter.FILTER_SKIP) {
        Node fChild = getFirstChild(newNode);
        if (fChild == null) {
            return getNextSibling(newNode, root);
        }
        return fChild;
    }
    else
    //if (accept == NodeFilter.REJECT_NODE)
    {
        return getNextSibling(newNode, root);
    }

}
 
Example 20
Source File: DomNodeIterator.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
private boolean isAccepted(final Node node) {
    if (filter_ == null) {
        return true;
    }
    return filter_.acceptNode(node) == NodeFilter.FILTER_ACCEPT;
}