01: /*
02: This file is part of the Tutorial chapter of "Getting Started with Enhydra".
03: It is not meant to be used in any other context.
04: */
05:
06: package simpleapp.presentation;
07:
08: import java.util.Date; //import com.lutris.xml.xmlc.*;
09: import org.enhydra.xml.xmlc.*;
10: import com.lutris.appserver.server.httpPresentation.*;
11: import org.w3c.dom.html.*;
12: import org.w3c.dom.*;
13:
14: import simpleapp.spec.SimpleListOfDiscsFactory;
15: import simpleapp.spec.SimpleListOfDiscs;
16:
17: public class SimplePresentation implements HttpPresentation {
18:
19: /*
20: String[][] discList =
21: { { "Felonious Monk Fish", "Deep Sea Blues", "Jazz", "Yes" },
22: { "Funky Urchin", "Lovely Spines", "Techno Pop", "Yes" },
23: { "Stinky Pups", "Shark Attack", "Hardcore", "No" } };
24: */
25:
26: public void run(HttpPresentationComms comms)
27: throws HttpPresentationException {
28:
29: String[][] discList;
30: try {
31: SimpleListOfDiscs sdl = SimpleListOfDiscsFactory
32: .createSimpleListOfDiscs("simpleapp.business.SimpleListOfDiscsImpl");
33: discList = sdl.getDiscList();
34: } catch (Exception ex) {
35: System.out.println("Exception: " + ex);
36:
37: discList = new String[1][4];
38: discList[0][0] = "SORRY, ";
39: discList[0][1] = "NO ";
40: discList[0][2] = "DISCS ";
41: discList[0][3] = "AVAILABLE!";
42:
43: }
44:
45: String now = new Date().toString();
46: // SimpleHTML simple = new SimpleHTML();
47: SimpleHTML simple = (SimpleHTML) comms.xmlcFactory
48: .create(SimpleHTML.class);
49:
50: simple.setTextTime(now);
51:
52: HTMLTableRowElement templateRow = simple
53: .getElementTemplateRow();
54: HTMLElement artistCellTemplate = simple.getElementArtist();
55: HTMLElement titleCellTemplate = simple.getElementTitle();
56: HTMLElement genreCellTemplate = simple.getElementGenre();
57: HTMLElement likeThisDisc = simple.getElementLikeThisDisc();
58:
59: templateRow.removeAttribute("id");
60: artistCellTemplate.removeAttribute("id");
61: titleCellTemplate.removeAttribute("id");
62: genreCellTemplate.removeAttribute("id");
63: likeThisDisc.removeAttribute("id");
64:
65: Node discTable = templateRow.getParentNode();
66:
67: for (int numDiscs = 0; numDiscs < discList.length; numDiscs++) {
68: simple.setTextArtist(discList[numDiscs][0]);
69: simple.setTextTitle(discList[numDiscs][1]);
70: simple.setTextGenre(discList[numDiscs][2]);
71: simple.setTextLikeThisDisc(discList[numDiscs][3]);
72: discTable.appendChild(templateRow.cloneNode(true));
73: }
74:
75: discTable.removeChild(templateRow);
76:
77: comms.response.writeHTML(simple.toDocument());
78: }
79:
80: }
|