use of jodd.lagarto.dom.Node 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.Node 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.Node in project jodd by oblac.
the class Jerry method children.
// ---------------------------------------------------------------- Traversing
/**
* Gets the immediate children of each element in the set of matched elements.
*/
public Jerry children() {
List<Node> result = new NodeList(nodes.length);
if (nodes.length > 0) {
for (Node node : nodes) {
Node[] children = node.getChildElements();
Collections.addAll(result, children);
}
}
return new Jerry(this, result);
}
use of jodd.lagarto.dom.Node in project jodd by oblac.
the class Jerry method text.
/**
* Sets the content of each element in the set of matched elements to the specified text.
*/
public Jerry text(String text) {
if (nodes.length == 0) {
return this;
}
if (text == null) {
text = StringPool.EMPTY;
}
for (Node node : nodes) {
node.removeAllChilds();
Text textNode = new Text(node.getOwnerDocument(), text);
node.addChild(textNode);
}
return this;
}
use of jodd.lagarto.dom.Node in project jodd by oblac.
the class Jerry method addClass.
/**
* Adds the specified class(es) to each of the set of matched elements.
*/
public Jerry addClass(String... classNames) {
if (nodes.length == 0) {
return this;
}
for (Node node : nodes) {
String attrClass = node.getAttribute("class");
Set<String> classes = createPropertiesSet(attrClass, ' ');
boolean wasChange = false;
for (String className : classNames) {
if (classes.add(className)) {
wasChange = true;
}
}
if (wasChange) {
String attrValue = generateAttributeValue(classes, ' ');
node.setAttribute("class", attrValue);
}
}
return this;
}
Aggregations