Coverage Report - org.crosswire.jsword.bridge.BookExporter
 
Classes in this File Line Coverage Branch Coverage Complexity
BookExporter
0%
0/32
0%
0/12
3.25
 
 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 or later
 5  
  * as published by the Free Software Foundation. This program is distributed
 6  
  * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 7  
  * the 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  
  * © CrossWire Bible Society, 2008 - 2016
 18  
  *
 19  
  */
 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  
 /**
 30  
  * Exports the Book in SWORD's imp format. This is identical to SWORD's mod2imp.
 31  
  * Note: it does not work with GenBook.
 32  
  * 
 33  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 34  
  * @author DM Smith
 35  
  */
 36  
 public class BookExporter {
 37  
 
 38  0
     public BookExporter(Book book) {
 39  0
         this.book = book;
 40  0
     }
 41  
 
 42  
     public void mod2imp() throws BookException {
 43  
         // Use short key names for Bibles.
 44  0
         if (BookCategory.BIBLE.equals(book.getBookCategory())) {
 45  0
             BookName.setFullBookName(false);
 46  
         }
 47  
 
 48  0
         Key keys = book.getGlobalKeyList();
 49  
 
 50  0
         StringBuilder buf = new StringBuilder();
 51  0
         for (Key key : keys) {
 52  
             //FIXME(CJB) iteration should be pushed down to benefit from performance improvement
 53  0
             String rawText = book.getRawText(key);
 54  0
             if (rawText != null && rawText.trim().length() > 0) {
 55  0
                 buf.delete(0, buf.length());
 56  0
                 buf.append("$$$").append(key).append('\n').append(rawText);
 57  0
                 System.out.println(buf.toString());
 58  
             }
 59  0
         }
 60  0
     }
 61  
 
 62  
     private Book book;
 63  
 
 64  
     /**
 65  
      * Call with <operation> book. Where operation can be one of:
 66  
      * <ul>
 67  
      * <li>check - returns "TRUE" or "FALSE" indicating whether the index exists
 68  
      * or not</li>
 69  
      * <li>create - (re)create the index</li>
 70  
      * <li>delete - delete the index if it exists</li>
 71  
      * </ul>
 72  
      * And book is the initials of a book, e.g. KJV.
 73  
      * 
 74  
      * @param args
 75  
      */
 76  
     public static void main(String[] args) {
 77  0
         if (args.length != 1) {
 78  0
             usage();
 79  0
             return;
 80  
         }
 81  
 
 82  0
         System.err.println("BookExporter " + args[0]);
 83  
 
 84  0
         Book b = Books.installed().getBook(args[0]);
 85  0
         if (b == null) {
 86  0
             System.err.println("Book not found");
 87  0
             return;
 88  
         }
 89  
 
 90  0
         BookExporter exporter = new BookExporter(b);
 91  
         try {
 92  0
             exporter.mod2imp();
 93  0
         } catch (BookException e) {
 94  0
             System.err.println("Error while exporting");
 95  0
             e.printStackTrace();
 96  0
         }
 97  0
     }
 98  
 
 99  
     public static void usage() {
 100  0
         System.err.println("Usage: BookExporter book");
 101  0
     }
 102  
 }