| ReadingsBookDriver.java |
1 /**
2 * Distribution License:
3 * JSword is free software; you can redistribute it and/or modify it under
4 * the terms of the GNU Lesser General Public License, version 2.1 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 * See the GNU Lesser General Public License for more details.
9 *
10 * The License is available on the internet at:
11 * http://www.gnu.org/copyleft/lgpl.html
12 * or by writing to:
13 * Free Software Foundation, Inc.
14 * 59 Temple Place - Suite 330
15 * Boston, MA 02111-1307, USA
16 *
17 * Copyright: 2005
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: ReadingsBookDriver.java 2050 2010-12-09 15:31:45Z dmsmith $
21 */
22 package org.crosswire.jsword.book.readings;
23
24 import java.io.IOException;
25 import java.net.URL;
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import org.crosswire.common.util.NetUtil;
30 import org.crosswire.common.util.ResourceUtil;
31 import org.crosswire.common.util.URIFilter;
32 import org.crosswire.jsword.book.Book;
33 import org.crosswire.jsword.book.BookCategory;
34 import org.crosswire.jsword.book.BookDriver;
35 import org.crosswire.jsword.book.basic.AbstractBookDriver;
36
37 /**
38 * A driver for the readings dictionary.
39 *
40 * @see gnu.lgpl.License for license details.<br>
41 * The copyright to this program is held by it's authors.
42 * @author Joe Walker [joe at eireneh dot com]
43 */
44 public class ReadingsBookDriver extends AbstractBookDriver {
45 /**
46 * Setup the array of BookMetaDatas
47 */
48 public ReadingsBookDriver() {
49 List<Book> bookList = new ArrayList<Book>();
50 String[] installedBooks = getInstalledReadingsSets();
51 for (int i = 0; i < installedBooks.length; i++) {
52 bookList.add(new ReadingsBook(this, installedBooks[i], BookCategory.DAILY_DEVOTIONS));
53 }
54
55 books = bookList.toArray(new Book[bookList.size()]);
56 }
57
58 /*
59 * (non-Javadoc)
60 *
61 * @see org.crosswire.jsword.book.BookDriver#getBooks()
62 */
63 public Book[] getBooks() {
64 return books == null ? null : (Book[]) books.clone();
65 }
66
67 /*
68 * (non-Javadoc)
69 *
70 * @see org.crosswire.jsword.book.BookDriver#getDriverName()
71 */
72 public String getDriverName() {
73 return "Readings";
74 }
75
76 /**
77 * Get the singleton instance of this driver.
78 *
79 * @return this driver instance
80 */
81 public static BookDriver instance() {
82 return INSTANCE;
83 }
84
85 /**
86 * Get a list of the available readings sets
87 */
88 public String[] getInstalledReadingsSets() {
89 try {
90 URL index = ResourceUtil.getResource(ReadingsBookDriver.class, "readings.txt");
91 return NetUtil.listByIndexFile(NetUtil.toURI(index), new ReadingsFilter());
92 } catch (IOException ex) {
93 return new String[0];
94 }
95 }
96
97 /**
98 * Get all files mentioned by readings.txt
99 */
100 static final class ReadingsFilter implements URIFilter {
101 public boolean accept(String name) {
102 return true;
103 }
104 }
105
106 /**
107 * The meta data array
108 */
109 private Book[] books;
110
111 /**
112 * Resources subdir for readings sets
113 */
114 public static final String DIR_READINGS = "readings";
115
116 /**
117 * A shared instance of this driver.
118 */
119 private static final BookDriver INSTANCE = new ReadingsBookDriver();
120 }
121