| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
package org.crosswire.jsword.bridge; |
| 21 | |
|
| 22 | |
import org.crosswire.jsword.book.Book; |
| 23 | |
import org.crosswire.jsword.book.BookException; |
| 24 | |
import org.crosswire.jsword.book.Books; |
| 25 | |
import org.crosswire.jsword.passage.Key; |
| 26 | |
import org.crosswire.jsword.passage.NoSuchKeyException; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
public class BookLookup { |
| 36 | |
|
| 37 | 0 | public BookLookup(Book book) { |
| 38 | 0 | this.book = book; |
| 39 | 0 | } |
| 40 | |
|
| 41 | |
public String locate(Key key) throws BookException { |
| 42 | 0 | StringBuilder buf = new StringBuilder(); |
| 43 | |
|
| 44 | |
|
| 45 | 0 | for (Key currentKey : key) { |
| 46 | 0 | String osisID = currentKey.getOsisID(); |
| 47 | 0 | if (buf.length() > 0) { |
| 48 | 0 | buf.append('\n'); |
| 49 | |
} |
| 50 | 0 | buf.append(book.getInitials()); |
| 51 | 0 | buf.append(':'); |
| 52 | 0 | buf.append(osisID); |
| 53 | 0 | buf.append(" - "); |
| 54 | 0 | String rawText = book.getRawText(currentKey); |
| 55 | 0 | if (rawText != null && rawText.trim().length() > 0) { |
| 56 | 0 | buf.append(rawText); |
| 57 | |
} else { |
| 58 | 0 | buf.append("Not found"); |
| 59 | |
} |
| 60 | 0 | } |
| 61 | |
|
| 62 | 0 | return buf.toString(); |
| 63 | |
} |
| 64 | |
|
| 65 | |
private Book book; |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
public static void main(String[] args) { |
| 75 | 0 | if (args.length != 2) { |
| 76 | 0 | usage(); |
| 77 | 0 | return; |
| 78 | |
} |
| 79 | |
|
| 80 | 0 | System.err.print("BookLookup"); |
| 81 | 0 | for (int i = 0; i < args.length; i++) { |
| 82 | 0 | System.err.print(' '); |
| 83 | 0 | System.err.print(args[i]); |
| 84 | |
} |
| 85 | 0 | System.err.print('\n'); |
| 86 | |
|
| 87 | 0 | Book b = Books.installed().getBook(args[0]); |
| 88 | 0 | if (b == null) { |
| 89 | 0 | System.err.println("Book not found"); |
| 90 | 0 | return; |
| 91 | |
} |
| 92 | |
|
| 93 | 0 | BookLookup lookup = new BookLookup(b); |
| 94 | |
try { |
| 95 | 0 | System.out.println(lookup.locate(b.getKey(args[1]))); |
| 96 | 0 | } catch (BookException e) { |
| 97 | 0 | System.err.println("Error while doing lookup"); |
| 98 | 0 | e.printStackTrace(); |
| 99 | 0 | } catch (NoSuchKeyException e) { |
| 100 | 0 | System.err.println("Error while doing lookup"); |
| 101 | 0 | e.printStackTrace(); |
| 102 | 0 | } |
| 103 | 0 | } |
| 104 | |
|
| 105 | |
public static void usage() { |
| 106 | 0 | System.err.println("Usage: BookLookup book key"); |
| 107 | 0 | } |
| 108 | |
} |