org.w3c.dom.traversal.NodeFilter#FILTER_SKIP源码实例Demo

下面列出了org.w3c.dom.traversal.NodeFilter#FILTER_SKIP 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jStyleParser   文件: GenericTreeWalker.java
/**
 * 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;
}
 
源代码2 项目: jStyleParser   文件: GenericTreeWalker.java
/**
 * 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);

}
 
源代码3 项目: jStyleParser   文件: GenericTreeWalker.java
/**
 * Internal function. Return the first child Node, from the input node after
 * applying filter, whatToshow. The current node is not consulted or set.
 */
private Node getFirstChild(Node node) {

	if (node == null)
		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())
		return getFirstChild(newNode);

	// if (accept == NodeFilter.REJECT_NODE)
	return getNextSibling(newNode);
}
 
源代码4 项目: openjdk-jdk8u   文件: TreeWalkerImpl.java
/** 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);
    }

}
 
源代码5 项目: HtmlUnit-Android   文件: DomTreeWalker.java
/**
 * Test whether a specified node is visible in the logical view of a
 * TreeWalker, based solely on the whatToShow constant.
 *
 * @param n The node to check to see if it should be shown or not
 * @return a constant to determine whether the node is accepted, rejected,
 *          or skipped.
 */
private short acceptNode(final Node n) {
    final int flag = getFlagForNode(n);

    if ((whatToShow_ & flag) != 0) {
        return NodeFilter.FILTER_ACCEPT;
    }
    // Skip, don't reject.
    return NodeFilter.FILTER_SKIP;
}
 
源代码6 项目: hottub   文件: TreeWalkerImpl.java
/** 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;
        }
    }
}
 
源代码7 项目: openjdk-8-source   文件: TreeWalkerImpl.java
/** 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);
    }


}
 
源代码8 项目: jdk1.8-source-analysis   文件: TreeWalkerImpl.java
/** 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;
        }
    }
}
 
源代码9 项目: jdk1.8-source-analysis   文件: XMLSerializer.java
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}
 
源代码10 项目: openjdk-jdk9   文件: TreeWalkerImpl.java
/** 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);
    }


}
 
源代码11 项目: TencentKona-8   文件: TreeWalkerImpl.java
/** 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);
    }


}
 
源代码12 项目: hottub   文件: TreeWalkerImpl.java
/** 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);
    }


}
 
源代码13 项目: TencentKona-8   文件: XMLSerializer.java
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}
 
源代码14 项目: jdk8u60   文件: TreeWalkerImpl.java
/** 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);
    }

}
 
源代码15 项目: jdk8u60   文件: TreeWalkerImpl.java
/** 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);
    }

}
 
源代码16 项目: openjdk-8   文件: TreeWalkerImpl.java
/** 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;
        }
    }
}
 
源代码17 项目: openjdk-8-source   文件: XMLSerializer.java
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}
 
源代码18 项目: hottub   文件: TreeWalkerImpl.java
/** 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);
    }


}
 
源代码19 项目: JDKSourceCode1.8   文件: TreeWalkerImpl.java
/** 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);
    }

}
 
源代码20 项目: openjdk-jdk8u-backup   文件: TreeWalkerImpl.java
/** 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);
    }

}