KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sessionViewer > presentation > AppDetailPresentation


1 package sessionViewer.presentation;
2
3
4 import sessionViewer.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 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?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?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?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?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?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     
134     try {
135         id = comms.request.getParameter("id");
136     } catch (Exception JavaDoc e) {}
137        
138        
139   
140        AppDetailSessionList appDetailSessionList=AppDetailSessionListFactory.getAppDetailSessionList("sessionViewer.business.AppDetailSessionListImpl");
141      Vector JavaDoc[] sessionList=appDetailSessionList.getList(id);
142  
143     
144     
145     appDetail = (AppDetailHTML)comms.xmlcFactory.create(AppDetailHTML.class);
146     
147     setOutput(sessionList,id);
148     
149     comms.response.writeDOM(appDetail);
150   }
151   
152   public static void sort (Vector JavaDoc[] params, int col){
153         String JavaDoc temp= null;
154         for (int i =0; i< params[col].size()-1; i++){
155                 for (int j =i+1; j< params[col].size(); j++){
156                         if ((((String JavaDoc)params[col].elementAt(i)).compareTo((String JavaDoc)params[col].elementAt(j)))>0){
157                                 for (int k=0;k<params.length;k++){
158                                         temp=(String JavaDoc)params[k].elementAt(i);
159                                         params[k].setElementAt(params[k].elementAt(j),i);
160                                         params[k].setElementAt(temp,j);
161                                 }
162                         }
163                 }
164         }
165               
166   }
167   
168   public static void OutputSortList(HttpPresentationComms comms) throws Exception JavaDoc {
169     String JavaDoc id = null;
170     String JavaDoc colNum = null;
171     
172     try {
173         id = comms.request.getParameter("id");
174         colNum = comms.request.getParameter("colNum");
175     } catch (Exception JavaDoc e) {}
176        
177        
178   
179       AppDetailSessionList appDetailSessionList=AppDetailSessionListFactory.getAppDetailSessionList("sessionViewer.business.AppDetailSessionListImpl");
180      Vector JavaDoc[] sessionList=appDetailSessionList.getList(id);
181  
182     
183     sort(sessionList,Integer.parseInt(colNum));
184     
185     appDetail = (AppDetailHTML)comms.xmlcFactory.create(AppDetailHTML.class);
186     
187     setOutput(sessionList,id);
188     
189     comms.response.writeDOM(appDetail);
190   }
191 }
192
193
Popular Tags