private void installSingleBook(String initials) {
    BookInstaller bookInstaller = new BookInstaller();
    List<Book> books = (List<Book>) bookInstaller.getRepositoryBooks(REPOSITORY, BOOK_FILTER);

    for (Book book : books) {
      if (initials.equalsIgnoreCase(book.getInitials())) {
        String lang = book.getLanguage() == null ? " " : book.getLanguage().getCode();
        System.out.println("Found in repo:" + lang + " " + book.getName());

        try {
          if (Books.installed().getBook(book.getInitials()) != null) {
            System.out.println("Already installed:" + book.getInitials() + ":" + book.getName());
          } else {
            System.out.println(
                "Downloading and installing:" + book.getInitials() + ":" + book.getName());
            bookInstaller.installBook(REPOSITORY, book);
            waitToFinish();
          }

          Book installedBook = bookInstaller.getInstalledBook(book.getInitials());
          if (installedBook == null) {
            System.out.println("Not installed:" + book.getInitials() + " Name:" + book.getName());
          }

        } catch (Exception e) {
          System.out.println("Error installing:" + book.getInitials());
          e.printStackTrace();
        }
      }
    }
  }
  public void validateAllIndexes() {
    List<Book> bibles = Books.installed().getBooks(BookFilters.getBibles());

    for (Book book : bibles) {
      validateIndex(book);
    }
  }
Esempio n. 3
0
  public void testGetStrongs() throws NoSuchKeyException, BookException {
    Book book = Books.installed().getBook("KJV");
    assertTrue(
        "Should have Strongs", book.getBookMetaData().hasFeature(FeatureType.STRONGS_NUMBERS));

    Key key = book.getKey("Gen 1:1");
    BookData data = new BookData(book, key);
    Element osis = data.getOsisFragment();

    String strongsNumbers = OSISUtil.getStrongsNumbers(osis);
    assertTrue("No Strongs in KJV", strongsNumbers.length() > 0);
  }
