KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > phoneList > presentation > ListPresentation


1 package phoneList.presentation;
2
3 import phoneList.spec.*;
4
5 // Standard imports
6
import java.util.Vector JavaDoc;
7 import java.io.IOException JavaDoc;
8
9 // Enhydra SuperServlet imports
10
import com.lutris.appserver.server.httpPresentation.HttpPresentation;
11 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
12 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
13 import org.w3c.dom.html.HTMLAnchorElement;
14 import org.w3c.dom.Node JavaDoc;
15
16 public class ListPresentation implements HttpPresentation {
17
18   private static ListHTML list;
19
20   public void run(HttpPresentationComms comms) throws HttpPresentationException, IOException JavaDoc {
21
22     try{
23       OutputList(comms);
24     }catch(Exception JavaDoc e){
25       e.printStackTrace();
26     }
27   }
28
29
30   public static void OutputList(HttpPresentationComms comms) throws Exception JavaDoc {
31
32    
33  try{
34    list = (ListHTML)comms.xmlcFactory.create(ListHTML.class);
35   
36    PhoneList phoneList = PhoneListFactory.getPhoneList("phoneList.business.PhoneListImpl");
37
38     String JavaDoc server = phoneList.getServer();
39     String JavaDoc port = phoneList.getPort();
40
41     if (!phoneList.isConfigured()){
42       int p = comms.request.getServerPort();
43       port = Integer.toString(p);
44       
45       server = comms.request.getServerName();
46       
47       phoneList.setServerUrl(server, port);
48       phoneList.setConfigured();
49     }
50     
51     Vector JavaDoc[] lists = phoneList.getLists();
52     Vector JavaDoc firsts = lists[0];
53     Vector JavaDoc lasts = lists[1];
54     Vector JavaDoc phones = lists[2];
55     Vector JavaDoc ids = lists[3];
56     
57    
58   
59     Node JavaDoc phoneElementRow = list.getElementPhone_row();
60     Node JavaDoc no_entries_row = list.getElementNo_entries_row();
61     Node JavaDoc phone_row = list.getElementPhone_row();
62     
63     Node JavaDoc server_name_row = list.getElementServer_name_row();
64     Node JavaDoc server_port_row = list.getElementServer_port_row();
65
66     if (firsts.size() == 0) {
67
68       phone_row.getParentNode().removeChild(phone_row);
69
70     }else{
71       no_entries_row.getParentNode().removeChild(no_entries_row);
72       for (int i=0; i<firsts.size(); i++) {
73
74         String JavaDoc first = (String JavaDoc) firsts.elementAt(i);
75         String JavaDoc last = (String JavaDoc) lasts.elementAt(i);
76         String JavaDoc phone = (String JavaDoc) phones.elementAt(i);
77         String JavaDoc id = (String JavaDoc) ids.elementAt(i);
78
79         list.setTextFirst(first);
80         list.setTextLast(last);
81         list.setTextPhone(phone);
82         HTMLAnchorElement anchorDelete = list.getElementDelete();
83         anchorDelete.setHref("DoActionPresentation.po?action=delete&id="+id);
84         HTMLAnchorElement anchorEdit = list.getElementEdit();
85         anchorEdit.setHref("EditPresentation.po?id="+id);
86
87         phoneElementRow.getParentNode().insertBefore(phoneElementRow.cloneNode(true),
88                                                                phoneElementRow);
89
90       }
91       
92       phoneElementRow.getParentNode().removeChild(phoneElementRow);
93     }
94     list.setTextServer(server);
95     list.setTextPort(port);
96  /*
97  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run phoneBookClient_pres )
98  * We need to allow phoneBookClient_pres to be functional , respone will be default HTML page
99  */

100   
101    
102    }catch(NullPointerException JavaDoc e){
103    }
104    
105    
106     comms.response.writeDOM(list);
107    }
108 }
109
110
Popular Tags