001: /*
002: * snapper
003: *
004: * Enhydra super-servlet presentation object
005: *
006: */
007:
008: package org.enhydra.snapperAdmin.presentation;
009:
010: import java.text.DecimalFormat;
011: import java.util.Date;
012:
013: import org.enhydra.xml.xmlc.XMLObject;
014: import org.w3c.dom.Node;
015: import org.w3c.dom.html.HTMLElement;
016: import org.w3c.dom.html.HTMLTableRowElement;
017: import org.enhydra.snapperAdmin.presentation.BasePO;
018: import org.enhydra.snapperAdmin.presentation.html.IndexedSitesHistoryHTML;
019: import org.enhydra.snapperAdmin.spec.Indexed;
020: import org.enhydra.snapperAdmin.spec.IndexedFactory;
021: import org.enhydra.snapperAdmin.spec.Site;
022:
023: public class IndexedSitesPresentation extends BasePO {
024:
025: protected XMLObject getDOM() throws Exception {
026:
027: IndexedSitesHistoryHTML htmlPage;
028: Indexed[] indexedArray = null;
029: Site[] list = null;
030: Indexed in;
031:
032: htmlPage = (IndexedSitesHistoryHTML) comms.xmlcFactory
033: .create(IndexedSitesHistoryHTML.class);
034:
035: // Indexed table
036:
037: try {
038: in = IndexedFactory
039: .getIndexed("org.enhydra.snapperAdmin.business.IndexedImpl");
040: indexedArray = in.getList();
041:
042: } catch (Exception ex) {
043: System.out.println("Exception: " + ex);
044: indexedArray = null;
045: }
046:
047: HTMLTableRowElement templateRow = htmlPage
048: .getElementTemplateRow();
049:
050: HTMLElement siteNameCellTemplate = htmlPage
051: .getElementSiteLink();
052: HTMLElement indexedTimeCellTemplate = htmlPage.getElementTime();
053:
054: templateRow.removeAttribute("id");
055: siteNameCellTemplate.removeAttribute("id");
056:
057: Node pathTable = templateRow.getParentNode();
058: String link;
059: if (indexedArray != null && indexedArray.length != 0) {
060: for (int num = 0; num < indexedArray.length; num++) {
061: try {
062: Indexed current = indexedArray[num];
063: // set text of new cells to values from string array
064: htmlPage.setTextTime((new Date(current.getTime())
065: .toLocaleString()));
066: link = "NotIndexedPresentation.po?name="
067: + current.getName() + "&id="
068: + current.getName() + "_"
069: + current.getLASTTYPE() + "_"
070: + current.getLASTSTART() + ".txt";
071: htmlPage.getElementSiteLink().setHref(link);
072: htmlPage.setTextSiteLink(current.getName());
073: htmlPage.setTextStart((new Date(current
074: .getLASTSTART()).toLocaleString()));
075: htmlPage.setTextType(current.getLASTTYPE());
076: htmlPage.setTextDoc(String
077: .valueOf(current.getDoc()));
078:
079: final long HOURS_PER_DAY = 24l;
080: final long MINUTES_PER_HOUR = 60l;
081: final long SECONDS_PER_MINUTE = 60l;
082: final long MILLISECONDS_PER_SECOND = 1000l;
083:
084: /*
085: * value to break down into hours, minutes, seconds,
086: * milliseconds
087: */
088:
089: long length = current.getTime()
090: - current.getLASTSTART();
091: length = length / (MILLISECONDS_PER_SECOND);
092: String type = "sec.";
093:
094: if ((length / SECONDS_PER_MINUTE) >= 1) {
095: length /= SECONDS_PER_MINUTE;
096: type = "min.";
097: if ((length / MINUTES_PER_HOUR) >= 1) {
098: length /= MINUTES_PER_HOUR;
099: type = "hr.";
100: if ((length / HOURS_PER_DAY) >= 1) {
101: length /= HOURS_PER_DAY;
102: type = "days";
103: }
104: }
105: }
106: DecimalFormat df = new DecimalFormat("##0.##");
107: htmlPage.setTextLength(df.format(length) + " "
108: + type);
109:
110: pathTable.appendChild(templateRow.cloneNode(true));
111: }
112:
113: catch (Exception ex) {
114: ex.printStackTrace();
115: }
116: }
117: String dellink = "DeleteIndexed.po?action=sites";
118: htmlPage.getElementDeleteLink().setHref(dellink);
119: } else {
120: htmlPage.getElementDeleteLink().setHref(
121: "IndexedSitesPresentation.po");
122: }
123:
124: templateRow.getParentNode().removeChild(templateRow);
125:
126: return htmlPage;
127: }
128:
129: }
|