Search in sources :

Example 6 with VirtualVerse

use of biblemulticonverter.data.VirtualVerse 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 7 with VirtualVerse

use of biblemulticonverter.data.VirtualVerse 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 8 with VirtualVerse

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

the class OSIS method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    Element osis = doc.createElement("osis");
    doc.appendChild(osis);
    osis.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    osis.setAttribute("xmlns", "http://www.bibletechnologies.net/2003/OSIS/namespace");
    osis.setAttribute("xsi:schemaLocation", "http://www.bibletechnologies.net/2003/OSIS/namespace http://www.bibletechnologies.net/osisCore.2.1.1.xsd");
    Element osisText = doc.createElement("osisText");
    osis.appendChild(osisText);
    osisText.setAttribute("canonical", "true");
    osisText.setAttribute("osisIDWork", "Exported");
    osisText.appendChild(buildHeader(doc, bible.getName()));
    for (Book bk : bible.getBooks()) {
        Element book = doc.createElement("div");
        osisText.appendChild(book);
        book.setAttribute("type", "book");
        book.setAttribute("canonical", "true");
        book.setAttribute("osisID", bk.getId().getOsisID());
        Element bookTitle = doc.createElement("title");
        book.appendChild(bookTitle);
        bookTitle.setAttribute("type", "main");
        bookTitle.appendChild(doc.createTextNode(bk.getLongName()));
        int cnumber = 0;
        for (Chapter chp : bk.getChapters()) {
            cnumber++;
            Element chapter = doc.createElement("chapter");
            book.appendChild(chapter);
            chapter.setAttribute("osisID", bk.getId().getOsisID() + "." + cnumber);
            OSISVisitor visitor = new OSISVisitor(chapter, bk.getId().isNT());
            Element elem = doc.createElement("title");
            chapter.appendChild(elem);
            elem.setAttribute("type", "chapter");
            elem.appendChild(doc.createTextNode(bk.getAbbr() + " " + cnumber));
            if (chp.getProlog() != null) {
                chp.getProlog().accept(visitor);
            }
            for (VirtualVerse vv : chp.createVirtualVerses()) {
                String osisID = bk.getId().getOsisID() + "." + cnumber + "." + vv.getNumber();
                for (Headline hl : vv.getHeadlines()) {
                    hl.accept(visitor.visitHeadline(hl.getDepth()));
                }
                Element verse = doc.createElement("verse");
                chapter.appendChild(verse);
                verse.setAttribute("osisID", osisID);
                for (Verse v : vv.getVerses()) {
                    if (!v.getNumber().equals("" + vv.getNumber())) {
                        elem = doc.createElement("hi");
                        verse.appendChild(elem);
                        elem.setAttribute("type", "bold");
                        elem.appendChild(doc.createTextNode("(" + v.getNumber() + ")"));
                    }
                    v.accept(new OSISVisitor(verse, bk.getId().isNT()));
                }
            }
        }
    }
    String milestonedElementNames = exportArgs.length > 1 ? exportArgs[1] : "verse";
    if (!milestonedElementNames.equals("-")) {
        Set<String> milestonedElements = new HashSet<>(Arrays.asList(milestonedElementNames.split(",")));
        Set<String> unsupportedMilestonedElements = new HashSet<>(milestonedElements);
        unsupportedMilestonedElements.removeAll(GENERATED_MILESTONEABLE_ELEMENTS);
        if (!unsupportedMilestonedElements.isEmpty()) {
            for (String elem : unsupportedMilestonedElements) {
                if (GENERATED_UNMILESTONEABLE_ELEMENTS.contains(elem)) {
                    System.out.println("ERROR: " + elem + " may not be milestoned");
                } else {
                    System.out.println("ERROR: " + elem + " is never generated by the OSIS export");
                }
            }
            throw new IllegalArgumentException("Cannot create milestoned elements: " + milestonedElementNames);
        }
        convertChildrenToMilestoned(doc.getDocumentElement(), milestonedElements);
    }
    TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc), new StreamResult(new File(exportArgs[0])));
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) VirtualVerse(biblemulticonverter.data.VirtualVerse) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) Chapter(biblemulticonverter.data.Chapter) Document(org.w3c.dom.Document) MetadataBook(biblemulticonverter.data.MetadataBook) Book(biblemulticonverter.data.Book) Headline(biblemulticonverter.data.FormattedText.Headline) File(java.io.File) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse) HashSet(java.util.HashSet)

Example 9 with VirtualVerse

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

