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, setAttributeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetChildListprotected 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 HtmlParentrender in interface HtmlPiecerender in class HtmlElementpublic int getChildCount()
HtmlParentgetChildCount in interface HtmlParentpublic HtmlPiece getChild(int index)
HtmlParentgetChild in interface HtmlParentpublic void addChild(HtmlPiece child)
HtmlParentaddChild in interface HtmlParentpublic 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 HtmlParentpublic void addChild(int index,
HtmlPiece child)
HtmlParentRequired: 0 <= index <= getChildCount()
addChild in interface HtmlParentpublic HtmlPiece removeChild(int index)
HtmlParentremoveChild in interface HtmlParentpublic 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 HtmlParentpublic HtmlPiece setChild(int index, HtmlPiece newChild)
HtmlParentsetChild in interface HtmlParent