public final class JkDomElement<P>
extends java.lang.Object
Element
offering a Parent-Chaining fluent interface.
The underlying element may exist or not. If the underlying element does not exist,
a proxy element is used in place but write methods are disabled. The concrete w3c element
can be created afterward using the make()
method.
Modifier and Type | Method and Description |
---|---|
JkDomElement<JkDomElement<P>> |
add(java.lang.String name)
Adds a child element of the specified name on the underlying element.
|
JkDomElement<P> |
addSibling(java.lang.String name)
Adds a sibling element of the specified name just before this one.
|
JkDomElement<P> |
apply(java.util.function.Consumer<JkDomElement<?>> consumer)
Runs the specified consumer with this element as argument.
|
java.lang.String |
attr(java.lang.String name)
Returns the value of the specified attribute on this element.
|
JkDomElement<P> |
attr(java.lang.String name,
java.lang.String value)
Adds the specified attribute name/value on the underlying element.
|
JkDomElement |
child(java.lang.String name)
Returns the child first child of this element having the specified name.
|
JkDomElement |
child(java.lang.String name,
java.util.function.Predicate<JkDomElement> predicate)
Returns the child first child of this element having the specified name and verifying the specified predicate.
|
java.util.List<JkDomElement> |
children(java.lang.String name)
Returns an unmodifiable list of the child elements having the specified name.
|
java.util.List<JkDomElement> |
children(java.lang.String name,
java.util.function.Predicate<JkDomElement> predicate)
Returns an unmodifiable list of the child elements having the specified name and verifying the specified predicate.
|
boolean |
exist()
Returns
true if the underlying element exist. |
JkDomElement<JkDomElement<P>> |
get(java.lang.String name)
Returns the first child element of the underlying element having the specified name.
|
org.w3c.dom.Element |
getW3cElement()
Returns the underlying w3cElement.
|
JkDomElement<P> |
make()
Creates the underlying element and its non-existing parents.
|
static JkDomElement<java.lang.Void> |
of(org.w3c.dom.Element element)
Creates a VElement wrapping the specified element.
|
static <P> JkDomElement |
of(P parent,
org.w3c.dom.Element element)
Creates a VElement wrapping the specified parent and element.
|
JkDomElement<P> |
remove()
Removes the underlying element from its parent children.
|
JkDomElement<P> |
removeAttr(java.lang.String name)
Removes the specified attribute of the specified name from the underlying element.
|
java.lang.String |
text()
Returns the text pof the underlying element.
|
JkDomElement<P> |
text(java.lang.String text)
Sets the specified text on the underlying element.
|
java.lang.String |
toString() |
java.util.List<JkDomElement> |
xPath(java.lang.String xPathExpression)
Returns an unmodifiable list of elements matching the specified xPath expression.
|
java.util.List<JkDomElement> |
xPath(javax.xml.xpath.XPathExpression xPathExpression)
Returns an unmodifiable list of elements matching the specified xPath expression.
|
public final P __
public static JkDomElement<java.lang.Void> of(org.w3c.dom.Element element)
public static <P> JkDomElement of(P parent, org.w3c.dom.Element element)
public org.w3c.dom.Element getW3cElement()
public JkDomElement<P> attr(java.lang.String name, java.lang.String value)
java.lang.IllegalStateException
- if the underlying element does not exist.public java.lang.String attr(java.lang.String name)
null
if no such
attribute exists.public JkDomElement<P> removeAttr(java.lang.String name)
java.lang.IllegalStateException
- if the underlying element does not exist.public JkDomElement<P> text(java.lang.String text)
java.lang.IllegalStateException
- if the underlying element does not exist.public java.lang.String text()
null
if the underlying element does not exist.public JkDomElement<JkDomElement<P>> add(java.lang.String name)
java.lang.IllegalStateException
- if the underlying element does not exist.public JkDomElement<JkDomElement<P>> get(java.lang.String name)
If no such element exist, this method returns a proxy element that let creation possible afterward.
public java.util.List<JkDomElement> children(java.lang.String name, java.util.function.Predicate<JkDomElement> predicate)
public java.util.List<JkDomElement> children(java.lang.String name)
public JkDomElement child(java.lang.String name, java.util.function.Predicate<JkDomElement> predicate)
null if the underlying element does not exist or no such named child exists.
public JkDomElement child(java.lang.String name)
null if the underlying element does not exist or no such named child exists.
public java.util.List<JkDomElement> xPath(javax.xml.xpath.XPathExpression xPathExpression)
public java.util.List<JkDomElement> xPath(java.lang.String xPathExpression)
public JkDomElement<P> addSibling(java.lang.String name)
public JkDomElement<P> remove()
public JkDomElement<P> apply(java.util.function.Consumer<JkDomElement<?>> consumer)
public boolean exist()
true
if the underlying element exist.public JkDomElement<P> make()
public java.lang.String toString()
toString
in class java.lang.Object