Source code: com/eireneh/bible/control/search/words/StartsParamWord.java
1
2 package com.eireneh.bible.control.search.words;
3
4 import java.util.Enumeration;
5
6 import com.eireneh.util.*;
7 import com.eireneh.bible.passage.*;
8 import com.eireneh.bible.book.*;
9 import com.eireneh.bible.control.dictionary.Dictionary;
10 import com.eireneh.bible.control.search.*;
11
12 /**
13 * The Search Word for a Word to search for. The default
14 * if no other SearchWords match.
15 *
16 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
17 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
18 * Distribution Licence:<br />
19 * Project B is free software; you can redistribute it
20 * and/or modify it under the terms of the GNU General Public License,
21 * version 2 as published by the Free Software Foundation.<br />
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.<br />
26 * The License is available on the internet
27 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
28 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
29 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
30 * The copyright to this program is held by it's authors.
31 * </font></td></tr></table>
32 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
33 * @see docs.Licence
34 * @author Joe Walker
35 */
36 public class StartsParamWord implements ParamWord
37 {
38 /**
39 * Get a word for something else to word on.
40 */
41 public StartsParamWord()
42 {
43 }
44
45 /**
46 * Get a word for something else to word on.
47 * @param engine The controller that can provide access to the search
48 * string or a default Bible.
49 * @return The requested text
50 * @exception SearchException If this action is not appropriate
51 */
52 public String getWord(Engine engine) throws SearchException
53 {
54 throw new SearchException("search_starts_word");
55 }
56
57 /**
58 * Get a Passage for something else to work on. WARNING the return from
59 * this method is a PassageTally which is not a 100% match for the
60 * Passage interface. Maybe this needs to be fixed somehow.
61 * @param engine The controller that can provide access to the search
62 * string or a default Bible.
63 * @return A Passage relevant to this command
64 * @exception SearchException If this action is not appropriate
65 */
66 public Passage getPassage(Engine engine) throws SearchException
67 {
68 if (!engine.elements().hasMoreElements())
69 throw new SearchException("search_starts_blank");
70
71 try
72 {
73 ParamWord param = (ParamWord) engine.elements().nextElement();
74 String word = param.getWord(engine);
75 String[] words = engine.getBible().getStartsWith(word);
76 return BookUtil.getPassage(engine.getBible(), words);
77 }
78 catch (Exception ex)
79 {
80 throw new SearchException("search_starts_other", ex);
81 }
82 }
83
84 /** The Dictionary for looking words up in */
85 private Dictionary dict = new Dictionary();
86 }