Search in sources :

Example 6 with Headline

use of biblemulticonverter.data.FormattedText.Headline 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());
}
Also used : VirtualVerse(biblemulticonverter.data.VirtualVerse) FileWriter(java.io.FileWriter) Chapter(biblemulticonverter.data.Chapter) BitSet(java.util.BitSet) BufferedWriter(java.io.BufferedWriter) BookID(biblemulticonverter.data.BookID) Book(biblemulticonverter.data.Book) Headline(biblemulticonverter.data.FormattedText.Headline) EnumMap(java.util.EnumMap) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Example 7 with Headline

use of biblemulticonverter.data.FormattedText.Headline in project BibleMultiConverter by schierlm.

the class QuickBible method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    StringBuilder verseSection = new StringBuilder(), pericopeSection = new StringBuilder();
    StringBuilder footnoteSection = new StringBuilder(), xrefSection = new StringBuilder();
    try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportArgs[0]), StandardCharsets.UTF_8))) {
        bw.write("info\tlongName\t" + bible.getName() + "\n");
        for (Book book : bible.getBooks()) {
            Integer bNumber = BOOK_MAP.get(book.getId());
            if (bNumber == null) {
                System.out.println("WARNING: Skipping book " + book.getAbbr());
                continue;
            }
            bw.write("book_name\t" + bNumber + "\t" + book.getShortName() + "\t" + book.getAbbr() + "\n");
            int cNumber = 0;
            for (Chapter chapter : book.getChapters()) {
                cNumber++;
                if (chapter.getVerses().isEmpty()) {
                    verseSection.append("verse\t" + bNumber + "\t" + cNumber + "\t1\t\n");
                }
                int vNumber = 0;
                for (VirtualVerse vv : chapter.createVirtualVerses()) {
                    vNumber++;
                    while (vNumber < vv.getNumber()) {
                        verseSection.append("verse\t" + bNumber + "\t" + cNumber + "\t" + vNumber + "\t\n");
                        vNumber++;
                    }
                    if (vNumber != vv.getNumber())
                        throw new RuntimeException("Expected verse " + vNumber + ", but got " + vv.getNumber());
                    for (Headline h : vv.getHeadlines()) {
                        pericopeSection.append("pericope\t" + bNumber + "\t" + cNumber + "\t" + vNumber + "\t");
                        if (!h.getElementTypes(1).equals("t")) {
                            pericopeSection.append("@@");
                        }
                        h.accept(new QuickBibleVisitor(pericopeSection, true, false, "\n", null, null, null));
                    }
                    verseSection.append("verse\t" + bNumber + "\t" + cNumber + "\t" + vNumber + "\t");
                    boolean hasFormatting = false;
                    for (Verse v : vv.getVerses()) {
                        if (!v.getNumber().equals("" + vv.getNumber()) || !v.getElementTypes(1).equals("t")) {
                            hasFormatting = true;
                            break;
                        }
                    }
                    if (hasFormatting)
                        verseSection.append("@@");
                    StringBuilder verseBuilder = new StringBuilder();
                    List<StringBuilder> footnotes = new ArrayList<>();
                    List<List<StringBuilder>> footnoteXrefs = new ArrayList<>();
                    for (Verse v : vv.getVerses()) {
                        if (!v.getNumber().equals("" + vv.getNumber())) {
                            verseBuilder.append(" @9(" + v.getNumber() + ")@7 ");
                        }
                        v.accept(new QuickBibleVisitor(verseBuilder, true, true, "", footnotes, footnoteXrefs, null));
                    }
                    int xrefCounter = 0;
                    for (int i = 0; i < footnotes.size(); i++) {
                        int fn = i + 1;
                        int tagPos = verseBuilder.indexOf("@<f" + fn + "@>@/");
                        List<StringBuilder> xrefs = footnoteXrefs.get(i);
                        String fnt = footnotes.get(i).toString();
                        for (int j = 0; j < xrefs.size(); j++) {
                            xrefCounter++;
                            String xrefTag = "@<x" + xrefCounter + "@>@/";
                            verseBuilder.insert(tagPos, xrefTag);
                            tagPos += xrefTag.length();
                            String[] parts = xrefs.get(j).toString().split("@!");
                            xrefSection.append("xref\t" + bNumber + "\t" + cNumber + "\t" + vNumber + "\t" + xrefCounter + "\t" + parts[0] + parts[1] + "@/\n");
                            fnt = fnt.replace("@!" + j + "@!", parts[1]);
                        }
                        footnoteSection.append("footnote\t" + bNumber + "\t" + cNumber + "\t" + vNumber + "\t" + fn + "\t" + fnt + "\n");
                    }
                    verseSection.append(verseBuilder.toString());
                    verseSection.append("\n");
                }
            }
        }
        bw.write(verseSection.toString());
        bw.write(pericopeSection.toString());
        bw.write(footnoteSection.toString());
        bw.write(xrefSection.toString());
    }
}
Also used : VirtualVerse(biblemulticonverter.data.VirtualVerse) Chapter(biblemulticonverter.data.Chapter) ArrayList(java.util.ArrayList) BufferedWriter(java.io.BufferedWriter) Book(biblemulticonverter.data.Book) FileOutputStream(java.io.FileOutputStream) Headline(biblemulticonverter.data.FormattedText.Headline) OutputStreamWriter(java.io.OutputStreamWriter) ArrayList(java.util.ArrayList) List(java.util.List) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Example 8 with Headline

