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

The following examples show how to use org.w3c.dom.traversal.NodeFilter#FILTER_SKIP . 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 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);
}
 
Example 2
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 3
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 4
Source File: TreeWalkerImpl.java    From hottub 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 5
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 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 6
Source File: TreeWalkerImpl.java    From JDKSourceCode1.8 with MIT License 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 7
Source File: TreeWalkerImpl.java    From hottub 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 8
Source File: XMLSerializer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example 9
Source File: TreeWalkerImpl.java    From openjdk-8 with GNU General Public License v2.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 10
Source File: TreeWalkerImpl.java    From jdk8u60 with GNU General Public License v2.0 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 11
Source File: TreeWalkerImpl.java    From jdk8u60 with GNU General Public License v2.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 12
Source File: XMLSerializer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example 13
Source File: TreeWalkerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 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 14
Source File: TreeWalkerImpl.java    From TencentKona-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 15
Source File: TreeWalkerImpl.java    From openjdk-jdk9 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 16
Source File: XMLSerializer.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example 17
Source File: TreeWalkerImpl.java    From jdk1.8-source-analysis 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 18
Source File: TreeWalkerImpl.java    From openjdk-8-source 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 hottub with GNU General Public License v2.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 20
Source File: DomTreeWalker.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}