Changeset 25:97bb16063d9e
- Timestamp:
- 05/31/09 17:53:15 (15 years ago)
- Author:
- František Kučera <franta-hg@…>
- Branch:
- default
- Message:
-
Přechod ze servletu na JSP – zbavení se servletu a HTML uvnitř javového kódu.
- Location:
- java/sql-vyuka/src/java/cz/frantovo/sql/vyuka
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
r24
|
r25
|
|
1 | 1 | package cz.frantovo.sql.vyuka.dto; |
2 | | |
3 | | import cz.frantovo.sql.vyuka.Html; |
4 | 2 | |
5 | 3 | /** |
… |
… |
|
7 | 5 | * @author fiki |
8 | 6 | */ |
9 | | public class Hlaska implements HtmlObjekt { |
| 7 | public class Hlaska { |
10 | 8 | |
| 9 | public enum Typ { |
| 10 | |
| 11 | OK, |
| 12 | Tip, |
| 13 | Varovani, |
| 14 | Chyba |
| 15 | } |
11 | 16 | private String text; |
12 | 17 | private Typ typ; |
… |
… |
|
36 | 41 | } |
37 | 42 | |
38 | | public String getHtml() { |
39 | | String hodnota; |
40 | | if (isEscapovat()) { |
41 | | hodnota = Html.escapuj(text); |
42 | | } else { |
43 | | hodnota = text; |
44 | | } |
45 | | return "<p class=\"vysledek" + getTyp().name() + "\">" + hodnota + "</p>"; |
46 | | } |
47 | | |
48 | 43 | public String getText() { |
49 | 44 | return text; |
… |
… |
|
69 | 64 | this.escapovat = escapovat; |
70 | 65 | } |
71 | | |
72 | | public enum Typ { |
73 | | |
74 | | OK, |
75 | | Tip, |
76 | | Varovani, |
77 | | Chyba |
78 | | } |
79 | 66 | } |
-
r24
|
r25
|
|
1 | 1 | package cz.frantovo.sql.vyuka.dto; |
2 | 2 | |
3 | | import cz.frantovo.sql.vyuka.Html; |
4 | 3 | import java.util.ArrayList; |
5 | 4 | import java.util.Collection; |
… |
… |
|
9 | 8 | * @author fiki |
10 | 9 | */ |
11 | | public class Tabulka implements HtmlObjekt { |
| 10 | public class Tabulka { |
12 | 11 | |
13 | 12 | private String[] zahlavi; |
14 | 13 | private String zahlaviTip; |
15 | 14 | private Collection<Object[]> hodnoty = new ArrayList<Object[]>(); |
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 | | } |
62 | 15 | |
63 | 16 | public String[] getZahlavi() { |
-
r12
|
r25
|
|
5 | 5 | |
6 | 6 | /** |
7 | | * Výsledek SQL dotazu |
| 7 | * Výsledek SQL dotazu. |
| 8 | * Obsahuje tabulky a hlášky. |
8 | 9 | * @author fiki |
9 | 10 | */ |
10 | | public class VysledekSQL implements HtmlObjekt { |
| 11 | public class VysledekSQL { |
11 | 12 | |
12 | 13 | private Collection<Tabulka> tabulky = new ArrayList<Tabulka>(); |
… |
… |
|
20 | 21 | return hlasky; |
21 | 22 | } |
22 | | |
23 | | public String getHtml() { |
24 | | StringBuffer html = new StringBuffer(); |
25 | | |
26 | | for (Tabulka t : tabulky) { |
27 | | html.append(t.getHtml()); |
28 | | } |
29 | | |
30 | | for (Hlaska h : hlasky) { |
31 | | html.append(h.getHtml()); |
32 | | } |
33 | | |
34 | | return html.toString(); |
35 | | } |
36 | 23 | } |
-
r24
|
r25
|
|
18 | 18 | * Nastaví informace o klientovi (uživateli). |
19 | 19 | * @param ipAdresa IP adresa, ze které přišel HTTP požadavek |
20 | | * @param ipPresmerovano HTTP hlavička x-forwarded-for |
| 20 | * @param ipPresmerovano HTTP hlavička x-forwarded-for (přidává proxy). |
21 | 21 | * @param idSezeni javovská HTTP relace |
22 | 22 | */ |