use of biblemulticonverter.data.FormattedText.Headline in project BibleMultiConverter by schierlm.

the class ESwordHTML method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    new StrippedDiffable().mergeIntroductionPrologs(bible);
    String filename = exportArgs[0];
    String marker = exportArgs.length == 1 ? "" : exportArgs[1];
    String title = bible.getName();
    try (BufferedWriter bblx = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(filename + ".bblx.HTM")), StandardCharsets.UTF_8));
        BufferedWriter cmtx = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(filename + ".cmtx.HTM")), StandardCharsets.UTF_8))) {
        bblx.write("<html><head>\n" + "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\n" + "<style>\n" + "p{margin-top:0pt;margin-bottom:0pt;}\n" + "b.headline{font-size:14pt;}\n" + "sup.str{color:#008000;}\n" + ".xref {color:#008000;font-weight:bold;text-decoration:underline;}\n" + "</style>\n" + "</head><body>\n" + "<p>#define description=" + title + marker + "</p>\n" + "<p>#define abbreviation=ChangeMe" + marker + "</p>\n" + "<p>#define comments=Exported by BibleMultiConverter" + marker + "</p>\n" + "<p>#define version=1" + marker + "</p>\n" + "<p>#define strong=0" + marker + "</p>\n" + "<p>#define right2left=0" + marker + "</p>\n" + "<p>#define ot=1" + marker + "</p>\n" + "<p>#define nt=1" + marker + "</p>\n" + "<p>#define font=DEFAULT" + marker + "</p>\n" + "<p>#define apocrypha=1" + marker + "</p>\n" + "<p><span style=\"background-color:#C80000;\">\u00F7</span>" + marker + "</p>\n");
        cmtx.write("<html><head>\n" + "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\n" + "<style>\n" + "p{margin-top:0pt;margin-bottom:0pt;}\n" + "p.spc{margin-top:10pt;margin-bottom:0pt;}\n" + "p.prologend{border-width:1px;border-top-style:none;border-right-style:none;border-bottom-style:solid;border-left-style:none;border-color:black}\n" + "b.headline{font-size:14pt;}\n" + "sup.str{color:#008000;}\n" + "</style></head><body>\n" + "<p>#define description=" + title + " (Kommentar)" + marker + "</p>\n" + "<p>#define abbreviation=ChangeMe" + marker + "</p>\n" + "<p>#define comments=Exported by BibleMultiConverter" + marker + "</p>\n" + "<p>#define version=1" + marker + "</p>\r\n");
        for (Book book : bible.getBooks()) {
            ESwordBookInfo info = BOOK_INFO_BY_ID.get(book.getId());
            if (info == null) {
                System.out.println("WARNING: Skipping book " + book.getAbbr());
                continue;
            }
            String bname = info.name;
            int cnumber = 0;
            for (Chapter chapter : book.getChapters()) {
                cnumber++;
                if (cnumber > info.versification.length) {
                    System.out.println("WARNING: Skipping chapter " + book.getAbbr() + " " + cnumber);
                    continue;
                }
                int maxVerse = info.versification[cnumber - 1];
                BitSet allowedNumbers = new BitSet(maxVerse + 1);
                allowedNumbers.set(1, maxVerse + 1);
                FormattedText prolog = chapter.getProlog();
                for (VirtualVerse vv : chapter.createVirtualVerses(allowedNumbers)) {
                    int vnumber = vv.getNumber();
                    String vref = bname + " " + cnumber + ":" + vnumber;
                    StringBuilder parsedVerse = new StringBuilder();
                    StringBuilder parsedCommentary = new StringBuilder();
                    for (Headline hl : vv.getHeadlines()) {
                        parsedVerse.append("<b class=\"headline\">");
                        hl.accept(new ESwordVisitor(parsedVerse, marker, book.getId().isNT(), "", "", null, null));
                        parsedVerse.append("</b><br />");
                    }
                    for (Verse v : vv.getVerses()) {
                        if (!v.getNumber().equals("" + vnumber)) {
                            parsedVerse.append("<b>(" + v.getNumber() + ")</b>");
                        }
                        StringBuilder comments = new StringBuilder();
                        if (prolog != null) {
                            prolog.accept(new ESwordVisitor(comments, marker, book.getId().isNT(), "", "", "<i>", "</i>"));
                            comments.append(marker + "</p>\n<!--keep--><p class=\"prologend\">&nbsp;" + marker + "</p>\n<p class=\"spc\">");
                        }
                        v.accept(new ESwordVisitor(parsedVerse, marker, book.getId().isNT(), "", "", null, null));
                        v.accept(new ESwordVisitor(comments, marker, book.getId().isNT(), "<b>", "</b>", "", ""));
                        if (comments.toString().contains("<!--keep-->"))
                            parsedCommentary.append(comments.toString());
                    }
                    if (parsedVerse.length() == 0)
                        parsedVerse.append("-");
                    bblx.write("<p>" + vref + " " + parsedVerse.toString() + marker + "</p>\n");
                    if (parsedCommentary.length() > 0)
                        cmtx.write("<p><span style=\"background-color:#FF0000;\">\u00F7</span>" + vref + marker + "</p>\n<p>" + parsedCommentary.toString() + marker + "</p>\n");
                    prolog = null;
                }
            }
        }
        bblx.write("</body></html>");
        cmtx.write("</body></html>");
    }
}
Also used : VirtualVerse(biblemulticonverter.data.VirtualVerse) Chapter(biblemulticonverter.data.Chapter) BitSet(java.util.BitSet) FormattedText(biblemulticonverter.data.FormattedText) BufferedWriter(java.io.BufferedWriter) Book(biblemulticonverter.data.Book) FileOutputStream(java.io.FileOutputStream) Headline(biblemulticonverter.data.FormattedText.Headline) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Example 9 with Headline

