2
2
package org.crosswire.jsword.book.data;
4
import java.util.Enumeration;
5
import java.util.Vector;
4
import java.util.ArrayList;
5
import java.util.Iterator;
7
8
import org.jdom.Document;
8
9
import org.jdom.Element;
11
* Some helper classes to aid Document creation, and to hide all the
12
* DOM/ProjectX/XML4J specific bits.
13
* <p>The requirements for Document handling are these:<pre>
14
* - Do not force users of this or other packages to use org.w3c.dom
15
* - Model the current DTD.
18
* <p>This is the root of a set of Element type objects to help creating
19
* a DOM according to our DTD. In general it is the job of each Parent to
20
* add child Elements to itself. In general you should use the parent to
21
* create a child because it is easier.
23
* <table border='1' cellPadding='3' cellSpacing='0' width="100%">
24
* <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
25
* Distribution Licence:<br />
26
* Project B is free software; you can redistribute it
27
* and/or modify it under the terms of the GNU General Public License,
28
* version 2 as published by the Free Software Foundation.<br />
29
* This program is distributed in the hope that it will be useful,
30
* but WITHOUT ANY WARRANTY; without even the implied warranty of
31
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32
* General Public License for more details.<br />
33
* The License is available on the internet
34
* <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
35
* <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
36
* MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
37
* The copyright to this program is held by it's authors.
38
* </font></td></tr></table>
39
* @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
40
* @see <{docs.Licence}>
12
* Some helper classes to aid Document creation, and to hide all the
13
* DOM/ProjectX/XML4J specific bits.
14
* <p>The requirements for Document handling are these:<pre>
15
* - Do not force users of this or other packages to use org.w3c.dom
16
* - Model the current DTD.
19
* <p>This is the root of a set of Element type objects to help creating
20
* a DOM according to our DTD. In general it is the job of each Parent to
21
* add child Elements to itself. In general you should use the parent to
22
* create a child because it is easier.
24
* <p><table border='1' cellPadding='3' cellSpacing='0'>
25
* <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
27
* Distribution Licence:<br />
28
* JSword is free software; you can redistribute it
29
* and/or modify it under the terms of the GNU General Public License,
30
* version 2 as published by the Free Software Foundation.<br />
31
* This program is distributed in the hope that it will be useful,
32
* but WITHOUT ANY WARRANTY; without even the implied warranty of
33
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34
* General Public License for more details.<br />
35
* The License is available on the internet
36
* <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, or by writing to:
37
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
38
* MA 02111-1307, USA<br />
39
* The copyright to this program is held by it's authors.
40
* </font></td></tr></table>
42
* @author Joe Walker [joe at eireneh dot com]
44
45
public class DefaultBibleData implements BibleData
47
* Create a default BibleElement.
48
* Create a default BibleElement.
49
50
public DefaultBibleData()
51
52
bible = new Element("bible");
56
* Get a reference to the real W3C Document.
57
* @return The Document
57
* Get a reference to the real W3C Document.
58
* @return The Document
59
60
public Document getDocument()
65
* This is an accessor for the root <bible> Element
66
* @return The <bible> Element
66
* This is an accessor for the root <bible> Element
67
* @return The <bible> Element
68
69
public Element getElement()
74
* This is an enumeration through all the sections in this Document.
75
* Each of the sections will be able to give a list of the Verses
77
* @return The list of sections
79
public Enumeration getSectionDatas()
75
* This is an enumeration through all the sections in this Document.
76
* Each of the sections will be able to give a list of the Verses
78
* @return The list of sections
80
public Iterator getSectionDatas()
81
return sections.elements();
82
return sections.iterator();
86
* @param title The heading for this section
87
* @param version The Bible string
87
* @param title The heading for this section
88
* @param version The Bible string
89
90
public void addSectionData(SectionData section)
91
92
if (!(section instanceof DefaultSectionData))
92
93
throw new IllegalArgumentException("Can't mix implementations by adding a " + section.getClass().getName() + " to a " + this.getClass().getName());
94
95
DefaultSectionData dsection = (DefaultSectionData) section;
95
sections.addElement(dsection);
96
sections.add(dsection);
96
97
bible.addContent(dsection.getElement());
100
* Start a new section
101
* @param title The heading for this section
102
* @param version The Bible string
101
* Start a new section
102
* @param title The heading for this section
103
* @param version The Bible string
104
105
public SectionData createSectionData(String title)
106
107
SectionData section = new DefaultSectionData(this, title);
124
* A simplified plain text version of the data in this verse with all
125
* the markup stripped out.
126
* @return The Bible text without markup
125
* A simplified plain text version of the data in this verse with all
126
* the markup stripped out.
127
* @return The Bible text without markup
128
129
public String getPlainText()
130
131
StringBuffer buffer = new StringBuffer();
132
Enumeration en = getSectionDatas();
133
while (en.hasMoreElements())
133
Iterator it = getSectionDatas();
135
SectionData section = (SectionData) en.nextElement();
136
SectionData section = (SectionData) it.next();
136
137
buffer.append(section.getPlainText());