KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > multibase > presentation > MultibasePresentation


1 /*
2  * multibaseExemple
3  *
4  * Enhydra super-servlet presentation object
5  *
6  */

7
8 package multibase.presentation;
9
10 // Enhydra SuperServlet imports
11
import com.lutris.appserver.server.httpPresentation.HttpPresentation;
12 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
13 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
14 import org.w3c.dom.html.*;
15 import org.w3c.dom.Node JavaDoc;
16
17 // Standard imports
18
import java.io.IOException JavaDoc;
19 import java.util.Date JavaDoc;
20 import java.text.DateFormat JavaDoc;
21
22 // App imports
23
import multibase.spec.*;
24 import org.w3c.dom.Node JavaDoc;
25
26 public class MultibasePresentation implements HttpPresentation {
27
28
29     public void run(HttpPresentationComms comms)
30         throws HttpPresentationException, IOException JavaDoc {
31
32         MultibaseHTML multibase;
33         MyDataManager dataManager;
34
35         
36         multibase = (MultibaseHTML)comms.xmlcFactory.create(MultibaseHTML.class);
37       
38         dataManager = MyDataManagerFactory.getMyDataManager("multibase.business.MyDataManagerImpl");
39          
40     
41     try{
42         String JavaDoc event = comms.request.getParameter("AppActionRg");
43         if (event!=null){
44             if (event.equals("loadPr")) {
45                 dataManager.loadPr();
46             
47             } else if (event.equals("loadEm")){
48                 dataManager.loadEm();
49                 
50             } else if (event.equals("transferPr")){
51                 dataManager.transferPr();
52                 
53             } else if (event.equals("deleteTr")){
54                 dataManager.deleteTr();
55                 
56             } else if (event.equals("deleteAll")){
57                 dataManager.deleteAll();
58             }
59         }
60
61         String JavaDoc[][] programerArray=dataManager.getProgramers();
62         String JavaDoc[][] employeeArray=dataManager.getEmployees();
63         
64         
65         HTMLTableRowElement prTemplateRow = multibase.getElementPrTemplateRow();
66         HTMLElement pFirstNameCellTemplate = multibase.getElementPFirstName();
67         HTMLElement pLastNameCellTemplate = multibase.getElementPLastName();
68         HTMLElement expirienceCellTemplate = multibase.getElementExpirience();
69         HTMLElement projectCellTemplate = multibase.getElementProject();
70         Node JavaDoc prTable = prTemplateRow.getParentNode();
71         
72         
73         
74         prTemplateRow .removeAttribute("id");
75         pFirstNameCellTemplate.removeAttribute("id");
76         pLastNameCellTemplate.removeAttribute("id");
77         expirienceCellTemplate.removeAttribute("id");
78         projectCellTemplate.removeAttribute("id");
79         
80         
81         
82         if (programerArray!=null){
83             for (int numDiscs = 0; numDiscs < programerArray.length; numDiscs++) {
84                 multibase.setTextPFirstName(programerArray[numDiscs][0]);
85                 multibase.setTextPLastName (programerArray[numDiscs][1]);
86                 multibase.setTextExpirience (programerArray[numDiscs][2]);
87                 multibase.setTextProject (programerArray[numDiscs][3]);
88                 prTable.appendChild(prTemplateRow.cloneNode(true));
89             }
90         }
91         
92         
93         
94         HTMLTableRowElement emTemplateRow = multibase.getElementEmTemplateRow();
95         HTMLElement eFirstNameCellTemplate = multibase.getElementEFirstName();
96         HTMLElement eLastNameCellTemplate = multibase.getElementELastName();
97         HTMLElement occupationCellTemplate = multibase.getElementOccupation();
98         HTMLElement departmentCellTemplate = multibase.getElementDepartment();
99         Node JavaDoc emTable = emTemplateRow.getParentNode();
100         
101         
102         
103         emTemplateRow .removeAttribute("id");
104         eFirstNameCellTemplate.removeAttribute("id");
105         eLastNameCellTemplate.removeAttribute("id");
106         occupationCellTemplate.removeAttribute("id");
107         departmentCellTemplate.removeAttribute("id");
108         
109         
110         
111         if (employeeArray!=null){
112             for (int numDiscs = 0; numDiscs < employeeArray.length; numDiscs++) {
113                 multibase.setTextEFirstName(employeeArray[numDiscs][0]);
114                 multibase.setTextELastName (employeeArray[numDiscs][1]);
115                 multibase.setTextOccupation(employeeArray[numDiscs][2]);
116                 multibase.setTextDepartment(employeeArray[numDiscs][3]);
117                 emTable.appendChild(emTemplateRow.cloneNode(true));
118             }
119         }
120         
121         
122         prTemplateRow.getParentNode().removeChild(prTemplateRow);
123         emTemplateRow.getParentNode().removeChild(emTemplateRow);
124     
125     /*
126  * We want to allow multibase_pres to be functional , we cannot create instances of business layer when we run bultibase_pres
127  * catch NullPointerException and show default HTML page
128  */

129      }catch(NullPointerException JavaDoc e){
130         multibase.setTextMessage("MultiDb default page");
131         }
132         comms.response.writeDOM(multibase);
133     }
134
135 }
136
Popular Tags