001: /*
002: * multibaseExemple
003: *
004: * Enhydra super-servlet presentation object
005: *
006: */
007:
008: package multibase.presentation;
009:
010: // Enhydra SuperServlet imports
011: import com.lutris.appserver.server.httpPresentation.HttpPresentation;
012: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
013: import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
014: import org.w3c.dom.html.*;
015: import org.w3c.dom.Node;
016:
017: // Standard imports
018: import java.io.IOException;
019: import java.util.Date;
020: import java.text.DateFormat;
021:
022: // App imports
023: import multibase.spec.*;
024: import org.w3c.dom.Node;
025:
026: public class MultibasePresentation implements HttpPresentation {
027:
028: public void run(HttpPresentationComms comms)
029: throws HttpPresentationException, IOException {
030:
031: MultibaseHTML multibase;
032: MyDataManager dataManager;
033:
034: multibase = (MultibaseHTML) comms.xmlcFactory
035: .create(MultibaseHTML.class);
036:
037: dataManager = MyDataManagerFactory
038: .getMyDataManager("multibase.business.MyDataManagerImpl");
039:
040: try {
041: String event = comms.request.getParameter("AppActionRg");
042: if (event != null) {
043: if (event.equals("loadPr")) {
044: dataManager.loadPr();
045:
046: } else if (event.equals("loadEm")) {
047: dataManager.loadEm();
048:
049: } else if (event.equals("transferPr")) {
050: dataManager.transferPr();
051:
052: } else if (event.equals("deleteTr")) {
053: dataManager.deleteTr();
054:
055: } else if (event.equals("deleteAll")) {
056: dataManager.deleteAll();
057: }
058: }
059:
060: String[][] programerArray = dataManager.getProgramers();
061: String[][] employeeArray = dataManager.getEmployees();
062:
063: HTMLTableRowElement prTemplateRow = multibase
064: .getElementPrTemplateRow();
065: HTMLElement pFirstNameCellTemplate = multibase
066: .getElementPFirstName();
067: HTMLElement pLastNameCellTemplate = multibase
068: .getElementPLastName();
069: HTMLElement expirienceCellTemplate = multibase
070: .getElementExpirience();
071: HTMLElement projectCellTemplate = multibase
072: .getElementProject();
073: Node prTable = prTemplateRow.getParentNode();
074:
075: prTemplateRow.removeAttribute("id");
076: pFirstNameCellTemplate.removeAttribute("id");
077: pLastNameCellTemplate.removeAttribute("id");
078: expirienceCellTemplate.removeAttribute("id");
079: projectCellTemplate.removeAttribute("id");
080:
081: if (programerArray != null) {
082: for (int numDiscs = 0; numDiscs < programerArray.length; numDiscs++) {
083: multibase
084: .setTextPFirstName(programerArray[numDiscs][0]);
085: multibase
086: .setTextPLastName(programerArray[numDiscs][1]);
087: multibase
088: .setTextExpirience(programerArray[numDiscs][2]);
089: multibase
090: .setTextProject(programerArray[numDiscs][3]);
091: prTable.appendChild(prTemplateRow.cloneNode(true));
092: }
093: }
094:
095: HTMLTableRowElement emTemplateRow = multibase
096: .getElementEmTemplateRow();
097: HTMLElement eFirstNameCellTemplate = multibase
098: .getElementEFirstName();
099: HTMLElement eLastNameCellTemplate = multibase
100: .getElementELastName();
101: HTMLElement occupationCellTemplate = multibase
102: .getElementOccupation();
103: HTMLElement departmentCellTemplate = multibase
104: .getElementDepartment();
105: Node emTable = emTemplateRow.getParentNode();
106:
107: emTemplateRow.removeAttribute("id");
108: eFirstNameCellTemplate.removeAttribute("id");
109: eLastNameCellTemplate.removeAttribute("id");
110: occupationCellTemplate.removeAttribute("id");
111: departmentCellTemplate.removeAttribute("id");
112:
113: if (employeeArray != null) {
114: for (int numDiscs = 0; numDiscs < employeeArray.length; numDiscs++) {
115: multibase
116: .setTextEFirstName(employeeArray[numDiscs][0]);
117: multibase
118: .setTextELastName(employeeArray[numDiscs][1]);
119: multibase
120: .setTextOccupation(employeeArray[numDiscs][2]);
121: multibase
122: .setTextDepartment(employeeArray[numDiscs][3]);
123: emTable.appendChild(emTemplateRow.cloneNode(true));
124: }
125: }
126:
127: prTemplateRow.getParentNode().removeChild(prTemplateRow);
128: emTemplateRow.getParentNode().removeChild(emTemplateRow);
129:
130: /*
131: * We want to allow multibase_pres to be functional , we cannot create instances of business layer when we run bultibase_pres
132: * catch NullPointerException and show default HTML page
133: */
134: } catch (NullPointerException e) {
135: multibase.setTextMessage("MultiDb default page");
136: }
137: comms.response.writeDOM(multibase);
138: }
139:
140: }
|