001: /*
002: * snapper
003: *
004: * Enhydra super-servlet presentation object
005: *
006: */
007:
008: package org.enhydra.snapperAdmin.presentation;
009:
010: import org.w3c.dom.html.*;
011: import org.w3c.dom.*;
012:
013: // Enhydra SuperServlet specification imports
014: import org.enhydra.snapperAdmin.spec.Site;
015: import org.enhydra.snapperAdmin.spec.SiteList;
016: import org.enhydra.snapperAdmin.spec.SiteListFactory;
017:
018: import org.enhydra.snapperAdmin.presentation.BasePO;
019: import org.enhydra.snapperAdmin.presentation.html.*;
020: import org.enhydra.snapperAdmin.spec.*;
021: import org.enhydra.xml.xmlc.XMLObject;
022:
023: public class SiteListPresentation extends BasePO {
024:
025: static public boolean haveUpdater = false;
026: static public boolean haveOptimizer = false;
027:
028: static {
029: try {
030: UpdaterSpec us = UpdaterSpecFactory
031: .getUpdater("org.enhydra.snapperAdmin.business.Updater");
032: if (us != null)
033: haveUpdater = true;
034: } catch (Exception e) {
035: }
036: }
037:
038: static {
039: try {
040: OptimizerSpec os = OptimizerSpecFactory
041: .getOptimizer("org.enhydra.snapperAdmin.business.Optimizer");
042: if (os != null)
043: haveOptimizer = true;
044: } catch (Exception e) {
045: }
046: }
047:
048: protected XMLObject getDOM() throws Exception {
049:
050: SiteListHTML siteList;
051: Site[] list;
052: String id;
053:
054: siteList = (SiteListHTML) comms.xmlcFactory
055: .create(SiteListHTML.class);
056: id = comms.request.getParameter("id");
057:
058: if (comms.request.getParameter("i") != null) {
059: siteList.getElementInfo2()
060: .setValue(
061: "Indexing site: "
062: + comms.request.getParameter("i"));
063: }
064:
065: if (comms.request.getParameter("u") != null) {
066: siteList.getElementInfo2()
067: .setValue(
068: "Updating site: "
069: + comms.request.getParameter("u"));
070: }
071:
072: if (comms.request.getParameter("l") != null) {
073: siteList.getElementInfo2().setValue(
074: "SITE LOCKED! Site is already being indexed/updated: "
075: + comms.request.getParameter("l"));
076: }
077:
078: if (comms.request.getParameter("d") != null) {
079: siteList
080: .getElementInfo2()
081: .setValue(
082: " This is community version, updating is not supported !!!");
083: }
084:
085: try {
086: SiteList sl = SiteListFactory
087: .getSiteList("org.enhydra.snapperAdmin.business.SiteListImpl");
088:
089: list = sl.getList();
090:
091: } catch (Exception ex) {
092: System.out.println("Exception: " + ex);
093: list = null;
094: }
095:
096: HTMLTableRowElement templateRow = siteList
097: .getElementTemplateRow();
098:
099: HTMLElement nameCellTemplate = siteList.getElementName();
100: HTMLElement documentsCellTemplate = siteList
101: .getElementDocuments();
102: HTMLElement queriesCellTemplate = siteList.getElementQueries();
103: HTMLElement updatedCellTemplate = siteList.getElementUpdated();
104:
105: templateRow.removeAttribute("id");
106: nameCellTemplate.removeAttribute("id");
107: documentsCellTemplate.removeAttribute("id");
108: queriesCellTemplate.removeAttribute("id");
109: updatedCellTemplate.removeAttribute("id");
110:
111: Node sitesTable = templateRow.getParentNode();
112: String link;
113: if (list != null) {
114: if (!haveUpdater) {
115: siteList.getElementUpdateLink().getParentNode()
116: .removeChild(siteList.getElementUpdateLink());
117: siteList.getElementDeleteLink().getParentNode()
118: .removeChild(siteList.getElementDeleteLink());
119: }
120:
121: for (int numSites = 0; numSites < list.length; numSites++) {
122: try {
123: Site currentSite = list[numSites];
124: // set text of new cells to values from string array
125: siteList.setTextName(currentSite.getNAME());
126: siteList.setTextDocuments(String
127: .valueOf(currentSite.getFILENR()));
128: siteList.setTextQueries(String.valueOf(currentSite
129: .getQUERYNR()));
130: if (currentSite.getLASTUPDATE() == null
131: || currentSite.getLASTUPDATE().equals("")) {
132: siteList.setTextUpdated("never");
133: } else
134: siteList.setTextUpdated(currentSite
135: .getLASTUPDATE());
136:
137: link = "javascript:indexLock('"
138: + currentSite.getNAME() + "');"; //+ currentSite.getID();
139: siteList.getElementIndexLink().setHref(link);
140:
141: if (haveUpdater) {
142:
143: link = "javascript:updateLock('"
144: + currentSite.getNAME() + "');";
145: siteList.getElementUpdateLink().setHref(link);
146:
147: link = "javascript:checkLock('DeleteSite.po?id="
148: + currentSite.getNAME() + "');";
149: siteList.getElementDeleteLink().setHref(link);
150:
151: }
152:
153: if (haveOptimizer) {
154:
155: link = "javascript:indexOptimize('"
156: + currentSite.getNAME() + "');";
157: siteList.getElementOptimizeLink().setHref(link);
158:
159: }
160:
161: link = "UpdateSitePresentation.po?site_oidInput="
162: + currentSite.getNAME();
163: siteList.getElementUpdateSiteLink().setHref(link);
164:
165: sitesTable.appendChild(templateRow.cloneNode(true));
166: }
167:
168: catch (Exception ex) {
169: ex.printStackTrace();
170: }
171: }
172: }
173:
174: if (!haveUpdater) {
175: siteList.getElementUpdateAllAtOnce().getParentNode()
176: .removeChild(siteList.getElementUpdateAllAtOnce());
177: siteList.getElementUpdateOneByOne().getParentNode()
178: .removeChild(siteList.getElementUpdateOneByOne());
179: siteList.getElementFormNew().getParentNode().removeChild(
180: siteList.getElementFormNew());
181:
182: }
183:
184: templateRow.getParentNode().removeChild(templateRow);
185: return siteList;
186: }
187:
188: }
|