KickJava   Java API By Example, From Geeks To Geeks.

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


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

7
8 package org.enhydra.snapper.presentation;
9
10 // Enhydra SuperServlet specification imports
11
import org.enhydra.dods.DODS;
12 import org.enhydra.snapper.SnapperManager;
13 import org.enhydra.snapper.spec.IndexFactory;
14
15 import org.enhydra.snapper.spec.Index;
16 import org.enhydra.snapper.spec.IndexAll;
17 import org.enhydra.snapper.spec.IndexAllFactory;
18 import org.enhydra.snapper.spec.Path;
19 import org.enhydra.snapper.spec.PathType;
20 import org.enhydra.snapper.spec.Site;
21 import org.enhydra.snapper.spec.SiteFactory;
22 import org.enhydra.snapper.spec.SiteList;
23 import org.enhydra.snapper.spec.SiteListFactory;
24 import org.enhydra.xml.xmlc.XMLObject;
25
26 import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
27
28 // Standard imports
29

30 public class IndexSitePresentation extends BasePO {
31     Index index = null;
32
33     protected XMLObject getDOM() throws Exception JavaDoc {
34
35         String JavaDoc siteOID;
36         Site site = null;
37         Path[] pathArray = null;
38         PathType pathType = null;
39         String JavaDoc indexdir = "";
40         //Index index = null;
41

42         if (comms.request.getParameter("action") != null) {
43             if (comms.request.getParameter("action").equals("indexAllAtOnce")) {
44                 // index all Sites at once
45
indexAtOnce();
46             }
47
48             else
49                 indexOneByOne();
50
51             throw new ClientPageRedirectException(comms.request.getAppFileURIPath("SiteListPresentation.po"));
52         }
53
54         siteOID = comms.request.getParameter("id");
55         try {
56
57             site = (SiteFactory.getSite("org.enhydra.snapper.business.SiteImpl")).findSiteByID(siteOID, dbTransaction);
58
59             if (site.getLOCKED() == true) {
60
61                 SnapperManager.getInstance().getLoggingManager().info("Site locked! Indexing Aborted.");
62                 throw new ClientPageRedirectException(comms.request.getAppFileURIPath("SiteListPresentation.po?l="
63                                 + site.getName()));
64             }
65         } catch (Exception JavaDoc e) {
66         }
67
68         try {
69             index = IndexFactory.getIndex("org.enhydra.snapper.business.IndexImpl");
70         } catch (Exception JavaDoc ex) {
71             System.out.println("Exception: " + ex);
72         }
73
74         //check for indexall, updateall
75

76         index.index(siteOID, DODS.getDatabaseManager());
77         Thread JavaDoc newThread = new Thread JavaDoc((Runnable JavaDoc) index, siteOID);
78         DODS.register(newThread,DODS.getDatabaseManager());
79         newThread.start();
80         SnapperManager.getInstance().addThread(siteOID, index);
81
82         throw new ClientPageRedirectException(comms.request.getAppFileURIPath("SiteListPresentation.po")); //?i="
83
// + site.getName() + "&id=" + siteOID));
84

85     }
86
87     private void indexAtOnce() {
88         Site[] list;
89         try {
90             SiteList sl = SiteListFactory.getSiteList("org.enhydra.snapper.business.SiteListImpl");
91             list = sl.getList(dbTransaction);
92
93         } catch (Exception JavaDoc ex) {
94             System.out.println("Exception: " + ex);
95             list = null;
96         }
97
98         for (int numSites = 0; numSites < list.length; numSites++) {
99             try {
100                 String JavaDoc id = list[numSites].getID();
101                 Index index = IndexFactory.getIndex("org.enhydra.snapper.business.IndexImpl");
102                 index.index(id, DODS.getDatabaseManager());
103                 
104                 Thread JavaDoc newThread = new Thread JavaDoc((Runnable JavaDoc) index, id);
105                 DODS.register(newThread,DODS.getDatabaseManager());
106                 newThread.start();
107                 
108 // new Thread((Runnable) index, id).start();
109
SnapperManager.getInstance().addThread(id, index);
110             } catch (Exception JavaDoc e) {
111                 SnapperManager.getInstance().getLoggingManager().error("Could not index site");
112             }
113         }
114     }
115
116     private void indexOneByOne() {
117         Site[] list;
118         try {
119             SiteList sl = SiteListFactory.getSiteList("org.enhydra.snapper.business.SiteListImpl");
120             list = sl.getList(dbTransaction);
121             String JavaDoc[] ids = new String JavaDoc[list.length];
122             for (int i = 0; i < list.length; i++) {
123                 ids[i] = list[i].getID();
124             }
125             IndexAll indexall;
126             indexall = IndexAllFactory.getIndexAll("org.enhydra.snapper.business.IndexAllImpl");
127             indexall.index(ids, DODS.getDatabaseManager());
128             
129             Thread JavaDoc newThread = new Thread JavaDoc((Runnable JavaDoc) indexall);
130             DODS.register(newThread,DODS.getDatabaseManager());
131             newThread.start();
132             
133             //new Thread((Runnable) indexall).start();
134

135         } catch (Exception JavaDoc ex) {
136             System.out.println("Exception: " + ex);
137             list = null;
138         }
139
140     }
141
142 }
Popular Tags