KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > enhydraManager > presentation > AppDetailPresentation


1 package enhydraManager.presentation;
2
3
4 import enhydraManager.spec.*;
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 AppDetailPresentation implements HttpPresentation {
17
18   private static AppDetailHTML appDetail;
19
20   public void run(HttpPresentationComms comms) throws HttpPresentationException, IOException JavaDoc {
21
22     try{
23         try {
24                 String JavaDoc colNum = comms.request.getParameter("colNum");
25                 OutputSortList(comms);
26         } catch (Exception JavaDoc e) {
27                 OutputList(comms);
28         }
29     }catch(Exception JavaDoc e){
30         e.printStackTrace();
31     }
32   }
33   
34   private static void setOutput(Vector JavaDoc [] sessionList, String JavaDoc service, String JavaDoc host, String JavaDoc id){
35         
36     Vector JavaDoc sessionIDValues = sessionList[0];
37     Vector JavaDoc esuValues = sessionList[1];
38     Vector JavaDoc sdValues = sessionList[2];
39     Vector JavaDoc ctValues = sessionList[3];
40     Vector JavaDoc latValues = sessionList[4];
41     
42     String JavaDoc sessionID = null;
43     String JavaDoc esu = null;
44     String JavaDoc sd = null;
45     String JavaDoc ct = null;
46     String JavaDoc lat = null;
47     
48     Node JavaDoc sessionElementRow = appDetail.getElementSessions_row();
49     Node JavaDoc no_entries_row = appDetail.getElementNo_entries_row();
50     Node JavaDoc sessions_row = appDetail.getElementSessions_row();
51     
52     appDetail.setTextAppName(id.substring(1) + " Session List");
53     
54     HTMLAnchorElement anchorhead_id = appDetail.getElementHead_id();
55     anchorhead_id.setHref("AppDetailPresentation.po?service=" + service + "&host=" + host + "&id=" + id + "&colNum=0");
56     anchorhead_id.setTitle("Sort session list by Session ID value!");
57     appDetail.setTextHead_id("Session ID");
58     
59     HTMLAnchorElement anchorhead_esu = appDetail.getElementHead_esu();
60     anchorhead_esu.setHref("AppDetailPresentation.po?service=" + service + "&host=" + host + "&id=" + id + "&colNum=1");
61     anchorhead_esu.setTitle("Sort session list by Enhydra Session User value!");
62     appDetail.setTextHead_esu("Enhydra Session User");
63     
64     HTMLAnchorElement anchorhead_sd = appDetail.getElementHead_sd();
65     anchorhead_sd.setHref("AppDetailPresentation.po?service=" + service + "&host=" + host + "&id=" + id + "&colNum=2");
66     anchorhead_sd.setTitle("Sort session list by Session Data value!");
67     appDetail.setTextHead_sd("Session Data");
68     
69     HTMLAnchorElement anchorhead_ct = appDetail.getElementHead_ct();
70     anchorhead_ct.setHref("AppDetailPresentation.po?service=" + service + "&host=" + host + "&id=" + id + "&colNum=3");
71     anchorhead_ct.setTitle("Sort session list by Session Creation Time value!");
72     appDetail.setTextHead_ct("Session Creation Time");
73     
74     HTMLAnchorElement anchorhead_lat = appDetail.getElementHead_lat();
75     anchorhead_lat.setHref("AppDetailPresentation.po?service=" + service + "&host=" + host + "&id=" + id + "&colNum=4");
76     anchorhead_lat.setTitle("Sort session list by Session Last Accessed Time value!");
77     appDetail.setTextHead_lat("Session Last Accessed Time");
78                 
79     if (sessionIDValues.size() == 0) {
80
81       sessions_row.getParentNode().removeChild(sessions_row);
82
83     }else {
84         no_entries_row.getParentNode().removeChild(no_entries_row);
85         for (int i=0; i<sessionIDValues.size(); i++) {
86             
87             sessionID = (String JavaDoc) sessionIDValues.elementAt(i);
88             try {
89                 appDetail.setTextSession_id(sessionID);
90             } catch (IllegalArgumentException JavaDoc ex){
91                 appDetail.setTextSession_id("Couldn't get SessionID!");
92             }
93             
94             esu = (String JavaDoc) esuValues.elementAt(i);
95             try {
96                 appDetail.setTextSession_esu(esu);
97             } catch (IllegalArgumentException JavaDoc ex){
98                 appDetail.setTextSession_esu("Couldn't get Enhydra Session User!");
99             }
100             
101             sd = (String JavaDoc) sdValues.elementAt(i);
102             try {
103                 appDetail.setTextSession_sd(sd);
104             } catch (IllegalArgumentException JavaDoc ex){
105                 appDetail.setTextSession_sd("Couldn't get SessionData!");
106             }
107             
108             ct = (String JavaDoc) ctValues.elementAt(i);
109             try {
110                 appDetail.setTextSession_ct(ct);
111             } catch (IllegalArgumentException JavaDoc ex){
112                 appDetail.setTextSession_ct("Couldn't get session creation time!");
113             }
114             
115             lat = (String JavaDoc) latValues.elementAt(i);
116             try {
117                 appDetail.setTextSession_lat(lat);
118             } catch (IllegalArgumentException JavaDoc ex){
119                 appDetail.setTextSession_lat("Couldn't get session last access time!");
120             }
121             
122             sessionElementRow.getParentNode().insertBefore(sessionElementRow.cloneNode(true),
123                                                                    sessionElementRow);
124             
125         }
126         sessionElementRow.getParentNode().removeChild(sessionElementRow);
127     }
128   }
129
130   public static void OutputList(HttpPresentationComms comms) throws Exception JavaDoc {
131     
132     String JavaDoc id = null;
133     String JavaDoc host=null;
134     String JavaDoc service=null;
135     try {
136           service=comms.request.getParameter("service");
137         host=comms.request.getParameter("host");
138         id = comms.request.getParameter("id");
139     } catch (Exception JavaDoc e) {}
140        
141        
142   
143        AppDetailSessionList appDetailSessionList=AppDetailSessionListFactory.getAppDetailSessionList("enhydraManager.business.AppDetailSessionListImpl");
144      Vector JavaDoc[] sessionList=appDetailSessionList.getList(service,host,id);
145  
146     
147     
148     appDetail = (AppDetailHTML)comms.xmlcFactory.create(AppDetailHTML.class);
149     
150     setOutput(sessionList,service,host,id);
151     
152     comms.response.writeDOM(appDetail);
153   }
154   
155   public static void sort (Vector JavaDoc[] params, int col){
156         String JavaDoc temp= null;
157         for (int i =0; i< params[col].size()-1; i++){
158                 for (int j =i+1; j< params[col].size(); j++){
159                         if ((((String JavaDoc)params[col].elementAt(i)).compareTo((String JavaDoc)params[col].elementAt(j)))>0){
160                                 for (int k=0;k<params.length;k++){
161                                         temp=(String JavaDoc)params[k].elementAt(i);
162                                         params[k].setElementAt(params[k].elementAt(j),i);
163                                         params[k].setElementAt(temp,j);
164                                 }
165                         }
166                 }
167         }
168               
169   }
170   
171   public static void OutputSortList(HttpPresentationComms comms) throws Exception JavaDoc {
172     String JavaDoc id = null;
173     String JavaDoc colNum = null;
174     String JavaDoc host = null;
175     String JavaDoc service = null;
176     try {
177           service = comms.request.getParameter("service");
178         host = comms.request.getParameter("host");
179         id = comms.request.getParameter("id");
180         colNum = comms.request.getParameter("colNum");
181     } catch (Exception JavaDoc e) {}
182        
183        
184   
185     AppDetailSessionList appDetailSessionList=AppDetailSessionListFactory.getAppDetailSessionList("enhydraManager.business.AppDetailSessionListImpl");
186     Vector JavaDoc[] sessionList=appDetailSessionList.getList(service,host,id);
187  
188     
189     sort(sessionList,Integer.parseInt(colNum));
190     
191     appDetail = (AppDetailHTML)comms.xmlcFactory.create(AppDetailHTML.class);
192     
193     setOutput(sessionList,service,host,id);
194     
195     comms.response.writeDOM(appDetail);
196   }
197 }
198
199
Popular Tags