Esempio n. 4
0
 public void testReference() {
   try {
     THMLFilter thmlFilter = new THMLFilter();
     Book dummyBook = Books.installed().getBook("KJV");
     List<Content> out =
         thmlFilter.toOSIS(
             dummyBook,
             dummyBook.getKey("Gen.1.1"),
             "<a href=\"sword://StrongsRealGreek/01909\">1909</a>");
     assertEquals(
         "THML reference not handled correctly",
         "<reference osisRef=\"sword://StrongsRealGreek/01909\">1909</reference>",
         new XMLOutputter().outputString((Element) out.get(0)));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  private void installRepoBooks() {
    BookInstaller bookInstaller = new BookInstaller();
    List<Book> books = (List<Book>) bookInstaller.getRepositoryBooks(REPOSITORY, BOOK_FILTER);

    for (Book book : books) {
      try {
        if (Books.installed().getBook(book.getInitials()) != null) {
          System.out.println("Already installed:" + book.getInitials() + ":" + book.getName());
        } else {
          System.out.println(
              "Downloading and installing:" + book.getInitials() + ":" + book.getName());
          bookInstaller.installBook(REPOSITORY, book);
          waitToFinish();
        }
      } catch (Exception e) {
        System.out.println("Error installing:" + book.getInitials());
        e.printStackTrace();
      }
    }
  }
Esempio n. 6
0
  /**
   * Call with &lt;operation&gt; book. Where operation can be one of:
   *
   * <ul>
   *   <li>check - returns "TRUE" or "FALSE" indicating whether the index exists or not
   *   <li>create - (re)create the index
   *   <li>delete - delete the index if it exists
   * </ul>
   *
   * And book is the initials of a book, e.g. KJV.
   *
   * @param args
   */
  public static void main(String[] args) {
    if (args.length != 1) {
      usage();
      return;
    }

    System.err.println("BookExporter " + args[0]);

    Book b = Books.installed().getBook(args[0]);
    if (b == null) {
      System.err.println("Book not found");
      return;
    }

    BookExporter exporter = new BookExporter(b);
    try {
      exporter.mod2imp();
    } catch (BookException e) {
      System.err.println("Error while exporting");
      e.printStackTrace();
    }
  }
 public void validateIndex(String bookInitials) {
   validateIndex(Books.installed().getBook(bookInitials));
 }
Esempio n. 8
0
  public void dump(String name, String range)
      throws NoSuchKeyException, IOException, BookException {
    Books books = Books.installed();
    Book bible = books.getBook(name);
    BookMetaData bmd = bible.getBookMetaData();
    String lastBookName = "";
    int lastChapter = -1;
    StringBuffer buf = new StringBuffer();
    boolean inPreVerse = false;

    Key keys = bible.getKey(range);

    openOutputFile(bmd.getInitials(), !BY_BOOK);
    buildDocumentOpen(buf, bmd, range, !BY_BOOK);
    if (!BY_BOOK) {
      writeDocument(buf);
    }

    // Get a verse iterator
    for (Key key : keys) {
      Verse verse = (Verse) key;
      String raw = bible.getRawText(verse);
      String osisID = verse.getOsisID();
      String currentBookName = verse.getBook().getOSIS();
      int currentChapter = verse.getChapter();

      boolean newBookFound = !lastBookName.equals(currentBookName);

      if (newBookFound) {
        if (lastBookName.length() > 0) {
          if (currentChapter == 1) {
            if (inPreVerse) {
              buildPreVerseClose(buf);
              inPreVerse = false;
            }
            buildChapterClose(buf);
          }
          buildBookClose(buf);
          buildDocumentClose(buf, BY_BOOK);
          openOutputFile(lastBookName, BY_BOOK);
          writeDocument(buf);
          closeOutputFile(BY_BOOK);
        }

        buf = new StringBuffer();
        buildDocumentOpen(buf, bmd, currentBookName, BY_BOOK);
        buildBookOpen(buf, currentBookName);
      }

      if (newBookFound || lastChapter != currentChapter) {
        if (currentChapter != 1) {
          if (inPreVerse) {
            buildPreVerseClose(buf);
            inPreVerse = false;
          }
          buildChapterClose(buf);
        }
        buildChapterOpen(buf, currentBookName, currentChapter);
      }

      /* Output the verse */

      boolean foundPreVerse = false;
      String preVerseText = "";
      if (raw.indexOf(preVerseStart) != -1) {
        Matcher matcher = preVersePattern.matcher(raw);
        StringBuffer rawbuf = new StringBuffer();
        if (matcher.find()) {
          foundPreVerse = true;
          preVerseText = matcher.group(1);
          matcher.appendReplacement(rawbuf, "");
        }
        matcher.appendTail(rawbuf);
        raw = rawbuf.toString();
      }

      boolean foundPsalmTitle = false;
      String psalmTitleText = "";
      if (raw.indexOf(psalmTitleStart) != -1) {
        Matcher matcher = psalmTitlePattern.matcher(raw);
        StringBuffer rawbuf = new StringBuffer();
        if (matcher.find()) {
          foundPsalmTitle = true;
          psalmTitleText = matcher.group(1);
          matcher.appendReplacement(rawbuf, "");
        }
        matcher.appendTail(rawbuf);
        raw = rawbuf.toString();
      }

      if (foundPsalmTitle) {
        buildPsalmTitle(buf, psalmTitleText);
      }

      if (foundPreVerse && !preVerseText.equals(psalmTitleText)) {
        if (inPreVerse) {
          buildPreVerseClose(buf);
        }
        buildPreVerseOpen(buf, preVerseText);
        inPreVerse = true;
      }

      buildVerseOpen(buf, osisID);
      buf.append(raw);
      buildVerseClose(buf, osisID);

      lastChapter = currentChapter;
      lastBookName = currentBookName;
    }

    // Close everything that is open
    if (inPreVerse) {
      buildPreVerseClose(buf);
      inPreVerse = false;
    }

    buildChapterClose(buf);
    buildBookClose(buf);
    buildDocumentClose(buf, true);
    openOutputFile(lastBookName, BY_BOOK);
    writeDocument(buf);
    closeOutputFile(true);
  }