KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tableapp > presentation > WelcomePresentation


1 /*
2  * tableApp
3  *
4  * Enhydra super-servlet presentation object
5  *
6  * Prozone
7  *
8  */

9
10 package tableapp.presentation;
11
12 // Enhydra SuperServlet imports
13
import com.lutris.appserver.server.httpPresentation.HttpPresentation;
14 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
15 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
16 import org.enhydra.xml.xmlc.*;
17 import com.lutris.appserver.server.httpPresentation.*;
18 import org.w3c.dom.html.*;
19 import org.w3c.dom.*;
20 import org.enhydra.apache.html.dom.HTMLDocumentImpl;
21 // Enhydra SuperServlet specification imports
22
import tableapp.spec.*;
23
24 // Standard imports
25
import java.io.IOException JavaDoc;
26
27 public class WelcomePresentation
28     implements HttpPresentation {
29   static TableHTML table = null;
30   static Access access = null;
31   WelcomeHTML welcome;
32   static Node accTable = null;
33   static int i = 0;
34   static HTMLTableRowElement templateRow;
35   Document doc;
36   public void run(HttpPresentationComms comms) throws HttpPresentationException,
37       IOException JavaDoc {
38
39     String JavaDoc now;
40     welcome = (WelcomeHTML) comms.xmlcFactory.create(WelcomeHTML.class);
41     if (access == null) {
42       access = (Access) AccessFactory.createAccess(
43           "tableapp.business.AccessImpl");
44     }
45     if (table == null) {
46       table = (TableHTML) comms.xmlcFactory.create(TableHTML.class);
47     }
48     try {
49       Dater dater = DaterFactory.createDater("tableapp.business.DaterImpl");
50       now = dater.getDate();
51     }
52     catch (Exception JavaDoc ex) {
53       now = "Could not get business object!!!";
54     }
55
56     welcome.setTextTime(now);
57     tableNode(now);
58     comms.response.writeDOM(welcome);
59
60   }
61
62   public Document tableDoc() {
63     if (accTable == null) {
64       return null;
65     }
66
67     Document doc = accTable.getOwnerDocument();
68
69     return (Document) accTable.getOwnerDocument();
70   }
71
72   private void tableNode(String JavaDoc now) {
73     if (templateRow == null) {
74       templateRow = table.getElementTemplateRow();
75     }
76     HTMLElement accNumCellTemplate = table.getElementAccNum();
77     HTMLElement accTimeCellTemplate = table.getElementAccTime();
78
79     templateRow.removeAttribute("id");
80     accNumCellTemplate.removeAttribute("id");
81     accTimeCellTemplate.removeAttribute("id");
82
83     i++;
84     access.setNoAccesses(i);
85     table.setTextAccNum(" " + i);
86     table.setTextAccTime(now);
87     if (accTable == null) {
88       accTable = templateRow.getParentNode();
89       accTable.appendChild(templateRow.cloneNode(true));
90       accTable.removeChild(templateRow);
91     }
92     else {
93       if (i % 10 == 0) {
94         Node header = accTable.getFirstChild();
95         Node subNode = null;
96         while ( (subNode = header.getNextSibling()) != null) {
97           accTable.removeChild(subNode);
98         }
99       }
100       accTable.appendChild(templateRow.cloneNode(true));
101     }
102
103     HTMLTableElement welcomeTable = welcome.getElementTemplateTable();
104     Node welcomeNode = welcome.adoptNode(accTable.cloneNode(true));
105     Node parentNode = welcomeTable.getParentNode();
106     parentNode.appendChild(welcomeNode);
107
108     return;
109   }
110
111   public WelcomeHTML returnWelcome() {
112     return welcome;
113   }
114   public Access returnAccess(){
115     return access;
116   }
117 }
Popular Tags