KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > snapper > presentation > StatusPresentation


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

7
8 package org.enhydra.snapper.presentation;
9
10
11 import java.util.HashMap JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.Map JavaDoc;
14
15 import org.w3c.dom.html.*;
16 import org.w3c.dom.*;
17
18 // Enhydra SuperServlet specification imports
19
import org.enhydra.snapper.SnapperManager;
20 import org.enhydra.snapper.spec.*;
21
22 import org.enhydra.snapper.presentation.html.*;
23 import org.enhydra.xml.xmlc.XMLObject;
24
25
26 public class StatusPresentation extends BasePO {
27
28
29     protected XMLObject getDOM() throws Exception JavaDoc {
30
31         StatusListHTML status;
32         Site site = null;
33         String JavaDoc id;
34
35         status = (StatusListHTML)comms.xmlcFactory.create(StatusListHTML.class);
36         id = comms.request.getParameter("id");
37         
38         if (id != null) {
39             Map JavaDoc threads = SnapperManager.getInstance().getThreads();
40             if (threads.get(id) instanceof Update) {
41                 Update ii = (Update)threads.get(id);
42                 ii.setDoStop(true);
43             }
44             else {
45                 Index ii = (Index)threads.get(id);
46                 ii.setDoStop(true);
47             }
48             
49             SnapperManager.getInstance().removeThread(id);
50         }
51         
52         HTMLTableRowElement templateRow = status.getElementTemplateRow();
53         HTMLElement nameCellTemplate = status.getElementName();
54
55         templateRow.removeAttribute("id");
56         nameCellTemplate.removeAttribute("id");
57         
58         Node sitesTable = templateRow.getParentNode();
59         String JavaDoc link;
60         Map JavaDoc threads = new HashMap JavaDoc();
61         threads = SnapperManager.getInstance().getThreads();
62         
63         for (Iterator JavaDoc iterator = threads.entrySet().iterator(); iterator.hasNext();) {
64             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iterator.next();
65             String JavaDoc key = (String JavaDoc)entry.getKey();
66             try{
67                 try {
68                     Site si = SiteFactory.getSite("org.enhydra.snapper.business.SiteImpl");
69                     
70                     site = si.findSiteByID(key, dbTransaction);
71                     
72                 }catch (Exception JavaDoc ex){
73                     System.out.println("Exception: "+ex);
74                     site = null;
75                 }
76             // set text of new cells to values from string array
77
status.setTextName(site.getName());
78
79             link = "StatusPresentation.po?id=" + site.getID();
80             status.getElementDeleteLink().setHref(link);
81             
82             sitesTable.appendChild(templateRow.cloneNode(true));
83             }
84    
85         catch (Exception JavaDoc ex) {ex.printStackTrace();}
86         }
87         templateRow.getParentNode().removeChild(templateRow);
88         //siteList.setTextTime(now);
89
return status;
90     }
91
92 }
93
Popular Tags