Search in sources :

Example 21 with Node

use of jodd.lagarto.dom.Node in project jodd by oblac.

the class Jerry method contents.

/**
	* Get the children of each element in the set of matched elements, 
	* including text and comment nodes.
	*/
public Jerry contents() {
    List<Node> result = new NodeList(nodes.length);
    if (nodes.length > 0) {
        for (Node node : nodes) {
            Node[] contents = node.getChildNodes();
            Collections.addAll(result, contents);
        }
    }
    return new Jerry(this, result);
}
Also used : Node(jodd.lagarto.dom.Node)

Example 22 with Node

use of jodd.lagarto.dom.Node in project jodd by oblac.

the class Jerry method eq.

/**
	 * Reduces the set of matched elements to the one at the specified index.
	 */
public Jerry eq(int value) {
    List<Node> result = new NodeList(1);
    int matchingIndex = value >= 0 ? value : nodes.length + value;
    if (nodes.length > 0) {
        int index = 0;
        for (Node node : nodes) {
            if (index == matchingIndex) {
                result.add(node);
                break;
            }
            index++;
        }
    }
    return new Jerry(this, result);
}
Also used : Node(jodd.lagarto.dom.Node)

Example 23 with Node

use of jodd.lagarto.dom.Node in project jodd by oblac.

the class Jerry method not.

/**
	 * Removes elements from the set of matched elements.
	 */
public Jerry not(String cssSelector) {
    Node[] notNodes = root().find(cssSelector).nodes;
    List<Node> result = new NodeList(nodes.length);
    if (nodes.length > 0) {
        for (Node node : nodes) {
            if (!ArraysUtil.contains(notNodes, node)) {
                result.add(node);
            }
        }
    }
    return new Jerry(this, result);
}
Also used : Node(jodd.lagarto.dom.Node)

Example 24 with Node

use of jodd.lagarto.dom.Node in project jodd by oblac.

the class Jerry method each.

/**
	 * Iterates over a jQuery object, executing a function for
	 * each matched element.
	 * @see #eachNode(JerryNodeFunction)
	 */
public Jerry each(JerryFunction function) {
    for (int i = 0; i < nodes.length; i++) {
        Node node = nodes[i];
        Jerry $this = new Jerry(this, node);
        Boolean result = function.onNode($this, i);
        if (result != null && result == Boolean.FALSE) {
            break;
        }
    }
    return this;
}
Also used : Node(jodd.lagarto.dom.Node)

Example 25 with Node

use of jodd.lagarto.dom.Node in project jodd by oblac.

the class Jerry method nextAll.

/**
	 * Get all following siblings of each element in the set of matched 
	 * elements, optionally filtered by a selector.
	 */
public Jerry nextAll() {
    List<Node> result = new NodeList(nodes.length);
    if (nodes.length > 0) {
        for (Node node : nodes) {
            Node currentSiblingElement = node.getNextSiblingElement();
            while (currentSiblingElement != null) {
                result.add(currentSiblingElement);
                currentSiblingElement = currentSiblingElement.getNextSiblingElement();
            }
        }
    }
    return new Jerry(this, result);
}
Also used : Node(jodd.lagarto.dom.Node)

Aggregations

Node (jodd.lagarto.dom.Node)30 Document (jodd.lagarto.dom.Document)7 NodeSelector (jodd.lagarto.dom.NodeSelector)6 LagartoDOMBuilder (jodd.lagarto.dom.LagartoDOMBuilder)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Text (jodd.lagarto.dom.Text)1