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 class HtmlList extends HtmlComponent { private List items; private boolean ordered; public HtmlList() { super(); this.items = new ArrayList(); this.ordered = false; } public void setOrdered(boolean ordered) { this.ordered = ordered; } public boolean isOrdered() { return this.ordered; } public HtmlListItem createItem() { HtmlListItem newItem = new HtmlListItem(); this.items.add(newItem); return newItem; } public HtmlListItem createItem(int index) { HtmlListItem newItem = new HtmlListItem(); this.items.add(index, newItem); return newItem; } @Override public List getChildren() { List children = new ArrayList(super.getChildren()); children.addAll(this.items); return children; } public List getItems() { return this.items; } @Override public HtmlTag getOwnTag(PageContext context) { HtmlTag tag = super.getOwnTag(context); tag.setName(isOrdered() ? "ol" : "ul"); for (HtmlListItem item : this.items) { tag.addChild(item.getOwnTag(context)); } return tag; } }