001: /*
002: * snapper
003: *
004: * Enhydra super-servlet presentation object
005: *
006: */
007:
008: package org.enhydra.snapperAdmin.presentation;
009:
010: import java.util.HashMap;
011: import java.util.Iterator;
012: import java.util.Map;
013:
014: import org.w3c.dom.html.*;
015: import org.w3c.dom.*;
016:
017: // Enhydra SuperServlet specification imports
018: import org.enhydra.snapper.SnapperManager;
019: import org.enhydra.snapperAdmin.spec.Site;
020: import org.enhydra.snapperAdmin.spec.SiteList;
021: import org.enhydra.snapperAdmin.spec.SiteListFactory;
022:
023: import org.enhydra.snapperAdmin.presentation.BasePO;
024: import org.enhydra.snapperAdmin.presentation.html.*;
025: import org.enhydra.snapperAdmin.spec.*;
026: import org.enhydra.xml.xmlc.XMLObject;
027:
028: public class StatusPresentation extends BasePO {
029:
030: protected XMLObject getDOM() throws Exception {
031:
032: StatusListHTML status;
033: Site site = null;
034: String id;
035:
036: status = (StatusListHTML) comms.xmlcFactory
037: .create(StatusListHTML.class);
038: id = comms.request.getParameter("id");
039:
040: if (id != null) {
041: Map threads = SnapperManager.getInstance().getThreads();
042: if (threads.get(id) instanceof Update) {
043: Update ii = (Update) threads.get(id);
044: ii.setDoStop(true);
045: } else {
046: Index ii = (Index) threads.get(id);
047: ii.setDoStop(true);
048: }
049:
050: SnapperManager.getInstance().removeThread(id);
051: }
052:
053: HTMLTableRowElement templateRow = status
054: .getElementTemplateRow();
055: HTMLElement nameCellTemplate = status.getElementName();
056:
057: templateRow.removeAttribute("id");
058: nameCellTemplate.removeAttribute("id");
059:
060: Node sitesTable = templateRow.getParentNode();
061: String link;
062: Map threads = new HashMap();
063: threads = SnapperManager.getInstance().getThreads();
064:
065: for (Iterator iterator = threads.entrySet().iterator(); iterator
066: .hasNext();) {
067: Map.Entry entry = (Map.Entry) iterator.next();
068: String key = (String) entry.getKey();
069: try {
070: try {
071:
072: SiteList sl = SiteListFactory
073: .getSiteList("org.enhydra.snapperAdmin.business.SiteListImpl");
074:
075: site = sl.findSiteByName(key);
076:
077: } catch (Exception ex) {
078: System.out.println("Exception: " + ex);
079: site = null;
080: }
081: // set text of new cells to values from string array
082: if (site != null) {
083: status.setTextName(site.getNAME());
084:
085: link = "StatusPresentation.po?id=" + site.getNAME();
086: status.getElementDeleteLink().setHref(link);
087:
088: sitesTable.appendChild(templateRow.cloneNode(true));
089: }
090: }
091:
092: catch (Exception ex) {
093: ex.printStackTrace();
094: }
095: }
096: templateRow.getParentNode().removeChild(templateRow);
097: return status;
098: }
099:
100: }
|