001: package phoneList.presentation;
002:
003: import phoneList.spec.*;
004:
005: // Standard imports
006: import java.util.Vector;
007: import java.io.IOException;
008:
009: // Enhydra SuperServlet imports
010: import com.lutris.appserver.server.httpPresentation.HttpPresentation;
011: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
012: import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
013: import org.w3c.dom.html.HTMLAnchorElement;
014: import org.w3c.dom.Node;
015:
016: public class ListPresentation implements HttpPresentation {
017:
018: private static ListHTML list;
019:
020: public void run(HttpPresentationComms comms)
021: throws HttpPresentationException, IOException {
022:
023: try {
024: OutputList(comms);
025: } catch (Exception e) {
026: e.printStackTrace();
027: }
028: }
029:
030: public static void OutputList(HttpPresentationComms comms)
031: throws Exception {
032:
033: try {
034: list = (ListHTML) comms.xmlcFactory.create(ListHTML.class);
035:
036: PhoneList phoneList = PhoneListFactory
037: .getPhoneList("phoneList.business.PhoneListImpl");
038:
039: String server = phoneList.getServer();
040: String port = phoneList.getPort();
041:
042: if (!phoneList.isConfigured()) {
043: int p = comms.request.getServerPort();
044: port = Integer.toString(p);
045:
046: server = comms.request.getServerName();
047:
048: phoneList.setServerUrl(server, port);
049: phoneList.setConfigured();
050: }
051:
052: Vector[] lists = phoneList.getLists();
053: Vector firsts = lists[0];
054: Vector lasts = lists[1];
055: Vector phones = lists[2];
056: Vector ids = lists[3];
057:
058: Node phoneElementRow = list.getElementPhone_row();
059: Node no_entries_row = list.getElementNo_entries_row();
060: Node phone_row = list.getElementPhone_row();
061:
062: Node server_name_row = list.getElementServer_name_row();
063: Node server_port_row = list.getElementServer_port_row();
064:
065: if (firsts.size() == 0) {
066:
067: phone_row.getParentNode().removeChild(phone_row);
068:
069: } else {
070: no_entries_row.getParentNode().removeChild(
071: no_entries_row);
072: for (int i = 0; i < firsts.size(); i++) {
073:
074: String first = (String) firsts.elementAt(i);
075: String last = (String) lasts.elementAt(i);
076: String phone = (String) phones.elementAt(i);
077: String id = (String) ids.elementAt(i);
078:
079: list.setTextFirst(first);
080: list.setTextLast(last);
081: list.setTextPhone(phone);
082: HTMLAnchorElement anchorDelete = list
083: .getElementDelete();
084: anchorDelete
085: .setHref("DoActionPresentation.po?action=delete&id="
086: + id);
087: HTMLAnchorElement anchorEdit = list
088: .getElementEdit();
089: anchorEdit.setHref("EditPresentation.po?id=" + id);
090:
091: phoneElementRow.getParentNode().insertBefore(
092: phoneElementRow.cloneNode(true),
093: phoneElementRow);
094:
095: }
096:
097: phoneElementRow.getParentNode().removeChild(
098: phoneElementRow);
099: }
100: list.setTextServer(server);
101: list.setTextPort(port);
102: /*
103: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run phoneBookClient_pres )
104: * We need to allow phoneBookClient_pres to be functional , respone will be default HTML page
105: */
106:
107: } catch (NullPointerException e) {
108: }
109:
110: comms.response.writeDOM(list);
111: }
112: }
|