Source code: com/eireneh/bible/book/raw/ParaInstsMem.java
1
2 package com.eireneh.bible.book.raw;
3
4 import java.io.*;
5 import java.util.Vector;
6
7 import com.eireneh.bible.passage.*;
8
9 /**
10 * A ParaInstsMem provides access to the list of paragraphs that
11 * punctuate the Bible.
12 *
13 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
14 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
15 * Distribution Licence:<br />
16 * Project B is free software; you can redistribute it
17 * and/or modify it under the terms of the GNU General Public License,
18 * version 2 as published by the Free Software Foundation.<br />
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.<br />
23 * The License is available on the internet
24 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
25 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
27 * The copyright to this program is held by it's authors.
28 * </font></td></tr></table>
29 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
30 * @see docs.Licence
31 * @author Joe Walker
32 * @version D0.I0.T0
33 */
34 public class ParaInstsMem extends InstsMem
35 {
36 /**
37 * Basic constructor
38 * @param raw Reference to the RawBible that is using us
39 * @param filename The leaf name to read/write
40 * @param create Should we start all over again
41 */
42 public ParaInstsMem(RawBible raw, boolean create) throws Exception
43 {
44 super(raw, "parainst.idx", create);
45 }
46
47 /**
48 * Basic constructor
49 * @param raw Reference to the RawBible that is using us
50 * @param filename The leaf name to read/write
51 * @param create Should we start all over again
52 */
53 public ParaInstsMem(RawBible raw, boolean create, StringBuffer messages)
54 {
55 super(raw, "parainst.idx", create, messages);
56 }
57
58 /**
59 * Start all over again and clear the decks for more data.
60 */
61 public void init()
62 {
63 ref = PassageFactory.createPassage();
64 }
65
66 /**
67 * Load the Resource from a stream
68 * @param in The stream to read from
69 */
70 public void load(InputStream in) throws IOException, ClassNotFoundException
71 {
72 ObjectInputStream oin = new ObjectInputStream(in);
73
74 byte[] asig = new byte[6];
75 oin.readFully(asig);
76 String ssig = new String(asig);
77 if (!ssig.equals("RAW:AI"))
78 throw new IOException("This file is not a ParaInst file");
79
80 ref = (Passage) oin.readObject();
81
82 oin.close();
83 }
84
85 /**
86 * Ensure that all changes to the index of words are written to a
87 * stream
88 * @param out The stream to write to
89 */
90 public void save(OutputStream out) throws IOException
91 {
92 ObjectOutputStream oout = new ObjectOutputStream(out);
93
94 oout.writeBytes("RAW:AI");
95 oout.writeObject(ref);
96
97 oout.close();
98 }
99
100 /**
101 * Set the new paragraph status for a verse
102 * @param para The paragraph status
103 * @param verse The Verse to set data on
104 */
105 public void setPara(boolean para, Verse verse)
106 {
107 if (para)
108 {
109 ref.add(verse);
110 }
111 else
112 {
113 ref.remove(verse);
114 }
115 }
116
117 /**
118 * Set the new paragraph status for a verse.
119 * If the load failed then we treat each verse as a new paragraph
120 * @param verse The Verse to get data on
121 */
122 public boolean getPara(Verse verse)
123 {
124 return ref.contains(verse);
125 }
126
127 /** The storage of the Para markers */
128 private Passage ref;
129 }
130