~sword-devel/jsword/trunk

« back to all changes in this revision

Viewing changes to jsword/java/jsword/org/crosswire/jsword/book/data/DefaultBibleData.java

  • Committer: joe
  • Date: 2002-10-08 21:36:18 UTC
  • Revision ID: svn-v4:a88caf3b-7e0a-0410-8d0d-cecb45342206:trunk:80
big config and comment update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
package org.crosswire.jsword.book.data;
3
3
 
4
 
import java.util.Enumeration;
5
 
import java.util.Vector;
 
4
import java.util.ArrayList;
 
5
import java.util.Iterator;
 
6
import java.util.List;
6
7
 
7
8
import org.jdom.Document;
8
9
import org.jdom.Element;
9
10
 
10
11
/**
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.
16
 
* </pre>
17
 
*
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.
22
 
*
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}>
41
 
* @author Joe Walker
42
 
* @version D5.I2.T2
43
 
*/
 
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.
 
17
 * </pre>
 
18
 *
 
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.
 
23
 * 
 
24
 * <p><table border='1' cellPadding='3' cellSpacing='0'>
 
25
 * <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
 
26
 *
 
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>
 
41
 * @see docs.Licence
 
42
 * @author Joe Walker [joe at eireneh dot com]
 
43
 * @version $Id$
 
44
 */
44
45
public class DefaultBibleData implements BibleData
45
46
{
46
47
    /**
47
 
    * Create a default BibleElement.
48
 
    */
 
48
     * Create a default BibleElement.
 
49
     */
49
50
    public DefaultBibleData()
50
51
    {
51
52
        bible = new Element("bible");
53
54
    }
54
55
 
55
56
    /**
56
 
    * Get a reference to the real W3C Document.
57
 
    * @return The Document
58
 
    */
 
57
     * Get a reference to the real W3C Document.
 
58
     * @return The Document
 
59
     */
59
60
    public Document getDocument()
60
61
    {
61
62
        return doc;
62
63
    }
63
64
 
64
65
    /**
65
 
    * This is an accessor for the root &lt;bible> Element
66
 
    * @return The &lt;bible> Element
67
 
    */
 
66
     * This is an accessor for the root &lt;bible> Element
 
67
     * @return The &lt;bible> Element
 
68
     */
68
69
    public Element getElement()
69
70
    {
70
71
        return bible;
71
72
    }
72
73
 
73
74
    /**
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
76
 
    * that it contains.
77
 
    * @return The list of sections
78
 
    */
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
 
77
     * that it contains.
 
78
     * @return The list of sections
 
79
     */
 
80
    public Iterator getSectionDatas()
80
81
    {
81
 
        return sections.elements();
 
82
        return sections.iterator();
82
83
    }
83
84
 
84
85
    /**
85
 
    * Start a new section
86
 
    * @param title The heading for this section
87
 
    * @param version The Bible string
88
 
    */
 
86
     * Start a new section
 
87
     * @param title The heading for this section
 
88
     * @param version The Bible string
 
89
     */
89
90
    public void addSectionData(SectionData section)
90
91
    {
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());
93
94
 
94
95
        DefaultSectionData dsection = (DefaultSectionData) section;
95
 
        sections.addElement(dsection);
 
96
        sections.add(dsection);
96
97
        bible.addContent(dsection.getElement());
97
98
    }
98
99
 
99
100
    /**
100
 
    * Start a new section
101
 
    * @param title The heading for this section
102
 
    * @param version The Bible string
103
 
    */
 
101
     * Start a new section
 
102
     * @param title The heading for this section
 
103
     * @param version The Bible string
 
104
     */
104
105
    public SectionData createSectionData(String title)
105
106
    {
106
107
        SectionData section = new DefaultSectionData(this, title);
109
110
    }
110
111
 
111
112
    /**
112
 
    * Start a new section
113
 
    * @param title The heading for this section
114
 
    * @param version The Bible string
115
 
    */
 
113
     * Start a new section
 
114
     * @param title The heading for this section
 
115
     * @param version The Bible string
 
116
     */
116
117
    public SectionData createSectionData(String title, String version)
117
118
    {
118
119
        SectionData section = new DefaultSectionData(this, title, version);
121
122
    }
122
123
 
123
124
    /**
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
127
 
    */
 
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
     */
128
129
    public String getPlainText()
129
130
    {
130
131
        StringBuffer buffer = new StringBuffer();
131
132
 
132
 
        Enumeration en = getSectionDatas();
133
 
        while (en.hasMoreElements())
 
133
        Iterator it = getSectionDatas();
 
134
        while (it.hasNext())
134
135
        {
135
 
            SectionData section = (SectionData) en.nextElement();
 
136
            SectionData section = (SectionData) it.next();
136
137
            buffer.append(section.getPlainText());
137
138
        }
138
139
 
146
147
     * @clientCardinality 1
147
148
     * @supplierCardinality 1..*
148
149
     */
149
 
    private Vector sections = new Vector();
 
150
    private List sections = new ArrayList();
150
151
 
151
152
    /** The actual data store */
152
153
    private Document doc;