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

Quick Search    Search Deep

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


1   
2   package com.eireneh.bible.book;
3   
4   import java.io.*;
5   import java.util.*;
6   
7   import org.apache.xerces.dom.*;
8   import org.w3c.dom.*;
9   
10  import com.eireneh.util.*;
11  import com.eireneh.bible.passage.*;
12  
13  /**
14  * Some helper classes to aid Document creation, and to hide all the
15  * DOM/ProjectX/XML4J specific bits.
16  * <p>The requirements for Document handling are these:<pre>
17  *   - Do not force users of this or other packages to use org.w3c.dom
18  *   - Model the current DTD.
19  * </pre>
20  * 
21  * <p>This is the root of a set of Element type objects to help creating
22  * a DOM according to our DTD. In general it is the job of each Parent to
23  * add child Elements to itself. In general you should use the parent to
24  * create a child because it is easier. 
25  * 
26  * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
27  * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
28  * Distribution Licence:<br />
29  * Project B is free software; you can redistribute it
30  * and/or modify it under the terms of the GNU General Public License,
31  * version 2 as published by the Free Software Foundation.<br />
32  * This program is distributed in the hope that it will be useful,
33  * but WITHOUT ANY WARRANTY; without even the implied warranty of
34  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35  * General Public License for more details.<br />
36  * The License is available on the internet
37  * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
38  * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
39  * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
40  * The copyright to this program is held by it's authors.
41  * </font></td></tr></table>
42  * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
43  * @see docs.Licence
44  * @author Joe Walker
45  * @version D5.I2.T2
46  */
47  public class BibleEle implements BookEle
48  {
49      /**
50      * Create a default BibleEleument.
51      */
52      public BibleEle()
53      {
54          doc = new DocumentImpl();
55  
56          bible = doc.createElement("bible");
57          doc.appendChild(bible);
58      }
59  
60      /**
61      * Create a default BibleEleument.
62      */
63      public BibleEle(Node node)
64      {
65          doc = node.getOwnerDocument();
66  
67          bible = doc.createElement("bible");
68          node.appendChild(bible);
69      }
70  
71      /**
72      * Get a reference to the real W3C Document.
73      * @return The Document
74      */
75      public Document getDocument()
76      {
77          return doc;
78      }
79  
80      /**
81      * This is an accessor for the root &lt;bible> Element
82      * @return The &lt;bible> Element
83      */
84      public Element getElement()
85      {
86          return bible;
87      }
88  
89      /**
90      * This is an enumeration through all the sections in this Document.
91      * Each of the sections will be able to give a list of the Verses
92      * that it contains.
93      * @return The list of sections
94      */
95      public Enumeration getSectionEles()
96      {
97          return sections.elements();
98      }
99  
100     /**
101     * Start a new section
102     * @param title The heading for this section
103     * @param version The Bible string
104     */
105     public void addSectionEle(SectionEle section)
106     {
107         sections.addElement(section);
108         bible.appendChild(section.getElement());
109     }
110 
111     /**
112     * Start a new section
113     * @param title The heading for this section
114     * @param version The Bible string
115     */
116     public SectionEle createSectionEle(String title)
117     {
118         SectionEle section = new SectionEle(this, title);
119         addSectionEle(section);
120         return section;
121     }
122 
123     /**
124     * Start a new section
125     * @param title The heading for this section
126     * @param version The Bible string
127     */
128     public SectionEle createSectionEle(String title, String version)
129     {
130         SectionEle section = new SectionEle(this, title, version);
131         addSectionEle(section);
132         return section;
133     }
134 
135     /**
136     * A simplified plain text version of the data in this verse with all
137     * the markup stripped out.
138     * @return The Bible text without markup
139     */
140     public String getText()
141     {
142         StringBuffer buffer = new StringBuffer();
143         getText(buffer);
144         return buffer.toString().trim();
145     }
146 
147     /**
148     * A simplified plain text version of the data in this verse with all
149     * the markup stripped out.
150     * @return The Bible text without markup
151     */
152     public void getText(StringBuffer buffer)
153     {
154         Enumeration en = getSectionEles();
155         while (en.hasMoreElements())
156         {
157             SectionEle section = (SectionEle) en.nextElement();
158             section.getText(buffer);
159         }
160     }
161 
162     /** The list of Sections */
163     private Vector sections = new Vector();
164 
165     /** The actual data store */
166     private Document doc;
167 
168     /** The root of the DOM tree */
169     private Element bible;
170 }