package pt.ist.renderers.components; import java.util.ArrayList; import java.util.List; import javax.servlet.jsp.PageContext; import pt.ist.renderers.components.tags.HtmlTag; public abstract class HtmlContainer extends HtmlComponent { private List children; public HtmlContainer() { super(); children = new ArrayList(); } public void addChild(HtmlComponent component) { this.children.add(component); } public List getChildren() { return this.children; } public void removeChild(HtmlComponent container) { this.children.remove(container); } public void clearChildren() { this.children = new ArrayList(); } @Override public HtmlTag getOwnTag(PageContext context) { HtmlTag tag = super.getOwnTag(context); for (HtmlComponent component : getChildren()) { tag.addChild(component.getOwnTag(context)); } // force close tag to appear if (tag.getChildren().isEmpty()) { tag.addChild(new HtmlTag(null)); } return tag; } }