Example usage for org.dom4j NodeFilter matches

List of usage examples for org.dom4j NodeFilter matches

Introduction

In this page you can find the example usage for org.dom4j NodeFilter matches.

Prototype

boolean matches(Node node);

Source Link

Document

matches returns true if the given node matches the filter condition.

Usage

From source file:org.apache.taglibs.xtags.xpath.AbstractTag.java

License:Apache License

/** @return true if the given filter matches a node in the 
  * input nodes/* w  w  w  . j av a  2s .  com*/
  */
public boolean matches(NodeFilter filter) {
    Object input = getInputNodes(false);
    if (input == null) {
        // use an empty document to support
        // filters that just use XPath variables
        // such as "$foo='bar'"
        input = EMPTY_DOCUMENT;
    }
    if (input instanceof List) {
        List list = (List) input;
        for (Iterator iter = list.iterator(); iter.hasNext();) {
            Object object = iter.next();
            if (object instanceof Node) {
                Node node = (Node) object;
                if (filter.matches(node)) {
                    return true;
                }
            }
        }
    } else if (input instanceof Node) {
        Node node = (Node) input;
        if (filter.matches(node)) {
            return true;
        }
    }
    return false;
}