KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > simpleapp > presentation > SimplePresentation


1 /*
2     This file is part of the Tutorial chapter of "Getting Started with Enhydra".
3     It is not meant to be used in any other context.
4 */

5
6 package simpleapp.presentation;
7
8 import java.util.Date JavaDoc;
9 //import com.lutris.xml.xmlc.*;
10
import org.enhydra.xml.xmlc.*;
11 import com.lutris.appserver.server.httpPresentation.*;
12 import org.w3c.dom.html.*;
13 import org.w3c.dom.*;
14
15 import simpleapp.spec.SimpleListOfDiscsFactory;
16 import simpleapp.spec.SimpleListOfDiscs;
17
18
19 public class SimplePresentation implements HttpPresentation {
20
21 /*
22 String[][] discList =
23     { { "Felonious Monk Fish", "Deep Sea Blues", "Jazz", "Yes" },
24      { "Funky Urchin", "Lovely Spines", "Techno Pop", "Yes" },
25      { "Stinky Pups", "Shark Attack", "Hardcore", "No" } };
26 */

27    
28            
29    
30
31
32     public void run(HttpPresentationComms comms)
33         throws HttpPresentationException {
34
35         String JavaDoc[][] discList;
36         try {
37           SimpleListOfDiscs sdl = SimpleListOfDiscsFactory.createSimpleListOfDiscs("simpleapp.business.SimpleListOfDiscsImpl");
38           discList = sdl.getDiscList();
39         } catch (Exception JavaDoc ex){
40                System.out.println("Exception: "+ex);
41              
42               discList = new String JavaDoc[1][4];
43               discList[0][0] = "SORRY, ";
44               discList[0][1] = "NO ";
45               discList[0][2] = "DISCS ";
46               discList[0][3] = "AVAILABLE!";
47               
48          }
49         
50         String JavaDoc now = new Date JavaDoc().toString();
51         // SimpleHTML simple = new SimpleHTML();
52
SimpleHTML simple =(SimpleHTML)comms.xmlcFactory.create(SimpleHTML.class);
53
54         simple.setTextTime(now);
55
56         HTMLTableRowElement templateRow = simple.getElementTemplateRow();
57         HTMLElement artistCellTemplate = simple.getElementArtist();
58         HTMLElement titleCellTemplate = simple.getElementTitle();
59         HTMLElement genreCellTemplate = simple.getElementGenre();
60         HTMLElement likeThisDisc = simple.getElementLikeThisDisc();
61
62         templateRow.removeAttribute("id");
63         artistCellTemplate.removeAttribute("id");
64         titleCellTemplate.removeAttribute("id");
65         genreCellTemplate.removeAttribute("id");
66         likeThisDisc.removeAttribute("id");
67
68         Node discTable = templateRow.getParentNode();
69
70         for(int numDiscs = 0; numDiscs < discList.length; numDiscs++) {
71             simple.setTextArtist(discList[numDiscs][0]);
72             simple.setTextTitle(discList[numDiscs][1]);
73             simple.setTextGenre(discList[numDiscs][2]);
74             simple.setTextLikeThisDisc(discList[numDiscs][3]);
75             discTable.appendChild(templateRow.cloneNode(true));
76         }
77
78         discTable.removeChild(templateRow);
79
80         comms.response.writeHTML(simple.toDocument());
81     }
82
83 }
Popular Tags