1 9 10 package tableappclient.presentation; 11 12 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 ; 18 import org.w3c.dom.Element ; 19 import org.w3c.dom.html.HTMLTableElement; 20 import org.w3c.dom.html.HTMLTableRowElement; 21 import org.w3c.dom.html.HTMLElement; 22 23 import tableappclient.spec.*; 25 26 import java.io.IOException ; 28 29 public class WelcomePresentation 30 implements HttpPresentation { 31 static final String FOUND = "The following table has been retrieved from the TableApp application and transferred in a Document object, via Axis/Soap:"; 32 static final String NOTFOUND = "The server application TableApp has not been accessed yet. Access and refresh it few times, then refresh this window."; 33 static final String 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 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 { 37 String server = null; 38 try { 39 server = comms.request.getServerName(); 40 } catch (Exception e) {} 41 String port = null; 42 try { 43 port = new Integer (comms.request.getServerPort()).toString(); 44 } catch (Exception e) {} 45 46 String text = "1"; 47 String 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 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 welcomeNode = welcome.importNode(node, true); 64 Node 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 parrent = templateRow.getParentNode(); 73 welcome.setTextAccNum(new Integer (accessData.getNoAccesses()).toString()); 74 welcome.setTextAccTime(accessData.getAccessTime()); 75 parrent.appendChild(templateRow.cloneNode(true)); 76 parrent.removeChild(templateRow); 77 } 78 } 79 catch (Exception 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 |