KickJava   Java API By Example, From Geeks To Geeks.

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


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

7
8 package org.enhydra.snapper.presentation;
9
10 import java.text.DecimalFormat JavaDoc;
11
12 import org.w3c.dom.html.*;
13 import org.w3c.dom.*;
14
15 // Enhydra SuperServlet specification imports
16
import org.enhydra.snapper.spec.*;
17
18 import org.enhydra.snapper.presentation.html.*;
19 import org.enhydra.xml.xmlc.XMLObject;
20
21 public class IndexedSitesPresentation extends BasePO {
22
23     protected XMLObject getDOM() throws Exception JavaDoc {
24
25         IndexedSitesHistoryHTML htmlPage;
26         Indexed[] indexedArray = null;
27         Site[] list = null;
28         Indexed in;
29
30         htmlPage = (IndexedSitesHistoryHTML) comms.xmlcFactory
31                 .create(IndexedSitesHistoryHTML.class);
32
33         // Indexed table
34

35         try {
36             in = IndexedFactory
37                     .getIndexed("org.enhydra.snapper.business.IndexedImpl");
38             indexedArray = in.getList(dbTransaction);
39
40         } catch (Exception JavaDoc ex) {
41             System.out.println("Exception: " + ex);
42             indexedArray = null;
43         }
44
45         HTMLTableRowElement templateRow = htmlPage.getElementTemplateRow();
46
47         HTMLElement siteNameCellTemplate = htmlPage.getElementSiteLink();
48         HTMLElement indexedTimeCellTemplate = htmlPage.getElementTime();
49
50         templateRow.removeAttribute("id");
51         siteNameCellTemplate.removeAttribute("id");
52
53         Node pathTable = templateRow.getParentNode();
54         String JavaDoc link;
55         if (indexedArray != null && indexedArray.length != 0) {
56             for (int num = 0; num < indexedArray.length; num++) {
57                 try {
58                     Indexed current = indexedArray[num];
59                     // set text of new cells to values from string array
60
htmlPage.setTextTime(current.getTime().toString());
61                     link = "NotIndexedPresentation.po?name="
62                             + current.getName() + "&id=" + current.getID();
63                     htmlPage.getElementSiteLink().setHref(link);
64                     htmlPage.setTextSiteLink(current.getName());
65                     htmlPage.setTextStart(current.getLASTSTART()
66                             .toLocaleString());
67                     htmlPage.setTextType(current.getLASTTYPE());
68                     htmlPage.setTextDoc(String.valueOf(current.getDoc()));
69
70                     final long HOURS_PER_DAY = 24l;
71                     final long MINUTES_PER_HOUR = 60l;
72                     final long SECONDS_PER_MINUTE = 60l;
73                     final long MILLISECONDS_PER_SECOND = 1000l;
74
75                     /*
76                      * value to break down into hours, minutes, seconds,
77                      * milliseconds
78                      */

79
80                     long length = current.getTime().getTime()
81                             - current.getLASTSTART().getTime();
82                     length = length / (MILLISECONDS_PER_SECOND);
83                     String JavaDoc type = "sec.";
84
85                     if ((length / SECONDS_PER_MINUTE) >= 1) {
86                         length /= SECONDS_PER_MINUTE;
87                         type = "min.";
88                         if ((length / MINUTES_PER_HOUR) >= 1) {
89                             length /= MINUTES_PER_HOUR;
90                             type = "hr.";
91                             if ((length / HOURS_PER_DAY) >= 1) {
92                                 length /= HOURS_PER_DAY;
93                                 type = "days";
94                             }
95                         }
96                     }
97                     DecimalFormat JavaDoc df = new DecimalFormat JavaDoc("##0.##");
98                     htmlPage.setTextLength(df.format(length) + " " + type);
99
100                     //siteList.setTextLikeThisDisc();
101
pathTable.appendChild(templateRow.cloneNode(true));
102                 }
103
104                 catch (Exception JavaDoc ex) {
105                     ex.printStackTrace();
106                 }
107             }
108             String JavaDoc dellink = "DeleteIndexed.po?action=sites";
109             htmlPage.getElementDeleteLink().setHref(dellink);
110         }
111         else {
112             htmlPage.getElementDeleteLink().setHref("IndexedSitesPresentation.po");
113         }
114
115         
116         templateRow.getParentNode().removeChild(templateRow);
117         //siteList.setTextTime(now);
118

119         return htmlPage;
120     }
121
122 }
Popular Tags