Source code: com/eireneh/bible/view/office/ProjectB.java
1
2 package com.eireneh.bible.view.office;
3
4 import java.util.*;
5
6 import com.eireneh.bible.control.*;
7 import com.eireneh.bible.book.*;
8 import com.eireneh.util.*;
9
10 /**
11 * The ComInterface class provides some functionality that can be exposed
12 * to Microsoft Word and other similar apps.
13 *
14 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
15 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
16 * Distribution Licence:<br />
17 * Project B is free software; you can redistribute it
18 * and/or modify it under the terms of the GNU General Public License,
19 * version 2 as published by the Free Software Foundation.<br />
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * General Public License for more details.<br />
24 * The License is available on the internet
25 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
26 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
28 * The copyright to this program is held by it's authors.
29 * </font></td></tr></table>
30 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
31 * @see docs.Licence
32 * @author Joe Walker
33 * @version D0.I0.T0
34 * @com.register ( clsid=1B735FFC-08AC-11D3-A66A-0000E8E5869C, typelib=1B735FFB-08AC-11D3-A66A-0000E8E5869C )
35 */
36 public class ProjectB
37 {
38 /**
39 * Basic constructor
40 */
41 public ProjectB() throws TaskException, BookException
42 {
43 state = new FileState();
44 factory = state.getTaskFactory();
45 names = factory.getComboBoxNames();
46 bibles = Bibles.getBibleNames();
47 }
48
49 /**
50 * How many version do we have access to?
51 * @return The version count
52 */
53 public int CountBibles()
54 {
55 return bibles.length;
56 }
57
58 /**
59 * Get the name of one of the versions
60 * @param index The index of the version
61 * @return The version name
62 */
63 public String GetBibleName(int index)
64 {
65 return bibles[index];
66 }
67
68 /**
69 * Set the name of the Bible that we use for searching
70 * @param biblename The Bible name
71 */
72 public void SetBibleName(String biblename) throws BookException
73 {
74 state.setBible(biblename);
75 }
76
77 /**
78 * How many tasks do we have access to?
79 * @return The number of combo box tasks
80 */
81 public int CountTasks()
82 {
83 return names.length;
84 }
85
86 /**
87 * Get the name of one of the tasks
88 * @param index The index of the task
89 * @return The task name
90 */
91 public String GetTaskName(int index)
92 {
93 return names[index];
94 }
95
96 /**
97 * Get a list of the available versions for the drop down list
98 */
99 public int GetTaskParamCount(String name)
100 {
101 try
102 {
103 Task task = factory.findComboBoxTask(name);
104 return task.countParameters();
105 }
106 catch (TaskException ex)
107 {
108 Reporter.informUser(this, ex);
109 return 0;
110 }
111 }
112
113 /**
114 * Obtain the text of a reference
115 * @param desc The text version of the reference
116 * @return The Biblical text
117 */
118 public String ExecuteTask(String name) throws TaskException
119 {
120 Task task = factory.findComboBoxTask(name);
121 task.calculate();
122 return task.getResults();
123 }
124
125 /**
126 * Obtain the text of a reference
127 * @param desc The text version of the reference
128 * @return The Biblical text
129 */
130 public String ExecuteTask(String name, String param) throws TaskException
131 {
132 Task task = factory.findComboBoxTask(name);
133 task.setParams(new String[] { param });
134 task.calculate();
135 return task.getResults();
136 }
137
138 /** The store of tasks */
139 private TaskFactory factory;
140
141 /** The names of the tasks */
142 private String[] names;
143
144 /** The names of the available Bibles */
145 private String[] bibles;
146
147 /** The current configuration */
148 private State state;
149 }