001: /*
002: * tableApp
003: *
004: * Enhydra super-servlet presentation object
005: *
006: * Prozone
007: *
008: */
009:
010: package tableapp.presentation;
011:
012: // Enhydra SuperServlet imports
013: import com.lutris.appserver.server.httpPresentation.HttpPresentation;
014: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
015: import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
016: import org.enhydra.xml.xmlc.*;
017: import com.lutris.appserver.server.httpPresentation.*;
018: import org.w3c.dom.html.*;
019: import org.w3c.dom.*; //import org.enhydra.apache.html.dom.HTMLDocumentImpl;
020: // Enhydra SuperServlet specification imports
021: import tableapp.spec.*;
022:
023: // Standard imports
024: import java.io.IOException;
025:
026: public class WelcomePresentation implements HttpPresentation {
027: static TableHTML table = null;
028: static Access access = null;
029: WelcomeHTML welcome;
030: static Node accTable = null;
031: static int i = 0;
032: static HTMLTableRowElement templateRow;
033: Document doc;
034:
035: public void run(HttpPresentationComms comms)
036: throws HttpPresentationException, IOException {
037:
038: String now;
039: welcome = (WelcomeHTML) comms.xmlcFactory
040: .create(WelcomeHTML.class);
041: if (access == null) {
042: access = (Access) AccessFactory
043: .createAccess("tableapp.business.AccessImpl");
044: }
045: if (table == null) {
046: table = (TableHTML) comms.xmlcFactory
047: .create(TableHTML.class);
048: }
049: try {
050: Dater dater = DaterFactory
051: .createDater("tableapp.business.DaterImpl");
052: now = dater.getDate();
053: } catch (Exception ex) {
054: now = "Could not get business object!!!";
055: }
056:
057: welcome.setTextTime(now);
058: tableNode(now);
059: comms.response.writeDOM(welcome);
060:
061: }
062:
063: public Document tableDoc() {
064: if (accTable == null) {
065: return null;
066: }
067:
068: Document doc = accTable.getOwnerDocument();
069:
070: return (Document) accTable.getOwnerDocument();
071: }
072:
073: private void tableNode(String now) {
074: if (templateRow == null) {
075: templateRow = table.getElementTemplateRow();
076: }
077: HTMLElement accNumCellTemplate = table.getElementAccNum();
078: HTMLElement accTimeCellTemplate = table.getElementAccTime();
079:
080: templateRow.removeAttribute("id");
081: accNumCellTemplate.removeAttribute("id");
082: accTimeCellTemplate.removeAttribute("id");
083:
084: i++;
085: access.setNoAccesses(i);
086: table.setTextAccNum(" " + i);
087: table.setTextAccTime(now);
088: if (accTable == null) {
089: accTable = templateRow.getParentNode();
090: accTable.appendChild(templateRow.cloneNode(true));
091: accTable.removeChild(templateRow);
092: } else {
093: if (i % 10 == 0) {
094: Node header = accTable.getFirstChild();
095: Node subNode = null;
096: while ((subNode = header.getNextSibling()) != null) {
097: accTable.removeChild(subNode);
098: }
099: }
100: accTable.appendChild(templateRow.cloneNode(true));
101: }
102:
103: HTMLTableElement welcomeTable = welcome
104: .getElementTemplateTable();
105: Node welcomeNode = welcome.adoptNode(accTable.cloneNode(true));
106: Node parentNode = welcomeTable.getParentNode();
107: parentNode.appendChild(welcomeNode);
108:
109: return;
110: }
111:
112: public WelcomeHTML returnWelcome() {
113: return welcome;
114: }
115:
116: public Access returnAccess() {
117: return access;
118: }
119: }
|