1 package phoneList.presentation; 2 3 import phoneList.spec.*; 4 5 import java.util.Vector ; 7 import java.io.IOException ; 8 9 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 ; 15 16 public class ListPresentation implements HttpPresentation { 17 18 private static ListHTML list; 19 20 public void run(HttpPresentationComms comms) throws HttpPresentationException, IOException { 21 22 try{ 23 OutputList(comms); 24 }catch(Exception e){ 25 e.printStackTrace(); 26 } 27 } 28 29 30 public static void OutputList(HttpPresentationComms comms) throws Exception { 31 32 33 try{ 34 list = (ListHTML)comms.xmlcFactory.create(ListHTML.class); 35 36 PhoneList phoneList = PhoneListFactory.getPhoneList("phoneList.business.PhoneListImpl"); 37 38 String server = phoneList.getServer(); 39 String 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 [] lists = phoneList.getLists(); 52 Vector firsts = lists[0]; 53 Vector lasts = lists[1]; 54 Vector phones = lists[2]; 55 Vector ids = lists[3]; 56 57 58 59 Node phoneElementRow = list.getElementPhone_row(); 60 Node no_entries_row = list.getElementNo_entries_row(); 61 Node phone_row = list.getElementPhone_row(); 62 63 Node server_name_row = list.getElementServer_name_row(); 64 Node 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 first = (String ) firsts.elementAt(i); 75 String last = (String ) lasts.elementAt(i); 76 String phone = (String ) phones.elementAt(i); 77 String id = (String ) 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 100 101 102 }catch(NullPointerException e){ 103 } 104 105 106 comms.response.writeDOM(list); 107 } 108 } 109 110 | Popular Tags |