Example usage for org.jsoup.nodes Element siblingIndex

List of usage examples for org.jsoup.nodes Element siblingIndex

Introduction

In this page you can find the example usage for org.jsoup.nodes Element siblingIndex.

Prototype

public int siblingIndex() 

Source Link

Document

Get the list index of this node in its node sibling list.

Usage

From source file:cn.wanghaomiao.xpath.core.XpathEvaluator.java

/**
 * //from   ww  w  .jav  a2s . c o  m
 *
 * @param e
 * @param node
 * @return
 */
public Element filter(Element e, Node node) throws NoSuchFunctionException, NoSuchAxisException {
    if (node.getTagName().equals("*") || node.getTagName().equals(e.nodeName())) {
        if (node.getPredicate() != null && StringUtils.isNotBlank(node.getPredicate().getValue())) {
            Predicate p = node.getPredicate();
            if (p.getOpEm() == null) {
                if (p.getValue().matches("\\d+") && getElIndex(e) == Integer.parseInt(p.getValue())) {
                    return e;
                } else if (p.getValue().endsWith("()")
                        && (Boolean) callFilterFunc(p.getValue().substring(0, p.getValue().length() - 2), e)) {
                    return e;
                } else if (p.getValue().startsWith("@")
                        && e.hasAttr(StringUtils.substringAfter(p.getValue(), "@"))) {
                    return e;
                }
                //todo p.value ~= contains(./@href,'renren.com')
            } else {
                if (p.getLeft().matches("[^/]+\\(\\)")) {
                    Object filterRes = p.getOpEm().excute(
                            callFilterFunc(p.getLeft().substring(0, p.getLeft().length() - 2), e).toString(),
                            p.getRight());
                    if (filterRes instanceof Boolean && (Boolean) filterRes) {
                        return e;
                    } else if (filterRes instanceof Integer
                            && e.siblingIndex() == Integer.parseInt(filterRes.toString())) {
                        return e;
                    }
                } else if (p.getLeft().startsWith("@")) {
                    String lValue = e.attr(p.getLeft().substring(1));
                    Object filterRes = p.getOpEm().excute(lValue, p.getRight());
                    if ((Boolean) filterRes) {
                        return e;
                    }
                } else {
                    // ???xpath?
                    List<Element> eltmp = new LinkedList<Element>();
                    eltmp.add(e);
                    List<JXNode> rstmp = evaluate(p.getLeft(), new Elements(eltmp));
                    if ((Boolean) p.getOpEm().excute(StringUtils.join(rstmp, ""), p.getRight())) {
                        return e;
                    }
                }
            }
        } else {
            return e;
        }
    }
    return null;
}