KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tableappclient > presentation > WelcomePresentation


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

9
10 package tableappclient.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
17 import org.w3c.dom.Node JavaDoc;
18 import org.w3c.dom.Element JavaDoc;
19 import org.w3c.dom.html.HTMLTableElement;
20 import org.w3c.dom.html.HTMLTableRowElement;
21 import org.w3c.dom.html.HTMLElement;
22
23 // Enhydra SuperServlet specification imports
24
import tableappclient.spec.*;
25
26 // Standard imports
27
import java.io.IOException JavaDoc;
28
29 public class WelcomePresentation
30     implements HttpPresentation {
31   static final String JavaDoc FOUND = "The following table has been retrieved from the TableApp application and transferred in a Document object, via Axis/Soap:";
32   static final String JavaDoc NOTFOUND = "The server application TableApp has not been accessed yet. Access and refresh it few times, then refresh this window.";
33   static final String JavaDoc FOUNDOBJ = "The following data have been retrieved from the TableApp application and transferred in a custom serialized object, via Axis/Soap:";
34   static final String JavaDoc NOTFOUNDOBJ = "The following data will be retrieved from the TableApp application and transferred in a custom serialized object, via Axis/Soap:";
35   public void run(HttpPresentationComms comms) throws HttpPresentationException,
36       IOException JavaDoc {
37     String JavaDoc server = null;
38     try {
39       server = comms.request.getServerName();
40     } catch (Exception JavaDoc e) {}
41         String JavaDoc port = null;
42     try {
43       port = new Integer JavaDoc(comms.request.getServerPort()).toString();
44     } catch (Exception JavaDoc e) {}
45         
46     String JavaDoc text = "1";
47     String JavaDoc textObj = "2";
48     WelcomeHTML welcome = (WelcomeHTML) comms.xmlcFactory.create(WelcomeHTML.class);
49     try {
50       TableNode tableNode = TableNodeFactory.createTableNode(
51           "tableappclient.business.TableNodeImpl");
52       AccessData accessData = AccessDataFactory.createAccessData(
53           "tableappclient.business.AccessDataImpl",server,port);
54       Node JavaDoc node = tableNode.getTableNode(server,port);
55       if (node == null) {
56         text = NOTFOUND;
57         textObj = NOTFOUNDOBJ;
58       }
59       else {
60         text = FOUND;
61         textObj = FOUNDOBJ;
62         HTMLTableElement welcomeTable = welcome.getElementTemplateTable();
63         Node JavaDoc welcomeNode = welcome.importNode(node, true);
64         Node JavaDoc parentNode = welcomeTable.getParentNode();
65         parentNode.appendChild(welcomeNode);
66         HTMLTableRowElement templateRow = welcome.getElementTemplateRow();
67         HTMLElement noAccessesElement = welcome.getElementAccNum();
68         HTMLElement timeElement = welcome.getElementAccTime();
69         templateRow.removeAttribute("id");
70         noAccessesElement.removeAttribute("id");
71         timeElement.removeAttribute("id");
72         Node JavaDoc parrent = templateRow.getParentNode();
73         welcome.setTextAccNum(new Integer JavaDoc(accessData.getNoAccesses()).toString());
74         welcome.setTextAccTime(accessData.getAccessTime());
75         parrent.appendChild(templateRow.cloneNode(true));
76         parrent.removeChild(templateRow);
77       }
78     }
79     catch (Exception JavaDoc ex) {
80       System.out.println("Exception: " + ex);
81       text = "Could not get business object!!!";
82     }
83     welcome.setTextObjectTextTemplate(textObj);
84     welcome.setTextTextTemplate(text);
85     comms.response.writeDOM(welcome);
86   }
87 }
Popular Tags