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); }