use of jodd.lagarto.dom.NodeSelector in project jodd by oblac.
the class JerryMiscTest method test250.
@Test
public void test250() {
String html = "<html>\n" + " <body>\n" + " <a href=\"/go?to=foobar&index=null\" title=\"Choice 1\">link</a>\n" + " </body>\n" + "</html>";
LagartoDOMBuilder domBuilder = new LagartoDOMBuilder();
NodeSelector nodeSelector = new NodeSelector(domBuilder.parse(html));
List<Node> selectedNodes = nodeSelector.select("a[title='Choice 1']");
System.out.println();
assertEquals("/go?to=foobar&index=null", selectedNodes.get(0).getAttribute("href"));
}
use of jodd.lagarto.dom.NodeSelector in project jodd by oblac.
the class Jerry method filter.
/**
* Reduces the set of matched elements to those that match the selector.
*/
public Jerry filter(String cssSelectors) {
List<Node> result = new NodeList(nodes.length);
if (nodes.length > 0) {
for (Node node : nodes) {
Node parentNode = node.getParentNode();
if (parentNode == null) {
continue;
}
NodeSelector nodeSelector = createNodeSelector(parentNode);
List<Node> selectedNodes = nodeSelector.select(cssSelectors);
for (Node selected : selectedNodes) {
if (node == selected) {
result.add(node);
}
}
}
}
return new Jerry(this, result);
}
use of jodd.lagarto.dom.NodeSelector in project jodd by oblac.
the class Jerry method find.
/**
* Gets the descendants of each element in the current set of matched elements,
* filtered by a selector.
*/
public Jerry find(String cssSelector) {
final List<Node> result = new NodeList();
if (nodes.length > 0) {
for (Node node : nodes) {
NodeSelector nodeSelector = createNodeSelector(node);
List<Node> filteredNodes = nodeSelector.select(cssSelector);
result.addAll(filteredNodes);
}
}
return new Jerry(this, result);
}
use of jodd.lagarto.dom.NodeSelector in project jodd by oblac.
the class Jerry method has.
/**
* Reduce the set of matched elements to those that have a descendant that
* matches the selector or DOM element.
*/
public Jerry has(String cssSelectors) {
List<Node> result = new NodeList(nodes.length);
if (nodes.length > 0) {
for (Node node : nodes) {
NodeSelector nodeSelector = createNodeSelector(node);
List<Node> selectedNodes = nodeSelector.select(cssSelectors);
if (!selectedNodes.isEmpty()) {
result.add(node);
}
}
}
return new Jerry(this, result);
}
use of jodd.lagarto.dom.NodeSelector in project jodd by oblac.
the class Jerry method is.
/**
* Checks the current matched set of elements against a selector and
* return <code>true</code> if at least one of these elements matches
* the given arguments.
*/
public boolean is(String cssSelectors) {
if (nodes.length == 0) {
return false;
}
for (Node node : nodes) {
Node parentNode = node.getParentNode();
if (parentNode == null) {
continue;
}
NodeSelector nodeSelector = createNodeSelector(parentNode);
List<Node> selectedNodes = nodeSelector.select(cssSelectors);
for (Node selected : selectedNodes) {
if (node == selected) {
return true;
}
}
}
return false;
}
Aggregations