use of biblemulticonverter.data.FormattedText.Headline in project BibleMultiConverter by schierlm.

the class EquipdEPUB method writeChapter.

private void writeChapter(StringWriter sw, Set<String> unsupportedFeatures, Book book, int cnum, Boolean headlinesAfter) throws IOException {
    sw.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<html dir=\"ltr\" xmlns=\"http://www.w3.org/1999/xhtml\"" + " xmlns:epub=\"http://www.idpf.org/2007/ops\" xml:lang=\"en\">\n<head>\n  <meta http-equiv=\"Content-Type\"" + " content=\"text/html;charset=UTF-8\" />\n  <title>" + xml(book.getShortName()) + " " + cnum + "</title>\n" + "  <link rel=\"stylesheet\" href=\"global.css\" type=\"text/css\" />\n</head>\n<body>\n\n<h2>" + xml(book.getShortName()) + " " + cnum + "</h2>\n\n");
    StringWriter footnoteWriter = new StringWriter();
    int[] footnoteCounter = { 0 };
    Chapter chapter = book.getChapters().get(cnum - 1);
    if (chapter.getProlog() != null)
        unsupportedFeatures.add("prolog");
    for (VirtualVerse vv : chapter.createVirtualVerses()) {
        boolean markerWritten = false;
        if (headlinesAfter != null) {
            if (headlinesAfter && !vv.getHeadlines().isEmpty()) {
                if (!paragraphOpen) {
                    sw.write("<p>");
                    paragraphOpen = true;
                }
                sw.write("<a id=\"c" + cnum + "_v" + vv.getNumber() + "\"></a>");
                markerWritten = true;
            }
            for (Headline h : vv.getHeadlines()) {
                closeParagraph(sw);
                int depth = Math.min(h.getDepth() + 2, 6);
                sw.write("<h" + depth + ">");
                h.accept(new EquipdVisitor(sw, "</h" + depth + ">\n\n", unsupportedFeatures, " in headline", footnoteWriter, footnoteCounter, book.getId().isNT()));
            }
        }
        sw.write(paragraphOpen ? " " : "<p>");
        paragraphOpen = true;
        if (!markerWritten) {
            sw.write("<a id=\"c" + cnum + "_v" + vv.getNumber() + "\"></a>");
        }
        sw.write("<span class=\"vn\">" + vv.getNumber() + "</span> ");
        for (Verse v : vv.getVerses()) {
            if (!v.getNumber().equals("" + vv.getNumber())) {
                sw.write(" <b>(" + v.getNumber() + ")</b> ");
            }
            v.accept(new EquipdVisitor(sw, "", unsupportedFeatures, " in verse", footnoteWriter, footnoteCounter, book.getId().isNT()));
        }
    }
    closeParagraph(sw);
    if (footnoteCounter[0] != 0) {
        sw.write("<div class=\"groupFootnote\">\n" + footnoteWriter.toString() + "</div>\n\n");
    }
    sw.write("</body>\n</html>");
}
Also used : StringWriter(java.io.StringWriter) VirtualVerse(biblemulticonverter.data.VirtualVerse) Headline(biblemulticonverter.data.FormattedText.Headline) Chapter(biblemulticonverter.data.Chapter) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Example 10 with Headline

