Search in sources :

Example 21 with Book

use of biblemulticonverter.data.Book 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());
    }
}
Also used : ObjectFactory(biblemulticonverter.schema.roundtripxml.ObjectFactory) DOMSource(javax.xml.transform.dom.DOMSource) Text(org.w3c.dom.Text) LineBreakKind(biblemulticonverter.data.FormattedText.LineBreakKind) Arrays(java.util.Arrays) XPath(javax.xml.xpath.XPath) XPathConstants(javax.xml.xpath.XPathConstants) StreamResult(javax.xml.transform.stream.StreamResult) Bible(biblemulticonverter.data.Bible) MetadataBook(biblemulticonverter.data.MetadataBook) MetadataBookKey(biblemulticonverter.data.MetadataBook.MetadataBookKey) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FormattedText(biblemulticonverter.data.FormattedText) Matcher(java.util.regex.Matcher) ValidateXML(biblemulticonverter.tools.ValidateXML) Document(org.w3c.dom.Document) Node(org.w3c.dom.Node) Utils(biblemulticonverter.data.Utils) XMLConstants(javax.xml.XMLConstants) Book(biblemulticonverter.data.Book) VirtualVerse(biblemulticonverter.data.VirtualVerse) RawHTMLMode(biblemulticonverter.data.FormattedText.RawHTMLMode) Properties(java.util.Properties) SchemaFactory(javax.xml.validation.SchemaFactory) NodeList(org.w3c.dom.NodeList) FormattingInstructionKind(biblemulticonverter.data.FormattedText.FormattingInstructionKind) Verse(biblemulticonverter.data.Verse) Headline(biblemulticonverter.data.FormattedText.Headline) Set(java.util.Set) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Comment(org.w3c.dom.Comment) File(java.io.File) BookID(biblemulticonverter.data.BookID) List(java.util.List) Element(org.w3c.dom.Element) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Pattern(java.util.regex.Pattern) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) ExtraAttributePriority(biblemulticonverter.data.FormattedText.ExtraAttributePriority) Chapter(biblemulticonverter.data.Chapter) Visitor(biblemulticonverter.data.FormattedText.Visitor) Visitor(biblemulticonverter.data.FormattedText.Visitor) Matcher(java.util.regex.Matcher) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) FormattingInstructionKind(biblemulticonverter.data.FormattedText.FormattingInstructionKind) Text(org.w3c.dom.Text) FormattedText(biblemulticonverter.data.FormattedText) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) BookID(biblemulticonverter.data.BookID)

Example 22 with Book

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

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

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

the class Diffable method doExport.

protected void doExport(Bible bible, Writer w) throws IOException {
    w.write(MAGIC + bible.getName() + "\n");
    for (Book book : bible.getBooks()) {
        w.write(book.getAbbr() + " = " + book.getId().getOsisID() + "\t" + book.getShortName() + "\t" + book.getLongName() + "\n");
        int chapterNumber = 0;
        for (Chapter ch : book.getChapters()) {
            chapterNumber++;
            if (ch.getProlog() != null) {
                ch.getProlog().accept(new DiffableVisitor(w, book.getAbbr() + " " + chapterNumber + " "));
            }
            for (Verse v : ch.getVerses()) {
                v.accept(new DiffableVisitor(w, book.getAbbr() + " " + chapterNumber + ":" + v.getNumber() + " "));
            }
        }
    }
}
Also used : Book(biblemulticonverter.data.Book) Chapter(biblemulticonverter.data.Chapter) Verse(biblemulticonverter.data.Verse)

Example 25 with Book

use of biblemulticonverter.data.Book 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)

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