the class SimpleJSON method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportArgs[0]), StandardCharsets.UTF_8))) {
        SimpleJSONVisitor sjv = new SimpleJSONVisitor(bw);
        bw.write("\t{\"osis\": [{\"osisText\": [{\"osisRefWork\": {\"_value\": \"" + json(bible.getName()) + "\"}," + "\t\t\"header\": [{\"work\": [{");
        MetadataBook mdbk = bible.getMetadataBook();
        for (MetadataBookKey key : Arrays.asList(MetadataBookKey.title, MetadataBookKey.creator, MetadataBookKey.contributors, MetadataBookKey.identifier, MetadataBookKey.subject, MetadataBookKey.date, MetadataBookKey.description, MetadataBookKey.publisher, MetadataBookKey.type, MetadataBookKey.source, MetadataBookKey.language, MetadataBookKey.coverage, MetadataBookKey.rights)) {
            if (key != MetadataBookKey.title)
                bw.write(',');
            String value = mdbk == null ? null : mdbk.getValue(key);
            bw.write("\"" + key.toString() + "\": [{\"_text\": \"" + json(value == null ? "" : value) + "\"}]");
        }
        bw.write("}]}],\t\"div\": [");
        boolean first = true;
        for (Book bk : bible.getBooks()) {
            if (bk.getChapters().isEmpty() || bk.getChapters().get(0).getVerses().isEmpty()) {
                System.out.println("WARNING: Skipping empty book " + bk.getAbbr());
                continue;
            }
            if (!first)
                bw.write(',');
            bw.write("\t{\"name\": {\"_value\": \"" + json(bk.getLongName()) + "\"},\"osisID\": {\"_value\": \"" + json(bk.getId().getOsisID()) + "\"},\"chapter\": [");
            first = true;
            for (int ch = 1; ch <= bk.getChapters().size(); ch++) {
                if (!first)
                    bw.write(',');
                Chapter cc = bk.getChapters().get(ch - 1);
                bw.write("\t{\"cnumber\":" + ch + ",\n\"verse\": [");
                first = true;
                for (VirtualVerse vv : cc.createVirtualVerses()) {
                    if (!first)
                        bw.write(',');
                    bw.write("\t{\"osisID\": {\"_value\": \"" + json(bk.getId().getOsisID() + "." + ch + "." + vv.getNumber()) + "\"},\"vnumber\":" + vv.getNumber() + ",\"_text\": \"");
                    for (Verse v : vv.getVerses()) {
                        if (!v.getNumber().equals("" + vv.getNumber())) {
                            bw.write(" (" + v.getNumber() + ") ");
                        }
                        v.accept(sjv);
                    }
                    bw.write("\"}");
                    first = false;
                }
                bw.write("]}");
                first = false;
            }
            bw.write("]}");
            first = false;
        }
        bw.write("]}]}]}\n");
    }
}
Also used : MetadataBook(biblemulticonverter.data.MetadataBook) VirtualVerse(biblemulticonverter.data.VirtualVerse) Chapter(biblemulticonverter.data.Chapter) BufferedWriter(java.io.BufferedWriter) MetadataBook(biblemulticonverter.data.MetadataBook) Book(biblemulticonverter.data.Book) FileOutputStream(java.io.FileOutputStream) MetadataBookKey(biblemulticonverter.data.MetadataBook.MetadataBookKey) OutputStreamWriter(java.io.OutputStreamWriter) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Example 10 with VirtualVerse

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