use of biblemulticonverter.data.FormattedText.Headline in project BibleMultiConverter by schierlm.

the class BibleAnalyzerDatabase method startVerse.

@Override
protected Writer[] startVerse(Writer w, String abbr, int cnumber, VirtualVerse vv) throws Exception {
    for (Headline h : vv.getHeadlines()) {
        if (!headingEmpty)
            headingWriter.write("<br>");
        else
            headingEmpty = false;
        headingWriter.write(vv.getNumber() + " ");
        h.accept(new BibleAnalyzerVisitor(headingWriter));
    }
    verseRef = abbr + " " + cnumber + ":" + vv.getNumber();
    StringWriter verseWriter = new StringWriter();
    StringWriter footnoteWriter = new StringWriter();
    return new Writer[] { verseWriter, footnoteWriter };
}
Also used : StringWriter(java.io.StringWriter) Headline(biblemulticonverter.data.FormattedText.Headline) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

Headline (biblemulticonverter.data.FormattedText.Headline)24 Verse (biblemulticonverter.data.Verse)20 Chapter (biblemulticonverter.data.Chapter)18 VirtualVerse (biblemulticonverter.data.VirtualVerse)18 Book (biblemulticonverter.data.Book)17 MetadataBook (biblemulticonverter.data.MetadataBook)11 FormattedText (biblemulticonverter.data.FormattedText)10 ArrayList (java.util.ArrayList)10 BookID (biblemulticonverter.data.BookID)8 Bible (biblemulticonverter.data.Bible)6 BufferedWriter (java.io.BufferedWriter)6 File (java.io.File)6 FileOutputStream (java.io.FileOutputStream)6 IOException (java.io.IOException)6 BIBLEBOOK (biblemulticonverter.schema.zef2005.BIBLEBOOK)5 CAPTION (biblemulticonverter.schema.zef2005.CAPTION)5 CHAPTER (biblemulticonverter.schema.zef2005.CHAPTER)5 VERS (biblemulticonverter.schema.zef2005.VERS)5 OutputStreamWriter (java.io.OutputStreamWriter)5 EnumMap (java.util.EnumMap)5