public abstract class HtmlParentElement extends HtmlElement implements HtmlParent
A parent element contains a list of child pieces, for example
HtmlParentElement div = new Html4.DIV(); div.addChild(new HtmlText("abc")); div.addChild(new Html4.P()); div.render(0, System.out::print); // <div> // abc // <p></p> // </div>
This is an abstract class; a concrete subclass needs to implement HtmlElement.getElementType()
.
An HtmlParentElement must not be a void element.
Modifier | Constructor and Description |
---|---|
protected |
HtmlParentElement()
Protected constructor for subclasses.
|
Instance Methods | |
---|---|
void |
render(int indent,
Consumer<CharSequence> out)
Render this element to `out`.
|
int |
getChildCount()
Get the number of children.
|
HtmlPiece |
getChild(int index)
Get the child at the index.
|
void |
addChild(HtmlPiece child)
Append the child piece.
|
void |
addChildren(Object... children)
Append the child pieces.
|
void |
addChild(int index,
HtmlPiece child)
Insert the child at the index.
|
HtmlPiece |
removeChild(int index)
Remove the child at the index.
|
void |
detachChildren(Object... args)
Detach child pieces from this parent.
|
HtmlPiece |
setChild(int index,
HtmlPiece newChild)
Replace the child at the index.
|
getAttribute, getAttributeCount, getAttributeMap, getElementType, isBlock, setAttribute
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getChildList
protected HtmlParentElement()
public void render(int indent, Consumer<CharSequence> out)
See HtmlElement.render(indent, out)
for attribute rendering.
Child pieces will be rendered in order, possibly with indentations added.
render
in interface HtmlParent
render
in interface HtmlPiece
render
in class HtmlElement
public int getChildCount()
HtmlParent
getChildCount
in interface HtmlParent
public HtmlPiece getChild(int index)
HtmlParent
getChild
in interface HtmlParent
public void addChild(HtmlPiece child)
HtmlParent
addChild
in interface HtmlParent
public void addChildren(Object... children)
HtmlParent
If a `child` in `children` is not an HtmlPiece,
it will be converted to text by new HtmlText(child)
.
addChildren
in interface HtmlParent
public void addChild(int index, HtmlPiece child)
HtmlParent
Required: 0 <= index <= getChildCount()
addChild
in interface HtmlParent
public HtmlPiece removeChild(int index)
HtmlParent
removeChild
in interface HtmlParent
public void detachChildren(Object... args)
HtmlParent
See the specification in
ContentParent.detach(args)
The implementation of this method must treat the array `args` as read-only.
detachChildren
in interface HtmlParent
public HtmlPiece setChild(int index, HtmlPiece newChild)
HtmlParent
setChild
in interface HtmlParent