1
package org.crosswire.sword.orb;
3
import java.io.InputStream;
4
import java.io.InputStreamReader;
5
import java.io.BufferedReader;
6
import java.io.StringWriter;
7
import javax.servlet.http.HttpSession;
8
import javax.servlet.http.HttpSessionBindingListener;
9
import javax.servlet.http.HttpSessionBindingEvent;
11
public class SwordOrb extends Object implements HttpSessionBindingListener {
12
public static final String BIBLES = "Biblical Texts";
13
public static final String COMMENTARIES = "Commentaries";
14
public static final String LEXDICTS = "Lexicons / Dictionaries";
15
public static final String GENBOOKS = "Generic Books";
16
public static final String DAILYDEVOS = "Daily Devotional";
17
static org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(new String[]{}, null);
20
private SWMgr attach() {
23
System.out.println("attaching...");
24
org.omg.CORBA.Object obj = orb.string_to_object(ior);
25
retVal = SWMgrHelper.narrow(obj);
26
System.out.println("calling testConnection");
27
retVal.testConnection();
28
System.out.println("testConnection successful");
30
catch(org.omg.CORBA.SystemException e) {
33
System.out.println("failed in attach");
42
// this doesn't seem to work. Never seems to get called for me
43
public void finalize () throws Throwable {
44
// shut down external process
46
getSWMgrInstance().terminate();
48
catch (Exception e) {} // we know this doesn't return property cuz we killed the orb! :)
53
public void valueBound(HttpSessionBindingEvent httpSessionBindingEvent) {}
55
public void valueUnbound(HttpSessionBindingEvent httpSessionBindingEvent) {
57
// throw new Exception("value unbound; showing stacktrace");
58
getSWMgrInstance().terminate();
60
catch (Exception e) {} // we know this doesn't return properly cuz we killed the orb! :)
61
// catch (Exception e) {e.printStackTrace();} // we know this doesn't return properly cuz we killed the orb! :)
65
private void startOrb() {
67
// start external process
68
java.lang.Process p = Runtime.getRuntime().exec("swordorbserver");
69
InputStream is = p.getInputStream();
70
InputStreamReader isr = new InputStreamReader(is);
71
BufferedReader input = new BufferedReader(isr);
74
line = input.readLine();
75
// retVal = p.waitFor();
77
System.out.println("Launched ORB, IOR: " + ior);
79
catch (Exception e) {e.printStackTrace();}
83
public SWMgr getSWMgrInstance() {
86
System.out.println("trying to attach to running ORB");
89
catch(org.omg.CORBA.SystemException e) {
95
System.out.println("no ORB running; trying to launch");
97
System.out.println("trying to attach to newly launched ORB");
100
catch(org.omg.CORBA.SystemException e) {
108
public static SWMgr getSWMgrInstance(HttpSession session) {
109
SwordOrb orb = (SwordOrb)session.getAttribute("SwordOrb");
111
System.out.println("No ORB found in session; constructing a new instance");
112
orb = new SwordOrb();
113
session.setAttribute("SwordOrb", orb);
116
System.out.println("ORB found in session");
118
SWMgr mgr = orb.getSWMgrInstance();
123
public static void main(String args[]) throws Exception {
124
SWMgr mgr = new SwordOrb().getSWMgrInstance();
126
System.out.println("PrefixPath: " + mgr.getPrefixPath());
127
System.out.println("ConfigPath: " + mgr.getConfigPath());
128
ModInfo[] modInfoList = mgr.getModInfoList();
129
System.out.println("sequence size: " + modInfoList.length);
131
for (int i = 0; i < modInfoList.length; i++) {
132
System.out.println(modInfoList[i].name + ": " + modInfoList[i].category + ": " + modInfoList[i].language);
133
module = mgr.getModuleByName(modInfoList[i].name);
134
module.setKeyText("jas1:19");
135
System.out.println(module.getRenderText());
137
module = mgr.getModuleByName("WEB");
138
SearchHit[] searchResults = module.search("God love world", SearchType.MULTIWORD, 0, "");
139
for (int i = 0; i < searchResults.length; i++)
140
System.out.println(searchResults[i].key);