Search in sources :

Example 66 with Book

use of biblemulticonverter.data.Book in project BibleMultiConverter by schierlm.

the class Validate method printSpecialVerseNumbers.

private void printSpecialVerseNumbers(Bible bible) throws IOException {
    boolean lastPrinted = false;
    for (Book b : bible.getBooks()) {
        int chapter = 0;
        for (Chapter c : b.getChapters()) {
            chapter++;
            Verse lastVerse = null;
            for (Verse v : c.getVerses()) {
                boolean print;
                if (lastVerse == null) {
                    print = !v.getNumber().equals("1");
                } else {
                    try {
                        int last = Integer.parseInt(lastVerse.getNumber());
                        print = !v.getNumber().equals("" + (last + 1));
                    } catch (NumberFormatException ex) {
                        print = true;
                    }
                }
                if (print) {
                    if (!lastPrinted && lastVerse != null) {
                        printShortVerse(b, chapter, lastVerse);
                    }
                    printShortVerse(b, chapter, v);
                } else if (lastPrinted) {
                    System.out.println("\t====");
                }
                lastPrinted = print;
                lastVerse = v;
            }
        }
    }
}
Also used : Book(biblemulticonverter.data.Book) Chapter(biblemulticonverter.data.Chapter) Verse(biblemulticonverter.data.Verse)

Example 67 with Book

use of biblemulticonverter.data.Book in project BibleMultiConverter by schierlm.

the class Accordance method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    boolean paraMarker = false;
    for (Book book : bible.getBooks()) {
        if (!BOOK_NAME_MAP.containsKey(book.getId())) {
            continue;
        }
        for (Chapter chapter : book.getChapters()) {
            for (Verse v : chapter.getVerses()) {
                if (v.getElementTypes(Integer.MAX_VALUE).contains("b")) {
                    paraMarker = true;
                    break;
                }
            }
            if (paraMarker)
                break;
        }
        if (paraMarker)
            break;
    }
    File mainFile = new File(exportArgs[0] + ".txt");
    try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mainFile), StandardCharsets.UTF_8));
        BufferedWriter bnw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportArgs[0] + "-booknames.txt"), StandardCharsets.UTF_8))) {
        for (Book book : bible.getBooks()) {
            String bookName = BOOK_NAME_MAP.get(book.getId());
            if (bookName == null) {
                System.out.println("WARNING: Skipping book " + book.getAbbr());
                continue;
            }
            bnw.write(bookName + "\t" + book.getAbbr() + "\n");
            bw.write(bookName + " ");
            int cnumber = 0;
            for (Chapter chapter : book.getChapters()) {
                cnumber++;
                bw.write(cnumber + ":");
                List<VirtualVerse> vvs = chapter.createVirtualVerses();
                if (vvs.isEmpty()) {
                    bw.write("1 " + (paraMarker ? "¶" : "") + "\n");
                    paraMarker = false;
                }
                for (VirtualVerse vv : vvs) {
                    bw.write(vv.getNumber() + " " + (paraMarker ? "¶ " : ""));
                    paraMarker = false;
                    StringBuilder sb = new StringBuilder();
                    for (Verse v : vv.getVerses()) {
                        if (!v.getNumber().equals("" + vv.getNumber())) {
                            sb.append(" <b>(" + v.getNumber() + ")</b> ");
                        }
                        v.accept(new AccordanceVisitor(sb));
                    }
                    String verseText = sb.toString().replaceAll("  +", " ").trim();
                    if (verseText.endsWith(" ¶")) {
                        verseText = verseText.substring(0, verseText.length() - 2);
                        paraMarker = true;
                    }
                    bw.write(verseText + "\n");
                }
            }
        }
    }
    if (mainFile.length() > 0) {
        try (RandomAccessFile raf = new RandomAccessFile(mainFile, "rw")) {
            raf.setLength(mainFile.length() - 1);
        }
    }
}
Also used : VirtualVerse(biblemulticonverter.data.VirtualVerse) Chapter(biblemulticonverter.data.Chapter) BufferedWriter(java.io.BufferedWriter) RandomAccessFile(java.io.RandomAccessFile) Book(biblemulticonverter.data.Book) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Aggregations

Book (biblemulticonverter.data.Book)67 Chapter (biblemulticonverter.data.Chapter)60 Verse (biblemulticonverter.data.Verse)57 FormattedText (biblemulticonverter.data.FormattedText)27 MetadataBook (biblemulticonverter.data.MetadataBook)25 VirtualVerse (biblemulticonverter.data.VirtualVerse)24 BookID (biblemulticonverter.data.BookID)22 ArrayList (java.util.ArrayList)22 File (java.io.File)20 Bible (biblemulticonverter.data.Bible)19 Headline (biblemulticonverter.data.FormattedText.Headline)18 BufferedWriter (java.io.BufferedWriter)16 FileOutputStream (java.io.FileOutputStream)15 IOException (java.io.IOException)14 OutputStreamWriter (java.io.OutputStreamWriter)13 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10 Visitor (biblemulticonverter.data.FormattedText.Visitor)9 FileInputStream (java.io.FileInputStream)9 EnumMap (java.util.EnumMap)9