use of biblemulticonverter.data.Chapter in project BibleMultiConverter by schierlm.
the class Validate method printHeadlines.
private void printHeadlines(Bible bible) throws IOException {
HeadlineSummaryVisitor hsv = new HeadlineSummaryVisitor();
for (Book b : bible.getBooks()) {
int cnumber = 0;
for (Chapter c : b.getChapters()) {
cnumber++;
if (c.getProlog() != null) {
hsv.setCurrentVerse(b.getAbbr() + " " + cnumber + " (Prolog)");
c.getProlog().accept(hsv);
}
for (Verse v : c.getVerses()) {
hsv.setCurrentVerse(b.getAbbr() + " " + cnumber + ":" + v.getNumber());
v.accept(hsv);
}
}
}
hsv.printVerseRange();
}
use of biblemulticonverter.data.Chapter in project BibleMultiConverter by schierlm.
the class Validate method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
Map<String, Set<String>> dictionaryEntries = null;
if (exportArgs.length > 0 && exportArgs[0].equals("IncludeExternalRefs")) {
dictionaryEntries = new HashMap<String, Set<String>>();
for (int i = 1; i < exportArgs.length; i++) {
String ref = exportArgs[i];
if (ref.startsWith("S"))
ref = "Lstrongs=" + ref.substring(1);
if (ref.startsWith("B")) {
for (Book baseBook : new Diffable().doImport(new File(ref.substring(1))).getBooks()) {
if (baseBook.getId().getZefID() < 0)
continue;
Book book = null;
for (Book oldBook : bible.getBooks()) {
if (oldBook.getId().equals(baseBook.getId())) {
book = oldBook;
break;
}
}
if (book == null) {
book = new Book(baseBook.getAbbr(), baseBook.getId(), "$BBL$" + baseBook.getAbbr(), "$BBL$" + baseBook.getAbbr());
bible.getBooks().add(book);
}
for (int ch = 0; ch < baseBook.getChapters().size(); ch++) {
for (Verse v : baseBook.getChapters().get(ch).getVerses()) {
while (book.getChapters().size() <= ch) book.getChapters().add(new Chapter());
Chapter c = book.getChapters().get(ch);
boolean verseFound = false;
for (Verse vv : c.getVerses()) {
if (vv.getNumber().equals(v.getNumber())) {
verseFound = true;
break;
}
}
if (!verseFound) {
Verse vv = new Verse(v.getNumber());
vv.getAppendVisitor().visitText("X");
vv.finished();
c.getVerses().add(vv);
}
}
}
}
} else if (ref.startsWith("L")) {
if (ref.contains("=")) {
int pos = ref.indexOf('=');
Set<String> entryList = new HashSet<>();
try (BufferedReader br = new BufferedReader(new FileReader(ref.substring(pos + 1)))) {
String line;
while ((line = br.readLine()) != null) {
entryList.add(line);
}
}
dictionaryEntries.put(ref.substring(1, pos), entryList);
} else {
Set<String> entryList = new HashSet<>();
for (Book bk : bible.getBooks()) {
if (bk.getId().equals(BookID.DICTIONARY_ENTRY)) {
entryList.add(bk.getAbbr());
}
}
dictionaryEntries.put(ref.substring(1), entryList);
}
} else if (ref.startsWith("X")) {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(ref.substring(1)))) {
for (Book bk : bible.getBooks()) {
if (bk.getId().equals(BookID.DICTIONARY_ENTRY)) {
bw.write(bk.getAbbr());
bw.newLine();
}
}
}
} else {
System.out.println("WARNING: external reference: " + ref);
}
}
exportArgs = new String[0];
}
List<String> danglingReferences = new ArrayList<>();
bible.validate(danglingReferences, dictionaryEntries);
if (danglingReferences.size() > 0) {
System.out.println("Dangling references: ");
for (String reference : danglingReferences) {
System.out.println("\t" + reference);
}
System.out.println();
}
if (exportArgs.length == 1 && exportArgs[0].equals("PrintSpecialVerseSummary")) {
System.out.println("Special verse numbers:");
printSpecialVerseNumbers(bible);
} else if (exportArgs.length == 1 && exportArgs[0].equals("PrintHeadlines")) {
System.out.println("Headlines:");
printHeadlines(bible);
} else if (exportArgs.length > 0) {
System.out.println("WARNING: Unsupported arguments: " + Arrays.toString(exportArgs));
}
}
use of biblemulticonverter.data.Chapter in project BibleMultiConverter by schierlm.
the class MobiPocket method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
footNotes.setLength(0);
crossRefs.setLength(0);
footNoteCount = 0;
chapref = "";
File exportFile = new File(exportArgs[0]);
String title = bible.getName();
File directory = exportFile.getParentFile();
String filename = exportFile.getName();
try (final BufferedWriter opfw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(directory, filename + ".opf")), "UTF-8"))) {
opfw.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<package unique-identifier=\"uid\">\r\n" + " <metadata>\r\n" + " <dc-metadata xmlns:dc=\"http://purl.org/metadata/dublin_core\" xmlns:oebpackage=\"http://openebook.org/namespaces/oeb-package/1.0/\">\r\n" + " <dc:Title>" + TITLEPREFIX + title + "</dc:Title>\r\n" + " <dc:Language>" + LANGUAGE + "</dc:Language>\r\n" + " </dc-metadata>\r\n" + " <x-metadata>\r\n" + " <DatabaseName>Bible" + filename + "</DatabaseName>\r\n" + " <output encoding=\"Windows-1252\"></output>\r\n" + " </x-metadata>\r\n" + " </metadata>\r\n" + " <manifest>\r\n" + " <item id=\"onlyfile\" media-type=\"text/x-oeb1-document\" href=\"" + filename + ".html\"></item>\r\n" + " </manifest>\r\n" + " <spine>\r\n" + " <itemref idref=\"onlyfile\" />\r\n" + " </spine>\r\n" + " <tours></tours>\r\n" + " <guide></guide>\r\n" + "</package>\r\n" + "");
}
boolean isDictionary = false;
for (Book bk : bible.getBooks()) {
if (bk.getId() == BookID.DICTIONARY_ENTRY) {
isDictionary = true;
break;
} else if (bk.getId().getZefID() > 0) {
isDictionary = false;
break;
}
}
try (final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(directory, filename + ".html")), "UTF-8"))) {
bw.write("<html><head>");
bw.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
bw.write("<style type=\"text/css\">body {font-family: Verdana, Arial, Helvetica, sans-serif}</style>");
bw.write("<title>" + TITLEPREFIX + title + "</title></head><body>");
bw.newLine();
bw.write("<h1>" + title + "</h1>");
if (isDictionary) {
bw.write("<a onclick=\"index_search()\">Suchen</a><br>");
}
bw.write("<h2>" + TOC + "</h2>");
bw.newLine();
List<String> books = new ArrayList<String>();
Map<String, Integer> maxChapter = new HashMap<String, Integer>();
Map<String, BookID> bookIDs = new HashMap<String, BookID>();
for (Book bk : bible.getBooks()) {
books.add(bk.getAbbr());
if (isDictionary) {
bw.write("<p><a href=\"#" + bk.getAbbr() + "\">" + bk.getLongName() + "</a></p>");
} else {
bw.write("<p><a href=\"#b" + bookRef(bk) + "\">" + bk.getLongName() + " (" + bk.getAbbr() + ")</a></p>");
}
bw.newLine();
maxChapter.put(bk.getAbbr(), bk.getChapters().size());
bookIDs.put(bk.getAbbr(), bk.getId());
}
try (final BufferedWriter bxw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(directory, filename + ".bxr")), "UTF-8"))) {
bxw.write(title);
bxw.newLine();
for (String bk : books) {
bxw.write(bk + "|" + bookRef(bk, bookIDs.get(bk)) + "|" + maxChapter.get(bk));
bxw.newLine();
}
}
bxrs.add(new MobiPocketBXR(filename, new File(directory, filename + ".bxr")));
final String lexiconName = (isDictionary ? "Bible" : "BibleDict") + filename;
for (Book bk : bible.getBooks()) {
if (bk.getId() == BookID.DICTIONARY_ENTRY) {
bw.write("<mbp:pagebreak><idx:entry>");
bw.newLine();
bw.write("<h2><a name=\"" + bk.getAbbr() + "\" external=\"yes\"><idx:orth>" + bk.getLongName() + "</idx:orth></a></h2>");
bw.newLine();
bw.write("<p>");
bw.newLine();
writeVerse(bw, bk.getChapters().get(0).getProlog(), bible, "", lexiconName);
bw.write("</p>");
bw.newLine();
writeFootNotes(bw);
bw.write("</idx:entry>");
} else {
bw.write("<mbp:pagebreak>");
bw.newLine();
chapref = "b" + bookRef(bk);
bw.write("<h2><a name=\"" + chapref + "\" external=\"yes\">" + bk.getLongName() + " (" + bk.getAbbr() + ")</a> (<a href=\"oeb:redirect?title=BibleNavigation#" + chapref + "\">Navigation</a>)</h2>");
bw.newLine();
int chapter = 0;
for (Chapter ch : bk.getChapters()) {
chapter++;
chapref = "b" + bookRef(bk) + "c" + chapter;
bw.write("<h3><a name=\"" + chapref + "\" external=\"yes\">" + bk.getAbbr() + " " + chapter + "</a> (<a href=\"oeb:redirect?title=BibleNavigation#" + chapref + "\">Navigation</a>)</h3>");
bw.newLine();
if (ch.getProlog() != null) {
bw.write("<small>");
bw.newLine();
writeVerse(bw, ch.getProlog(), bible, "", lexiconName);
bw.write("</small>");
bw.newLine();
}
for (final Verse v : ch.getVerses()) {
writeVerse(bw, v, bible, "<b>" + v.getNumber() + "</b> ", lexiconName);
}
writeFootNotes(bw);
}
}
}
}
}
use of biblemulticonverter.data.Chapter in project BibleMultiConverter by schierlm.
the class OSIS method parseStructuredTextElement.
private void parseStructuredTextElement(Visitor<RuntimeException> vv, Element elem) {
if (elem.getNodeName().equals("lb")) {
vv.visitLineBreak(LineBreakKind.NEWLINE);
} else if (elem.getNodeName().equals("brp")) {
vv.visitLineBreak(LineBreakKind.PARAGRAPH);
} else if (elem.getNodeName().equals("divineName")) {
parseStructuredTextChildren(vv.visitFormattingInstruction(FormattingInstructionKind.DIVINE_NAME), elem);
} else if (elem.getNodeName().equals("woj")) {
parseStructuredTextChildren(vv.visitFormattingInstruction(FormattingInstructionKind.WORDS_OF_JESUS), elem);
} else if (elem.getNodeName().equals("catchWord")) {
parseStructuredTextChildren(vv.visitCSSFormatting("osis-style: catchWord; font-style:italic;"), elem);
} else if (elem.getNodeName().equals("hi")) {
FormattingInstructionKind kind;
if (elem.getAttribute("type").equals("italic")) {
kind = FormattingInstructionKind.ITALIC;
} else if (elem.getAttribute("type").equals("bold")) {
kind = FormattingInstructionKind.BOLD;
} else {
kind = null;
printWarning("WARNING: Invalid hi type: " + elem.getAttribute("type"));
}
if (elem.getChildNodes().getLength() != 0) {
Visitor<RuntimeException> vv1 = kind == null ? vv : vv.visitFormattingInstruction(kind);
parseStructuredTextChildren(vv1, elem);
}
} else if (elem.getNodeName().equals("seg") || elem.getNodeName().equals("transChange") || elem.getNodeName().equals("rdg")) {
String css;
if (elem.getNodeName().equals("seg") && elem.getAttribute("type").equals("x-alternative")) {
css = "osis-style: alternative; color: gray;";
} else if (elem.getNodeName().equals("transChange") && elem.getAttribute("type").equals("added")) {
css = "osis-style: added; font-style:italic;";
} else if (elem.getNodeName().equals("transChange") && elem.getAttribute("type").equals("deleted")) {
css = "osis-style: deleted; text-decoration: line-through; color: gray;";
} else if (elem.getNodeName().equals("transChange") && elem.getAttribute("type").equals("amplified")) {
css = "osis-style: amplified; font-style: italic;";
} else if (elem.getNodeName().equals("transChange") && elem.getAttribute("type").isEmpty()) {
css = "osis-style: trans-change;";
} else if (elem.getNodeName().equals("rdg") && elem.getAttribute("type").equals("alternative")) {
css = "osis-style: alternative-reading; color: gray;";
} else if (elem.getNodeName().equals("rdg") && elem.getAttribute("type").equals("x-literal")) {
css = "osis-style: literal-reading; color: gray;";
} else if (elem.getNodeName().equals("rdg") && elem.getAttribute("type").equals("x-meaning")) {
css = "osis-style: meaning-reading; color: gray;";
} else if (elem.getNodeName().equals("rdg") && elem.getAttribute("type").equals("x-equivalent")) {
css = "osis-style: equivalent-reading; color: gray;";
} else if (elem.getNodeName().equals("rdg") && elem.getAttribute("type").equals("x-identity")) {
css = "osis-style: identity-reading; color: gray;";
} else if (elem.getNodeName().equals("rdg") && elem.getAttribute("type").isEmpty()) {
css = "osis-style: reading; color: gray;";
} else {
css = null;
printWarning("WARNING: Invalid " + elem.getNodeName() + " type: " + elem.getAttribute("type"));
}
if (elem.getChildNodes().getLength() != 0) {
Visitor<RuntimeException> vv1 = css == null ? vv : vv.visitCSSFormatting(css);
parseStructuredTextChildren(vv1, elem);
}
} else if (elem.getNodeName().equals("note")) {
if (elem.getAttribute("type").equals("crossReference")) {
Visitor<RuntimeException> fn = vv.visitFootnote();
fn.visitText(FormattedText.XREF_MARKER);
if (elem.getFirstChild() != null && elem.getFirstChild().getNodeName().equals("reference")) {
for (Node n = elem.getFirstChild(); n != null; n = n.getNextSibling()) {
if (n instanceof Text) {
fn.visitText(n.getTextContent());
continue;
}
Element e = (Element) n;
String[] ref = e.getAttribute("osisRef").split("\\.");
if (ref.length != 3) {
printWarning("WARNING: Invalid reference target: " + e.getAttribute("osisRef"));
fn.visitText(e.getTextContent());
continue;
}
BookID bookID = BookID.fromOsisId(ref[0]);
int ch = Integer.parseInt(ref[1]);
String vs = ref[2];
fn.visitCrossReference(ref[0], bookID, ch, vs, ch, vs).visitText(e.getTextContent());
}
} else if (elem.getTextContent().length() > 0) {
// OSIS converted from USFM contains a reference back to the verse itself
for (Node n = elem.getFirstChild(); n != null; n = n.getNextSibling()) {
if (n instanceof Element && n.getNodeName().equals("reference")) {
if (((Element) n).getAttribute("osisRef").equals(((Element) elem).getAttribute("osisRef"))) {
n = n.getPreviousSibling();
n.getParentNode().removeChild(n.getNextSibling());
}
}
}
boolean first = true;
for (String ref : elem.getTextContent().split("\\|")) {
Matcher m = XREF_PATTERN.matcher(ref);
if (!m.matches()) {
ref = ref.trim();
if (ref.startsWith("1 ") || ref.startsWith("2 ") || ref.startsWith("3 ")) {
ref = ref.substring(0, 1) + ref.substring(2);
}
m = XREF_PATTERN_2.matcher(ref);
if (m.matches()) {
try {
BookID.fromOsisId(m.group(1));
} catch (IllegalArgumentException ex) {
BookID bk = null;
for (BookID id : BookID.values()) {
if (id.getThreeLetterCode().equalsIgnoreCase(m.group(1)))
bk = id;
}
if (bk != null) {
m = XREF_PATTERN_2.matcher(bk.getOsisID() + " " + m.group(2) + "." + m.group(3));
} else {
m = XREF_PATTERN_2.matcher("");
}
}
}
}
if (!first)
fn.visitText("; ");
first = false;
if (m.matches()) {
String book = m.group(1);
BookID bookID = BookID.fromOsisId(book);
int ch = Integer.parseInt(m.group(2));
String vs = m.group(3);
fn.visitCrossReference(book, bookID, ch, vs, ch, vs).visitText(ref);
} else {
printWarning("WARNING: Malformed cross reference: " + ref);
fn.visitText(ref.replaceAll("[\r\n\t ]+", " ").trim());
}
}
} else {
printWarning("WARNING: crossReference without content");
fn.visitText("-");
}
} else if (elem.getFirstChild() != null) {
Visitor<RuntimeException> v = vv.visitFootnote();
parseStructuredTextChildren(v, elem);
}
} else if (elem.getNodeName().equals("w")) {
if (elem.getFirstChild() == null)
// skip empty w tags
return;
String src = elem.getAttribute("src");
Visitor<RuntimeException> v = vv;
int[] strong = null, idx = null;
List<Integer> strongList = new ArrayList<Integer>();
for (String lemma : elem.getAttribute("lemma").trim().split(" +")) {
if (!lemma.startsWith("strong:G") && !lemma.startsWith("strong:H"))
continue;
String rawStrong = lemma.substring(8);
if (!rawStrong.matches("0*[1-9][0-9]*(-0*[1-9][0-9]*)*")) {
printWarning("WARNING: Invalid strong dictionary entry: " + rawStrong);
continue;
}
String[] strs = rawStrong.split("-");
for (String str : strs) {
strongList.add(Integer.parseInt(str));
}
}
if (!strongList.isEmpty())
strong = strongList.stream().mapToInt(s -> s).toArray();
List<String> rmac = new ArrayList<>();
for (String morph : elem.getAttribute("morph").trim().split(" +")) {
if (morph.startsWith("robinson:")) {
String rmacCandidate = morph.substring(9);
if (Utils.compilePattern(Utils.RMAC_REGEX).matcher(rmacCandidate).matches()) {
rmac.add(rmacCandidate);
} else {
printWarning("WARNING: Invalid RMAC: " + rmacCandidate);
}
}
}
if (src.matches("[0-9]{2}( [0-9]{2})*")) {
String[] strs = src.split(" ");
idx = new int[strs.length];
for (int i = 0; i < strs.length; i++) {
idx[i] = Integer.parseInt(strs[i]);
}
}
if (strong == null && rmac.isEmpty() && idx == null) {
printWarning("INFO: Skipped <w> tag without any usable information");
} else {
v = v.visitGrammarInformation(strong, rmac.isEmpty() ? null : rmac.toArray(new String[rmac.size()]), idx);
}
parseStructuredTextChildren(v, elem);
} else if (elem.getNodeName().equals("reference")) {
String osisRef = elem.getAttribute("osisRef");
if (osisRef.contains("\u00A0")) {
printWarning("WARNING: osisRef contains Non-Breaking spaces: '" + osisRef + "'");
osisRef = osisRef.replace('\u00A0', ' ');
}
if (!osisRef.equals(osisRef.trim())) {
printWarning("WARNING: Removed whitespace from osisRef '" + osisRef + "' - replaced by '" + osisRef.trim() + "'");
osisRef = osisRef.trim();
}
Matcher fixupMatcher = Utils.compilePattern("([A-Z0-9][A-Z0-9a-z]+\\.[0-9]+\\.)([0-9]+)((?:[+-][0-9]+)+)").matcher(osisRef);
if (fixupMatcher.matches()) {
osisRef = fixupMatcher.group(1) + fixupMatcher.group(2);
for (String suffix : fixupMatcher.group(3).split("(?=[+-])")) {
if (suffix.isEmpty())
continue;
osisRef += suffix.substring(0, 1).replace('+', ' ') + fixupMatcher.group(1) + suffix.substring(1);
}
printWarning("INFO: Replaced osisRef " + elem.getAttribute("osisRef") + " by " + osisRef);
}
if (osisRefMap == null) {
osisRefMap = new Properties();
String path = System.getProperty("biblemulticonverter.osisrefmap", "");
if (!path.isEmpty()) {
try (FileInputStream fis = new FileInputStream(path)) {
osisRefMap.load(fis);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
String mappedOsisRef = osisRefMap.getProperty(osisRef);
if (mappedOsisRef != null) {
printWarning("INFO: Replaced osisRef " + osisRef + " by " + mappedOsisRef + " (based on osisRef map)");
osisRef = mappedOsisRef;
}
if (osisRef.matches("[^ ]+ [^ ]+") && elem.getFirstChild() instanceof Text && elem.getFirstChild().getNextSibling() == null) {
String value = elem.getTextContent();
int lastPos = value.lastIndexOf('.');
if (lastPos != -1) {
Element newElem = elem.getOwnerDocument().createElement("reference");
newElem.setAttribute("osisRef", osisRef.split(" ")[0]);
newElem.appendChild(elem.getOwnerDocument().createTextNode(value.substring(0, lastPos)));
parseStructuredTextElement(vv, newElem);
vv.visitText(".");
newElem = elem.getOwnerDocument().createElement("reference");
newElem.setAttribute("osisRef", osisRef.split(" ")[1]);
newElem.appendChild(elem.getOwnerDocument().createTextNode(value.substring(lastPos + 1)));
parseStructuredTextElement(vv, newElem);
return;
}
}
Visitor<RuntimeException> v = vv;
if (osisRef.matches("[A-Z0-9][A-Z0-9a-z]+\\.[0-9]+\\.[0-9]+")) {
String[] osisRefParts = osisRef.split("\\.");
int chapter = Integer.parseInt(osisRefParts[1]);
try {
v = v.visitCrossReference(osisRefParts[0], BookID.fromOsisId(osisRefParts[0]), chapter, osisRefParts[2], chapter, osisRefParts[2]);
} catch (IllegalArgumentException ex) {
printWarning("WARNING: " + ex.getMessage());
}
} else if (osisRef.matches("([A-Z0-9][A-Z0-9a-z]+)\\.[0-9]+\\.[0-9]+-\\1\\.[0-9]+\\.[0-9]+")) {
String[] osisRefParts = osisRef.split("[.-]");
int firstChapter = Integer.parseInt(osisRefParts[1]);
int lastChapter = Integer.parseInt(osisRefParts[4]);
try {
v = v.visitCrossReference(osisRefParts[0], BookID.fromOsisId(osisRefParts[0]), firstChapter, osisRefParts[2], lastChapter, osisRefParts[5]);
} catch (IllegalArgumentException ex) {
printWarning("WARNING: " + ex.getMessage());
}
} else {
printWarning("WARNING: Unsupported osisRef: " + osisRef);
}
parseStructuredTextChildren(v, elem);
} else if (elem.getNodeName().equals("variation")) {
parseStructuredTextChildren(vv.visitVariationText(new String[] { elem.getAttribute("name") }), elem);
} else {
printWarning("WARNING: invalid structured element level tag: " + elem.getNodeName());
}
}
use of biblemulticonverter.data.Chapter in project BibleMultiConverter by schierlm.
the class OnLineBible method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
String outFile = exportArgs[0], namesFile = null;
;
boolean includeStrongs = false;
if (exportArgs.length > 1) {
if (exportArgs[1].equals("IncludeStrongs")) {
includeStrongs = true;
} else {
namesFile = exportArgs[1];
}
if (exportArgs.length > 2 && exportArgs[2].equals("IncludeStrongs")) {
includeStrongs = true;
}
}
Set<BookID> supportedBooks = EnumSet.noneOf(BookID.class);
for (BookMeta bm : BOOK_META) {
supportedBooks.add(bm.id);
}
Map<BookID, Book> bookMap = new EnumMap<>(BookID.class);
for (Book book : bible.getBooks()) {
if (supportedBooks.contains(book.getId()))
bookMap.put(book.getId(), book);
else
System.out.println("WARNING: Skipping book " + book.getAbbr());
}
if (namesFile != null) {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(namesFile))) {
for (BookMeta bm : BOOK_META) {
Book bk = bookMap.get(bm.id);
if (bk != null) {
bw.write(bk.getShortName() + " " + bm.abbr);
bw.newLine();
}
}
}
}
try (BufferedWriter bw = new BufferedWriter(new FileWriter(outFile))) {
for (BookMeta bm : BOOK_META) {
String prefix = "";
if (bm.id == BookID.BOOK_Matt && includeStrongs) {
prefix = "0 ";
}
Book bk = bookMap.remove(bm.id);
int[] verseCount = StandardVersification.KJV.getVerseCount(bm.id);
for (int i = 0; i < verseCount.length; i++) {
Chapter ch = bk != null && i < bk.getChapters().size() ? bk.getChapters().get(i) : null;
int maxVerse = verseCount[i];
BitSet allowedNumbers = new BitSet(maxVerse + 1);
allowedNumbers.set(1, maxVerse + 1);
List<VirtualVerse> vvs = ch == null ? null : ch.createVirtualVerses(null);
for (int vnum = 1; vnum <= verseCount[i]; vnum++) {
bw.write("$$$ " + bm.abbr + " " + (i + 1) + ":" + vnum + " ");
bw.newLine();
StringBuilder text = new StringBuilder(prefix);
if (vvs != null) {
for (VirtualVerse vv : vvs) {
if (vv.getNumber() == vnum) {
for (Headline h : vv.getHeadlines()) {
text.append(" {\\$");
h.accept(new OnLineBibleVisitor(text, includeStrongs));
text.append("\\$} ");
}
for (Verse v : vv.getVerses()) {
if (!v.getNumber().equals("" + vv.getNumber())) {
text.append("\\\\(" + v.getNumber() + ")\\\\ ");
}
v.accept(new OnLineBibleVisitor(text, includeStrongs));
}
}
}
}
if (text.length() > 0) {
bw.write(text.toString().replaceAll(" +", " "));
bw.newLine();
}
prefix = "";
}
}
}
}
if (!bookMap.isEmpty())
throw new IllegalStateException("Remaining books: " + bookMap.keySet());
}
Aggregations