the class YCHPalmBible method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    String filename = exportArgs[0];
    String description = bible.getName();
    MetadataBook metadata = bible.getMetadataBook();
    if (metadata != null) {
        String metaDescription = bible.getMetadataBook().getValue(MetadataBookKey.description);
        if (metaDescription != null)
            description = metaDescription;
    }
    try (final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "windows-1252"))) {
        bw.write("<PARSERINFO ENCODE=\"Cp1252\" WORDTYPE=\"SPCSEP\">");
        bw.newLine();
        bw.write("<BIBLE NAME=\"" + bible.getName() + "\" INFO=\"" + description + "\">");
        bw.newLine();
        Visitor<IOException> contentVisitor = new FormattedText.VisitorAdapter<IOException>(null) {

            @Override
            public void visitVerseSeparator() throws IOException {
            // strip
            }

            @Override
            public void visitText(String text) throws IOException {
                bw.write(text);
            }

            @Override
            public Visitor<IOException> visitFormattingInstruction(FormattingInstructionKind kind) throws IOException {
                return this;
            }

            @Override
            public Visitor<IOException> visitCSSFormatting(String css) throws IOException {
                return this;
            }

            @Override
            public void visitLineBreak(LineBreakKind kind) throws IOException {
                bw.write(" ");
            }
        };
        for (Book bk : bible.getBooks()) {
            int zefID = bk.getId().getZefID();
            if (zefID < 1 || zefID >= PALM_BOOK_NUMBERS.length || PALM_BOOK_NUMBERS[zefID] == 0) {
                System.out.println("WARNING: Skipping unsupported book " + bk.getAbbr() + " (" + bk.getId().getOsisID() + ")");
                continue;
            }
            bw.write("<BOOK NAME=\"" + bk.getShortName() + "\" NUMBER=\"" + PALM_BOOK_NUMBERS[bk.getId().getZefID()] + "\" SHORTCUT=\"" + bk.getAbbr() + "\">");
            bw.newLine();
            String longtitle = bk.getLongName();
            int chapter = 0, verse;
            for (Chapter chap : bk.getChapters()) {
                chapter++;
                if (chap.getProlog() != null)
                    System.out.println("WARNING: Skipping prolog (prologs not supported)!");
                verse = 1;
                String chaptext = CHAPTER_NAME + " " + chapter;
                bw.write("<CHAPTER>");
                bw.newLine();
                for (VirtualVerse v : chap.createVirtualVerses()) {
                    while (v.getNumber() > verse) {
                        bw.write("<VERSE></VERSE>");
                        bw.newLine();
                        verse++;
                    }
                    if (v.getNumber() != verse)
                        throw new RuntimeException("Verse is " + v.getNumber() + ", should be " + verse);
                    boolean needVersText = false;
                    bw.write("<VERSE>");
                    if (longtitle != null) {
                        bw.write("<BOOKTEXT>" + longtitle);
                        longtitle = null;
                        needVersText = true;
                    }
                    if (chaptext != null) {
                        bw.write("<CHAPTEXT>" + chaptext);
                        chaptext = null;
                        needVersText = true;
                    }
                    for (Headline hl : v.getHeadlines()) {
                        bw.write("<DESCTEXT>");
                        hl.accept(contentVisitor);
                        needVersText = true;
                    }
                    if (needVersText)
                        bw.write("<VERSTEXT>");
                    for (Verse vv : v.getVerses()) {
                        if (!vv.getNumber().equals("" + v.getNumber())) {
                            bw.write("{" + vv.getNumber() + "} ");
                        }
                        vv.accept(contentVisitor);
                    }
                    bw.write("</VERSE>");
                    verse++;
                    bw.newLine();
                }
                bw.write("</CHAPTER>");
                bw.newLine();
            }
            bw.write("</BOOK>");
            bw.newLine();
        }
        bw.write("</BIBLE>");
        bw.newLine();
    }
}
Also used : MetadataBook(biblemulticonverter.data.MetadataBook) VirtualVerse(biblemulticonverter.data.VirtualVerse) Chapter(biblemulticonverter.data.Chapter) FormattingInstructionKind(biblemulticonverter.data.FormattedText.FormattingInstructionKind) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) LineBreakKind(biblemulticonverter.data.FormattedText.LineBreakKind) MetadataBook(biblemulticonverter.data.MetadataBook) Book(biblemulticonverter.data.Book) FileOutputStream(java.io.FileOutputStream) Headline(biblemulticonverter.data.FormattedText.Headline) OutputStreamWriter(java.io.OutputStreamWriter) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Aggregations

Chapter (biblemulticonverter.data.Chapter)17 Verse (biblemulticonverter.data.Verse)17 VirtualVerse (biblemulticonverter.data.VirtualVerse)17 Book (biblemulticonverter.data.Book)16 Headline (biblemulticonverter.data.FormattedText.Headline)12 BufferedWriter (java.io.BufferedWriter)9 MetadataBook (biblemulticonverter.data.MetadataBook)8 FileOutputStream (java.io.FileOutputStream)8 OutputStreamWriter (java.io.OutputStreamWriter)8 File (java.io.File)6 BookID (biblemulticonverter.data.BookID)5 BigInteger (java.math.BigInteger)4 QName (javax.xml.namespace.QName)4 FormattedText (biblemulticonverter.data.FormattedText)3 BIBLEBOOK (biblemulticonverter.schema.zef2005.BIBLEBOOK)3 CAPTION (biblemulticonverter.schema.zef2005.CAPTION)3 CHAPTER (biblemulticonverter.schema.zef2005.CHAPTER)3 EnumCaptionType (biblemulticonverter.schema.zef2005.EnumCaptionType)3 ObjectFactory (biblemulticonverter.schema.zef2005.ObjectFactory)3 STYLE (biblemulticonverter.schema.zef2005.STYLE)3