package cz.frantovo.sql.vyuka.dto; import cz.frantovo.sql.vyuka.Html; import java.util.ArrayList; import java.util.Collection; /** * Tabulka, která je výsledkem SQL dotazu. * @author fiki */ public class Tabulka implements HtmlObjekt { private String[] zahlavi; private Collection hodnoty = new ArrayList(); public String getHtml() { if (getZahlavi() == null || getHodnoty() == null || getZahlavi().length < 1) { return "

Chybná tabulka

"; } else { StringBuffer html = new StringBuffer(); html.append(""); html.append(""); html.append(""); for (String z : getZahlavi()) { html.append(""); } html.append(""); html.append(""); html.append(""); for (Object[] hh : getHodnoty()) { html.append(""); for (Object h : hh) { html.append(formatujBunku(h)); } html.append(""); } html.append(""); html.append("
" + Html.escapuj(z) + "
"); return html.toString(); } } private String formatujBunku(Object o) { /** TODO: podporovat i jiné typy */ if (o instanceof Integer) { return "" + Html.escapuj(String.valueOf(o)) + ""; } else { return "" + Html.escapuj(String.valueOf(o)) + ""; } } public String[] getZahlavi() { return zahlavi; } public void setZahlavi(String[] zahlavi) { this.zahlavi = zahlavi; } public Collection getHodnoty() { return hodnoty; } public void setHodnoty(Collection hodnoty) { this.hodnoty = hodnoty; } }