16 | | |
17 | | public String getHtml() { |
18 | | |
19 | | if (getZahlavi() == null || getHodnoty() == null || getZahlavi().length < 1) { |
20 | | return "<p>Chybná tabulka</p>"; |
21 | | } else { |
22 | | |
23 | | StringBuffer html = new StringBuffer(); |
24 | | |
25 | | html.append("<table>"); |
26 | | |
27 | | |
28 | | html.append("<thead title=\"Chceš setřídit výsledek podle nějakého sloupce? Co takhle ORDER BY sloupec.\">"); |
29 | | html.append("<tr>"); |
30 | | for (String z : getZahlavi()) { |
31 | | html.append("<td>" + Html.escapuj(z) + "</td>"); |
32 | | } |
33 | | html.append("</tr>"); |
34 | | html.append("</thead>"); |
35 | | |
36 | | |
37 | | html.append("<tbody>"); |
38 | | for (Object[] hh : getHodnoty()) { |
39 | | html.append("<tr>"); |
40 | | for (Object h : hh) { |
41 | | html.append(formatujBunku(h)); |
42 | | } |
43 | | html.append("</tr>"); |
44 | | } |
45 | | html.append("</tbody>"); |
46 | | |
47 | | html.append("</table>"); |
48 | | |
49 | | |
50 | | return html.toString(); |
51 | | } |
52 | | } |
53 | | |
54 | | private String formatujBunku(Object o) { |
55 | | /** TODO: podporovat i jiné typy */ |
56 | | if (o instanceof Integer) { |
57 | | return "<td class=\"cislo\">" + Html.escapuj(String.valueOf(o)) + "</td>"; |
58 | | } else { |
59 | | return "<td>" + Html.escapuj(String.valueOf(o)) + "</td>"; |
60 | | } |
61 | | } |