Source code: com/eireneh/bible/view/cli/View.java
1
2 package com.eireneh.bible.view.cli;
3
4 import org.w3c.dom.*;
5 import org.apache.xerces.dom.DocumentImpl;
6
7 import com.eireneh.util.*;
8
9 import com.eireneh.bible.util.*;
10 import com.eireneh.bible.control.*;
11
12 /**
13 * View is a command line interface to the Tasks that displays the results
14 * in the form of the text in the specified passages.
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 * @version D0.I0.T0
36 */
37 public class View
38 {
39 /**
40 * Easy start point
41 */
42 public static void main(String[] args)
43 {
44 try
45 {
46 Project.init();
47
48 State state = new FileState();
49 TaskFactory factory = state.getTaskFactory();
50
51 if (args.length == 0)
52 {
53 Task help = factory.getHelpAction();
54 help.calculate();
55 System.out.println(help.getResults());
56 }
57
58 int i = 0;
59 while (i < args.length)
60 {
61 Task task = factory.findCLITask(args[i]);
62 i++;
63
64 String[] params = new String[task.countParameters()];
65 for (int j=0; j<params.length; j++)
66 {
67 params[j] = args[i];
68 i++;
69 }
70
71 Document doc = new DocumentImpl();
72
73 task.setParams(params);
74 task.calculate();
75 task.getResults(doc);
76
77 String name = state.getPlainStyleName();
78 String result = state.getPlainStyle().applyStyleString(doc, name);
79
80 System.out.println(result);
81 }
82 }
83 catch (Exception ex)
84 {
85 Reporter.informUser(Search.class, ex);
86 }
87 }
88 }