001: /*
002: * snapper
003: *
004: * Enhydra super-servlet presentation object
005: *
006: */
007:
008: package org.enhydra.snapperAdmin.presentation;
009:
010: // Enhydra SuperServlet specification imports
011: import java.util.HashMap;
012: import java.util.Iterator;
013: import java.util.Map;
014:
015: import org.enhydra.snapper.SnapperManager;
016: import org.enhydra.snapperAdmin.presentation.BasePO;
017:
018: import org.enhydra.snapperAdmin.SnapperAdmin;
019: import org.enhydra.snapperAdmin.spec.Index;
020: import org.enhydra.snapperAdmin.spec.IndexAll;
021: import org.enhydra.snapperAdmin.spec.IndexAllFactory;
022: import org.enhydra.snapperAdmin.spec.IndexFactory;
023: import org.enhydra.snapperAdmin.spec.Path;
024: import org.enhydra.snapperAdmin.spec.Site;
025: import org.enhydra.snapperAdmin.spec.SiteList;
026: import org.enhydra.snapperAdmin.spec.SiteListFactory;
027: import org.enhydra.xml.xmlc.XMLObject;
028:
029: import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
030:
031: // Standard imports
032:
033: public class IndexSitePresentation extends BasePO {
034: Index index = null;
035:
036: protected XMLObject getDOM() throws Exception {
037:
038: String siteOID;
039: Site site = null;
040: Path[] pathArray = null;
041: String indexdir = "";
042: //Index index = null;
043:
044: if (comms.request.getParameter("action") != null) {
045: if (comms.request.getParameter("action").equals(
046: "indexAllAtOnce")) {
047: // index all Sites at once
048: indexAtOnce();
049: }
050:
051: else
052: indexOneByOne();
053:
054: throw new ClientPageRedirectException(comms.request
055: .getAppFileURIPath("SiteListPresentation.po"));
056: }
057:
058: siteOID = comms.request.getParameter("id");
059: try {
060:
061: Map threads = new HashMap();
062: threads = SnapperManager.getInstance().getThreads();
063:
064: for (Iterator iterator = threads.entrySet().iterator(); iterator
065: .hasNext();) {
066: Map.Entry entry = (Map.Entry) iterator.next();
067: String key = (String) entry.getKey();
068:
069: if (siteOID.equals(key)) {
070: SnapperAdmin.logInfo("Site " + siteOID
071: + " locked! Indexing Aborted.");
072: throw new ClientPageRedirectException(
073: comms.request
074: .getAppFileURIPath("SiteListPresentation.po?l="
075: + siteOID));
076: }
077: }
078:
079: } catch (Exception e) {
080: }
081:
082: try {
083: index = IndexFactory
084: .getIndex("org.enhydra.snapperAdmin.business.IndexImpl");
085: } catch (Exception ex) {
086: System.out.println("Exception: " + ex);
087: }
088:
089: //check for indexall, updateall
090: index.index(siteOID);
091: Thread newThread = new Thread((Runnable) index, siteOID);
092: newThread.start();
093: SnapperManager.getInstance().addThread(siteOID, index);
094:
095: throw new ClientPageRedirectException(comms.request
096: .getAppFileURIPath("SiteListPresentation.po")); //?i="
097: // + site.getName() + "&id=" + siteOID));
098:
099: }
100:
101: private void indexAtOnce() {
102: Site[] list;
103: try {
104: SiteList sl = SiteListFactory
105: .getSiteList("org.enhydra.snapperAdmin.business.SiteListImpl");
106: list = sl.getList();
107:
108: } catch (Exception ex) {
109: System.out.println("Exception: " + ex);
110: list = null;
111: }
112: if (list != null) {
113: for (int numSites = 0; numSites < list.length; numSites++) {
114: try {
115: String id = list[numSites].getNAME();
116: Index index = IndexFactory
117: .getIndex("org.enhydra.snapperAdmin.business.IndexImpl");
118: index.index(id);
119:
120: Thread newThread = new Thread((Runnable) index, id);
121: newThread.start();
122:
123: SnapperManager.getInstance().addThread(id, index);
124: } catch (Exception e) {
125: SnapperAdmin.logError("Could not index site");
126: }
127: }
128: }
129: }
130:
131: private void indexOneByOne() {
132: Site[] list;
133: try {
134: SiteList sl = SiteListFactory
135: .getSiteList("org.enhydra.snapperAdmin.business.SiteListImpl");
136: list = sl.getList();
137: String[] ids;
138: if (list != null) {
139: ids = new String[list.length];
140:
141: for (int i = 0; i < list.length; i++) {
142: ids[i] = list[i].getNAME();
143: }
144: } else {
145: return;
146: }
147:
148: IndexAll indexall;
149: indexall = IndexAllFactory
150: .getIndexAll("org.enhydra.snapperAdmin.business.IndexAllImpl");
151: indexall.index(ids);
152:
153: Thread newThread = new Thread((Runnable) indexall);
154: newThread.start();
155:
156: } catch (Exception ex) {
157: System.out.println("Exception: " + ex);
158: list = null;
159: }
160:
161: }
162:
163: }
|