1
20 package org.crosswire.jsword.bridge;
21
22 import org.crosswire.jsword.book.Book;
23 import org.crosswire.jsword.book.BookCategory;
24 import org.crosswire.jsword.book.BookException;
25 import org.crosswire.jsword.book.Books;
26 import org.crosswire.jsword.passage.Key;
27 import org.crosswire.jsword.versification.BookName;
28
29
36 public class BookExporter {
37
38 public BookExporter(Book book) {
39 this.book = book;
40 }
41
42 public void mod2imp() throws BookException {
43 if (BookCategory.BIBLE.equals(book.getBookCategory())) {
45 BookName.setFullBookName(false);
46 }
47
48 Key keys = book.getGlobalKeyList();
49
50 StringBuilder buf = new StringBuilder();
51 for (Key key : keys) {
52 String rawText = book.getRawText(key);
54 if (rawText != null && rawText.trim().length() > 0) {
55 buf.delete(0, buf.length());
56 buf.append("$$$").append(key).append('\n').append(rawText);
57 System.out.println(buf.toString());
58 }
59 }
60 }
61
62 private Book book;
63
64
76 public static void main(String[] args) {
77 if (args.length != 1) {
78 usage();
79 return;
80 }
81
82 System.err.println("BookExporter " + args[0]);
83
84 Book b = Books.installed().getBook(args[0]);
85 if (b == null) {
86 System.err.println("Book not found");
87 return;
88 }
89
90 BookExporter exporter = new BookExporter(b);
91 try {
92 exporter.mod2imp();
93 } catch (BookException e) {
94 System.err.println("Error while exporting");
95 e.printStackTrace();
96 }
97 }
98
99 public static void usage() {
100 System.err.println("Usage: BookExporter book");
101 }
102 }
103