| BookExporter.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: 2008
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: BookIndexer.java 1466 2007-07-02 02:48:09Z dmsmith $
21 */
22 package org.crosswire.jsword.bridge;
23
24 import org.crosswire.jsword.book.Book;
25 import org.crosswire.jsword.book.BookCategory;
26 import org.crosswire.jsword.book.BookException;
27 import org.crosswire.jsword.book.Books;
28 import org.crosswire.jsword.passage.Key;
29 import org.crosswire.jsword.versification.BookName;
30
31 /**
32 * Exports the Book in SWORD's imp format. This is identical to SWORD's mod2imp.
33 * Note: it does not work with GenBook.
34 *
35 * @see gnu.lgpl.License for license details.<br>
36 * The copyright to this program is held by it's authors.
37 * @author DM Smith [dmsmith555 at yahoo dot com]
38 */
39 public class BookExporter {
40
41 public BookExporter(Book book) {
42 this.book = book;
43 }
44
45 public void mod2imp() throws BookException {
46 // Use short key names for Bibles.
47 if (BookCategory.BIBLE.equals(book.getBookCategory())) {
48 BookName.setFullBookName(false);
49 }
50
51 Key keys = book.getGlobalKeyList();
52
53 StringBuilder buf = new StringBuilder();
54 for (Key key : keys) {
55 String rawText = book.getRawText(key);
56 if (rawText != null && rawText.trim().length() > 0) {
57 buf.delete(0, buf.length());
58 buf.append("$$$").append(key).append('\n').append(rawText);
59 System.out.println(buf.toString());
60 }
61 }
62 }
63
64 private Book book;
65
66 /**
67 * Call with <operation> book. Where operation can be one of:
68 * <ul>
69 * <li>check - returns "TRUE" or "FALSE" indicating whether the index exists
70 * or not</li>
71 * <li>create - (re)create the index</li>
72 * <li>delete - delete the index if it exists</li>
73 * </ul>
74 * And book is the initials of a book, e.g. KJV.
75 *
76 * @param args
77 */
78 public static void main(String[] args) {
79 if (args.length != 1) {
80 usage();
81 return;
82 }
83
84 System.err.println("BookExporter " + args[0]);
85
86 Book b = Books.installed().getBook(args[0]);
87 if (b == null) {
88 System.err.println("Book not found");
89 return;
90 }
91
92 BookExporter exporter = new BookExporter(b);
93 try {
94 exporter.mod2imp();
95 } catch (BookException e) {
96 System.err.println("Error while exporting");
97 e.printStackTrace();
98 }
99 }
100
101 public static void usage() {
102 System.err.println("Usage: BookExporter book");
103 }
104 }
105