Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/eireneh/bible/book/AbstractBible.java


1   
2   package com.eireneh.bible.book;
3   
4   import java.net.URL;
5   import java.util.Properties;
6   
7   import org.jdom.*;
8   
9   import com.eireneh.util.EventListenerList;
10  import com.eireneh.config.Config;
11  import com.eireneh.bible.passage.*;
12  
13  /**
14   * An AbstractBible implements a few of the more generic methods of Bible,
15   * and takes care of a BookConfig object.
16   *
17   * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
18   * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
19   * Distribution Licence:<br />
20   * Project B is free software; you can redistribute it
21   * and/or modify it under the terms of the GNU General Public License,
22   * version 2 as published by the Free Software Foundation.<br />
23   * This program is distributed in the hope that it will be useful,
24   * but WITHOUT ANY WARRANTY; without even the implied warranty of
25   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26   * General Public License for more details.<br />
27   * The License is available on the internet
28   * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
29   * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30   * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
31   * The copyright to this program is held by it's authors.
32   * </font></td></tr></table>
33   * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
34   * @see docs.Licence
35   * @author Joe Walker
36   * @version T2.I7.D8
37   */
38  public abstract class AbstractBible implements Bible
39  {
40      /**
41       * Retrieval: Create an String for the specified Verses.
42       * @param range The verses to search for
43       * @return The Bible text
44       */
45      public String getText(VerseRange range) throws BookException
46      {
47          Passage ref = PassageFactory.createPassage();
48          ref.add(range);
49  
50          BibleEle doc = new BibleEle();
51          getDocument(doc, ref);
52  
53          return doc.getText().trim();
54      }
55  
56      /**
57       * Retrieval: Use JDOM to retrieve some Bible data
58       * @param doc The document
59       * @param ref The verses to search for
60       */
61      public Element getElement(Passage ref) throws BookException
62      {
63          return null;
64      }
65  
66      /**
67       * What configuration options are available? A null return from this
68       * IS valid, and means, there is nothing to configure.
69       * @return A Config set
70       */
71      public Config getProperties() throws BookException
72      {
73          return null;
74      }
75  
76      /**
77       * If there is something to configure, and the config options are
78       * worth saving to disk (this may not be the case for read-only
79       * options) then this is where to save the stuff to.
80       * @return URL to save a properties file to
81       */
82      public URL getPropertiesURL()
83      {
84          return null;
85      }
86  
87      /**
88       * Read from the given source version to generate ourselves. This
89       * method is called in place of init(). It should periodically call
90       * <code>Thread.currentThread().isInterrupted()</code> to check that
91       * it is safe to continue, and clear up if not.
92       * @param version The source
93       */
94      public void generate(Bible version) throws BookException
95      {
96          throw new BookException("book_readonly");
97      }
98  
99      /**
100      * Add a progress listener to the list of things wanting
101      * to know whenever we make some progress
102      */
103     public void addProgressListener(ProgressListener li)
104     {
105         listeners.add(ProgressListener.class, li);
106     }
107 
108     /**
109      * Remove a progress listener from the list of things wanting
110      * to know whenever we make some progress
111      */
112     public void removeProgressListener(ProgressListener li)
113     {
114         listeners.remove(ProgressListener.class, li);
115     }
116 
117     /**
118      * Called to fire a ProgressEvent to all the Listeners, but only if
119      * there is actual progress since last time.
120      * @param percent The percentage of the way through that we are now
121      */
122     protected void fireProgressMade(String name, int percent)
123     {
124         if (this.percent == percent)
125             return;
126 
127         this.percent = percent;
128 
129         // Guaranteed to return a non-null array
130         Object[] contents = listeners.getListenerList();
131 
132         // Process the listeners last to first, notifying
133         // those that are interested in this event
134         ProgressEvent ev = null;
135         for (int i=contents.length-2; i>=0; i-=2)
136         {
137             if (contents[i] == ProgressListener.class)
138             {
139                 if (ev == null)
140                     ev = new ProgressEvent(this, name, percent);
141 
142                 ((ProgressListener) contents[i+1]).progressMade(ev);
143             }
144         }
145     }
146 
147     /** The list of listeners */
148     protected EventListenerList listeners = new EventListenerList();
149 
150     /** The current progress */
151     protected int percent = -1;
152 }