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;
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: public class SimplePresentation implements HttpPresentation {
15:
16: String[][] discList = {
17: { "Felonious Monk Fish", "Deep Sea Blues", "Jazz", "Yes" },
18: { "Funky Urchin", "Lovely Spines", "Techno Pop", "Yes" },
19: { "Stinky Pups", "Shark Attack", "Hardcore", "No" } };
20:
21: public void run(HttpPresentationComms comms)
22: throws HttpPresentationException {
23:
24: String now = new Date().toString();
25: // SimpleHTML simple = new SimpleHTML();
26: SimpleHTML simple = (SimpleHTML) comms.xmlcFactory
27: .create(SimpleHTML.class);
28:
29: simple.setTextTime(now);
30:
31: HTMLTableRowElement templateRow = simple
32: .getElementTemplateRow();
33: HTMLElement artistCellTemplate = simple.getElementArtist();
34: HTMLElement titleCellTemplate = simple.getElementTitle();
35: HTMLElement genreCellTemplate = simple.getElementGenre();
36: HTMLElement likeThisDisc = simple.getElementLikeThisDisc();
37:
38: templateRow.removeAttribute("id");
39: artistCellTemplate.removeAttribute("id");
40: titleCellTemplate.removeAttribute("id");
41: genreCellTemplate.removeAttribute("id");
42: likeThisDisc.removeAttribute("id");
43:
44: Node discTable = templateRow.getParentNode();
45:
46: for (int numDiscs = 0; numDiscs < discList.length; numDiscs++) {
47: simple.setTextArtist(discList[numDiscs][0]);
48: simple.setTextTitle(discList[numDiscs][1]);
49: simple.setTextGenre(discList[numDiscs][2]);
50: simple.setTextLikeThisDisc(discList[numDiscs][3]);
51: discTable.appendChild(templateRow.cloneNode(true));
52: }
53:
54: discTable.removeChild(templateRow);
55:
56: comms.response.writeHTML(simple.toDocument());
57: }
58:
59: }
|