Search in sources :

Example 46 with Chapter

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

the class ZefaniaXML method createXMLBible.

protected XMLBIBLE createXMLBible(Bible bible) throws Exception {
    ObjectFactory of = new ObjectFactory();
    XMLBIBLE doc = of.createXMLBIBLE();
    doc.setBiblename(bible.getName());
    doc.setType(EnumModtyp.X_BIBLE);
    doc.setINFORMATION(of.createINFORMATION());
    MetadataBook metadata = bible.getMetadataBook();
    if (metadata != null) {
        for (String key : metadata.getKeys()) {
            String value = metadata.getValue(key);
            if (key.equals(MetadataBookKey.status.toString())) {
                doc.setStatus(EnumStatus.fromValue(value));
            } else if (key.equals(MetadataBookKey.version.toString())) {
                doc.setVersion(value);
            } else if (key.equals(MetadataBookKey.revision.toString())) {
                doc.setRevision(new BigInteger(value));
            } else if (!key.contains("@")) {
                Pattern regex = INFORMATION_FIELDS.get(MetadataBookKey.valueOf(key));
                if (regex != null && regex.matcher(value).matches())
                    doc.getINFORMATION().getTitleOrCreatorOrDescription().add(new JAXBElement<String>(new QName(key), String.class, value));
            }
        }
    }
    doc.getINFORMATION().getTitleOrCreatorOrDescription().add(new JAXBElement<String>(new QName("format"), String.class, "Zefania XML Bible Markup Language"));
    for (Book bk : bible.getBooks()) {
        if (bk.getId().equals(BookID.METADATA))
            continue;
        if (bk.getId().getZefID() <= 0) {
            System.out.println("WARNING: Unable to export book " + bk.getAbbr());
            continue;
        }
        BIBLEBOOK bb = of.createBIBLEBOOK();
        bb.setBnumber(BigInteger.valueOf(bk.getId().getZefID()));
        bb.setBsname(bk.getShortName());
        bb.setBname(bk.getLongName());
        int cnumber = 0;
        for (Chapter ccc : bk.getChapters()) {
            cnumber++;
            if (ccc.getVerses().size() == 0)
                continue;
            CHAPTER cc = of.createCHAPTER();
            cc.setCnumber(BigInteger.valueOf(cnumber));
            bb.getCHAPTER().add(cc);
            if (ccc.getProlog() != null) {
                PROLOG prolog = of.createPROLOG();
                prolog.setVref(BigInteger.ONE);
                ccc.getProlog().accept(new CreateContentVisitor(of, prolog.getContent(), null));
                cc.getPROLOGOrCAPTIONOrVERS().add(prolog);
            }
            for (VirtualVerse vv : ccc.createVirtualVerses()) {
                for (Headline h : vv.getHeadlines()) {
                    CAPTION caption = of.createCAPTION();
                    caption.setVref(BigInteger.valueOf(vv.getNumber()));
                    h.accept(new CreateContentVisitor(of, caption.getContent(), null));
                    EnumCaptionType[] types = new EnumCaptionType[] { null, EnumCaptionType.X_H_1, EnumCaptionType.X_H_2, EnumCaptionType.X_H_3, EnumCaptionType.X_H_4, EnumCaptionType.X_H_5, EnumCaptionType.X_H_6, null, null, null };
                    caption.setType(types[h.getDepth()]);
                    cc.getPROLOGOrCAPTIONOrVERS().add(caption);
                }
                VERS vers = of.createVERS();
                vers.setVnumber(BigInteger.valueOf(vv.getNumber()));
                for (Verse v : vv.getVerses()) {
                    if (!v.getNumber().equals("" + vv.getNumber())) {
                        STYLE verseNum = of.createSTYLE();
                        verseNum.setCss("font-weight: bold");
                        verseNum.getContent().add("(" + v.getNumber() + ")");
                        vers.getContent().add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, verseNum));
                        vers.getContent().add(" ");
                    }
                    v.accept(new CreateContentVisitor(of, vers.getContent(), vers));
                }
                cc.getPROLOGOrCAPTIONOrVERS().add(vers);
            }
        }
        doc.getBIBLEBOOK().add(bb);
    }
    return doc;
}
Also used : MetadataBook(biblemulticonverter.data.MetadataBook) Pattern(java.util.regex.Pattern) VirtualVerse(biblemulticonverter.data.VirtualVerse) XMLBIBLE(biblemulticonverter.schema.zef2005.XMLBIBLE) QName(javax.xml.namespace.QName) Chapter(biblemulticonverter.data.Chapter) STYLE(biblemulticonverter.schema.zef2005.STYLE) BIBLEBOOK(biblemulticonverter.schema.zef2005.BIBLEBOOK) ObjectFactory(biblemulticonverter.schema.zef2005.ObjectFactory) EnumCaptionType(biblemulticonverter.schema.zef2005.EnumCaptionType) CHAPTER(biblemulticonverter.schema.zef2005.CHAPTER) Book(biblemulticonverter.data.Book) MetadataBook(biblemulticonverter.data.MetadataBook) Headline(biblemulticonverter.data.FormattedText.Headline) VERS(biblemulticonverter.schema.zef2005.VERS) BigInteger(java.math.BigInteger) PROLOG(biblemulticonverter.schema.zef2005.PROLOG) CAPTION(biblemulticonverter.schema.zef2005.CAPTION) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Example 47 with Chapter

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

the class ZefaniaXML method parseBible.

protected Bible parseBible(XMLBIBLE doc) throws Exception {
    Bible result = new Bible(doc.getBiblename());
    MetadataBook metadata = new MetadataBook();
    if (doc.getStatus() != null) {
        metadata.setValue(MetadataBookKey.status, doc.getStatus().value());
    }
    if (doc.getVersion() != null) {
        metadata.setValue(MetadataBookKey.version, doc.getVersion());
    }
    if (doc.getRevision() != null) {
        metadata.setValue(MetadataBookKey.revision, doc.getRevision().toString());
    }
    for (JAXBElement<?> elem : doc.getINFORMATION().getTitleOrCreatorOrDescription()) {
        if (elem.getValue() == null)
            continue;
        String value = normalize(elem.getValue().toString(), true).trim();
        if (value.length() != 0)
            metadata.setValue(elem.getName().getLocalPart(), value);
    }
    metadata.finished();
    if (metadata.getKeys().size() > 0)
        result.getBooks().add(metadata.getBook());
    Set<String> abbrs = new HashSet<String>();
    Set<String> shortnames = new HashSet<String>();
    Set<String> longnames = new HashSet<String>();
    Map<BookID, String> abbrMap = new EnumMap<BookID, String>(BookID.class);
    List<BIBLEBOOK> nl = doc.getBIBLEBOOK();
    for (BIBLEBOOK e : nl) {
        String shortname = e.getBsname();
        int number = e.getBnumber().intValue();
        BookID bookID;
        try {
            bookID = BookID.fromZefId(number);
        } catch (IllegalArgumentException ex) {
            continue;
        }
        if (shortname == null || shortname.length() == 0)
            shortname = "_" + bookID.getOsisID();
        String abbr = shortname.replaceAll("[^A-Z0-9a-zäöü]++", "");
        if (abbr.length() == 0 || Character.isLowerCase(abbr.charAt(0)))
            abbr = "X" + abbr;
        if (abbr.length() == 1)
            abbr += "x";
        if (abbrs.contains(abbr)) {
            for (int i = 2; i < 100; i++) {
                if (!abbrs.contains(abbr + i)) {
                    abbr = abbr + i;
                    break;
                }
            }
        }
        abbrs.add(abbr);
        abbrMap.put(bookID, abbr);
    }
    abbrs.clear();
    EnumMap<BookID, Book> existingBooks = new EnumMap<BookID, Book>(BookID.class);
    for (BIBLEBOOK e : nl) {
        String shortname = e.getBsname();
        String longname = e.getBname();
        int number = e.getBnumber().intValue();
        BookID bookID;
        try {
            bookID = BookID.fromZefId(number);
        } catch (IllegalArgumentException ex) {
            System.out.println("WARNING: Skipping book with unknown id " + number);
            continue;
        }
        if (shortname == null || shortname.length() == 0)
            shortname = "_" + bookID.getOsisID();
        if (longname == null || longname.length() == 0)
            longname = "_" + bookID.getEnglishName();
        else
            longname = longname.replaceAll("  ++", " ").trim();
        String abbr = shortname.replaceAll("[^A-Z0-9a-zäöü]++", "");
        if (abbr.length() == 0 || Character.isLowerCase(abbr.charAt(0)))
            abbr = "X" + abbr;
        if (abbr.length() == 1)
            abbr += "x";
        if (abbrs.contains(abbr)) {
            for (int i = 2; i < 100; i++) {
                if (!abbrs.contains(abbr + i)) {
                    abbr = abbr + i;
                    break;
                }
            }
        }
        abbrs.add(abbr);
        if (shortname.equals("Gen") && longname.equals("Genesis") && bookID == BookID.BOOK_Exod) {
            System.out.println("WARNING: Book number " + bookID.getZefID() + " has name " + longname);
            shortname = "Exo";
            longname = "Exodus";
        }
        if (shortname.equals("1Chr") && longname.equals("2 Chronicles")) {
            System.out.println("WARNING: Book name 2 Chronicles has short name 1Chr");
            shortname = "2Chr";
        }
        if (shortnames.contains(shortname)) {
            System.out.println("WARNING: Duplicate short name " + shortname);
            for (int i = 2; i < 100; i++) {
                if (!shortnames.contains(shortname + i)) {
                    shortname = shortname + i;
                    break;
                }
            }
        }
        shortnames.add(shortname);
        if (longnames.contains(longname)) {
            System.out.println("WARNING: Duplicate long name " + shortname);
            for (int i = 2; i < 100; i++) {
                if (!longnames.contains(longname + i)) {
                    longname = longname + i;
                    break;
                }
            }
        }
        longnames.add(longname);
        Book book = existingBooks.get(bookID);
        if (book == null) {
            book = new Book(abbr, bookID, shortname, longname);
            existingBooks.put(bookID, book);
            result.getBooks().add(book);
        }
        List<Headline> headlineBuffer = new ArrayList<Headline>();
        for (CHAPTER e2 : e.getCHAPTER()) {
            int chapterNumber = e2.getCnumber().intValue();
            while (book.getChapters().size() < chapterNumber) book.getChapters().add(new Chapter());
            Chapter chapter = book.getChapters().get(chapterNumber - 1);
            int existingVerses = chapter.getVerses().size();
            for (Object e3 : e2.getPROLOGOrCAPTIONOrVERS()) {
                if (e3 instanceof CAPTION) {
                    CAPTION caption = (CAPTION) e3;
                    int depth;
                    if (caption.getType() == null) {
                        depth = 9;
                    } else {
                        switch(caption.getType()) {
                            case X_H_1:
                                depth = 1;
                                break;
                            case X_H_2:
                                depth = 2;
                                break;
                            case X_H_3:
                                depth = 3;
                                break;
                            case X_H_4:
                                depth = 4;
                                break;
                            case X_H_5:
                                depth = 5;
                                break;
                            case X_H_6:
                                depth = 6;
                                break;
                            default:
                                depth = 9;
                                break;
                        }
                    }
                    int lastDepth = headlineBuffer.size() == 0 ? -1 : headlineBuffer.get(headlineBuffer.size() - 1).getDepth();
                    if (depth <= lastDepth)
                        depth = lastDepth == 9 ? 9 : lastDepth + 1;
                    Headline h = new Headline(depth);
                    if (parseContent(h.getAppendVisitor(), caption.getContent(), abbrMap)) {
                        h.trimWhitespace();
                        h.finished();
                        headlineBuffer.add(h);
                    }
                } else if (e3 instanceof REMARK) {
                    REMARK remark = (REMARK) e3;
                    int vref = remark.getVref().intValue();
                    int idx = chapter.getVerseIndex("" + vref);
                    if (idx == -1)
                        continue;
                    Verse v = chapter.getVerses().get(idx);
                    if (remark.getContent().size() != 1)
                        continue;
                    String remarkText = normalize((String) remark.getContent().get(0), true).trim();
                    v.getAppendVisitor().visitFootnote().visitText(remarkText);
                } else if (e3 instanceof XREF) {
                    XREF xref = (XREF) e3;
                    int vref = xref.getVref().intValue();
                    int idx = chapter.getVerseIndex("" + vref);
                    if (idx == -1)
                        continue;
                    Verse v = chapter.getVerses().get(idx);
                    Visitor<RuntimeException> footnoteVisitor = v.getAppendVisitor().visitFootnote();
                    boolean first = true;
                    for (String mscope : xref.getMscope().split(" ")) {
                        Matcher m = Utils.compilePattern("([0-9]+);([0-9]+)(-[0-9]+)?;([0-9]+)(-[0-9]+)?").matcher(mscope);
                        if (!m.matches())
                            continue;
                        BookID xrefBookID = BookID.fromZefId(Integer.parseInt(m.group(1)));
                        int xrefChapter = Integer.parseInt(m.group(2)), endChapter = xrefChapter;
                        if (m.group(3) != null)
                            endChapter = Integer.parseInt(m.group(3).substring(1));
                        String verse = m.group(4);
                        String endVerse = m.group(5);
                        if (endVerse == null)
                            endVerse = verse;
                        else
                            endVerse = endVerse.substring(1);
                        if (verse.equals("0") || endVerse.equals("0"))
                            continue;
                        if (xrefChapter == endChapter && Integer.parseInt(verse) > Integer.parseInt(endVerse))
                            continue;
                        String xrefAbbr = abbrMap.get(xrefBookID);
                        if (xrefAbbr == null)
                            xrefAbbr = xrefBookID.getOsisID();
                        if (first)
                            first = false;
                        else
                            footnoteVisitor.visitText(" ");
                        footnoteVisitor.visitCrossReference(xrefAbbr, xrefBookID, xrefChapter, verse, endChapter, endVerse).visitText(xrefAbbr + " " + xrefChapter + ":" + verse);
                    }
                    if (first)
                        visitEmptyMarker(footnoteVisitor);
                } else if (e3 instanceof PROLOG) {
                    PROLOG prolog = (PROLOG) e3;
                    if (chapter.getProlog() != null)
                        continue;
                    FormattedText prologText = new FormattedText();
                    if (parseContent(prologText.getAppendVisitor(), prolog.getContent(), abbrMap)) {
                        prologText.trimWhitespace();
                        prologText.finished();
                        chapter.setProlog(prologText);
                    }
                } else if (e3 instanceof VERS) {
                    VERS vers = (VERS) e3;
                    int vnumber = vers.getVnumber() == null ? 0 : vers.getVnumber().intValue();
                    if (vnumber == 0)
                        vnumber = chapter.getVerses().size() + 1;
                    String verseNumber = vnumber + (vers.getAix() == null ? "" : vers.getAix());
                    String infix = "";
                    while (chapter.getVerseIndex(verseNumber) != -1) {
                        for (char ch = 'a'; ch <= 'z'; ch++) {
                            if (chapter.getVerseIndex(vnumber + infix + ch) == -1) {
                                verseNumber = vnumber + infix + ch;
                                break;
                            }
                        }
                        infix += "-";
                    }
                    Verse verse = new Verse(verseNumber);
                    Visitor<RuntimeException> visitor = verse.getAppendVisitor();
                    boolean contentFound = false;
                    if (headlineBuffer.size() > 0) {
                        for (Headline h : headlineBuffer) {
                            h.accept(visitor.visitHeadline(h.getDepth()));
                        }
                        headlineBuffer.clear();
                        contentFound = true;
                    }
                    contentFound |= parseContent(visitor, vers.getContent(), abbrMap);
                    if (contentFound) {
                        verse.trimWhitespace();
                        chapter.getVerses().add(verse);
                    }
                }
            }
            for (Verse v : chapter.getVerses()) {
                if (existingVerses > 0) {
                    existingVerses--;
                    continue;
                }
                v.finished();
            }
        }
    }
    return result;
}
Also used : Matcher(java.util.regex.Matcher) Bible(biblemulticonverter.data.Bible) ArrayList(java.util.ArrayList) BookID(biblemulticonverter.data.BookID) Book(biblemulticonverter.data.Book) MetadataBook(biblemulticonverter.data.MetadataBook) Headline(biblemulticonverter.data.FormattedText.Headline) VERS(biblemulticonverter.schema.zef2005.VERS) PROLOG(biblemulticonverter.schema.zef2005.PROLOG) EnumMap(java.util.EnumMap) REMARK(biblemulticonverter.schema.zef2005.REMARK) HashSet(java.util.HashSet) MetadataBook(biblemulticonverter.data.MetadataBook) Chapter(biblemulticonverter.data.Chapter) FormattedText(biblemulticonverter.data.FormattedText) BIBLEBOOK(biblemulticonverter.schema.zef2005.BIBLEBOOK) XREF(biblemulticonverter.schema.zef2005.XREF) CHAPTER(biblemulticonverter.schema.zef2005.CHAPTER) CAPTION(biblemulticonverter.schema.zef2005.CAPTION) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Example 48 with Chapter

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

the class BibleAnalyzerFormattedText method exportBible.

protected final void exportBible(String basename, Writer w, Bible bible, boolean hasStrongs, boolean hasRMAC) throws Exception {
    for (Book book : bible.getBooks()) {
        if (book.getId() == BookID.DICTIONARY_ENTRY) {
            Writer dw = startDictionaryEntry(basename, book, w);
            book.getChapters().get(0).getProlog().accept(new BibleAnalyzerVisitor(dw));
            finishDictionaryEntry(dw);
            continue;
        }
        BibleAnalyzerBookInfo info = BOOK_INFO_BY_ID.get(book.getId());
        if (info == null) {
            System.out.println("WARNING: Skipping book " + book.getAbbr());
            continue;
        }
        List<Chapter> chapters = book.getChapters();
        if (chapters.size() > info.chapterCount) {
            System.out.println("WARNING: Merging chapter " + info.chapterCount + " to " + chapters.size() + " into " + book.getAbbr() + " " + info.chapterCount);
            chapters = new ArrayList<>(chapters.subList(0, info.chapterCount + 1));
            Chapter targetChapter = chapters.get(info.chapterCount - 1);
            for (int cn = info.chapterCount + 1; cn <= book.getChapters().size(); cn++) {
                Chapter sourceChapter = book.getChapters().get(cn - 1);
                if (sourceChapter.getProlog() != null)
                    System.out.println("WARNING: Prolog for " + book.getAbbr() + " " + cn + " is lost");
                for (Verse v : sourceChapter.getVerses()) {
                    String vn = v.getNumber();
                    if (!vn.contains(","))
                        vn = cn + "," + vn;
                    Verse vv = new Verse(vn);
                    v.accept(vv.getAppendVisitor());
                    vv.finished();
                    targetChapter.getVerses().add(vv);
                }
            }
        }
        int cnumber = 0;
        for (Chapter chapter : chapters) {
            cnumber++;
            int[] nextFootnote = { 1 };
            handleProlog(info.abbr, cnumber, chapter.getProlog());
            for (VirtualVerse vv : chapter.createVirtualVerses()) {
                Writer[] vw = startVerse(w, info.abbr, cnumber, vv);
                for (Verse v : vv.getVerses()) {
                    if (!v.getNumber().equals("" + vv.getNumber())) {
                        vw[0].append(" <b>(" + v.getNumber() + ")</b> ");
                    }
                    v.accept(new BibleAnalyzerVisitor(vw[0], vw[1], nextFootnote, book.getId().isNT(), "", hasStrongs, hasRMAC));
                }
                finishVerse(vw);
            }
            finishChapter();
        }
    }
}
Also used : VirtualVerse(biblemulticonverter.data.VirtualVerse) Chapter(biblemulticonverter.data.Chapter) Book(biblemulticonverter.data.Book) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Example 49 with Chapter

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

the class BrowserBible method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    File directory = new File(exportArgs[0]);
    if (!directory.exists())
        directory.mkdirs();
    try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(directory, "info.json")), StandardCharsets.UTF_8))) {
        bw.write("{\n" + " \"name\": \"" + bible.getName().replace("\\", "\\\\").replace("\"", "\\\"") + "\",\n" + " \"nameEnglish\": \"\",\n" + " \"langName\": \"Deutsch\",\n" + " \"langNameEnglish\": \"German\",\n" + " \"abbr\": \"XXX\",\n" + " \"id\": \"deu_xxx\",\n" + " \"lang\": \"deu\",\n" + " \"generator\": \"biblemulticonverter\",\n" + " \"dir\": \"ltr\"\n" + "}");
    }
    try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(directory, "biblemulticonverter.js")), StandardCharsets.UTF_8))) {
        Reader r = new InputStreamReader(RoundtripHTML.class.getResourceAsStream("/BrowserBible/biblemulticonverter.js"), StandardCharsets.UTF_8);
        char[] buf = new char[4096];
        int len;
        while ((len = r.read(buf)) != -1) {
            bw.write(buf, 0, len);
        }
    }
    try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(directory, "verses.txt")), StandardCharsets.UTF_8))) {
        for (Book book : bible.getBooks()) {
            String bookAbbr = BOOK_NAMES.get(book.getId());
            if (bookAbbr == null) {
                System.out.println("WARNING: Skipping book " + book.getAbbr());
                continue;
            }
            int cnumber = 0;
            String bookHeading = "<div class=\"mt\">" + book.getLongName() + "</div>";
            for (Chapter chapter : book.getChapters()) {
                int[] nextFootnote = new int[] { 1 };
                cnumber++;
                if (chapter.getProlog() != null) {
                    bw.write(bookAbbr + "\t" + book.getShortName() + "\t" + cnumber + "\t\t" + bookHeading + "\t");
                    bookHeading = "";
                    StringWriter fnw = new StringWriter();
                    chapter.getProlog().accept(new BrowserBibleVisitor(bw, fnw, nextFootnote, book.getId().isNT(), ""));
                    bw.write("\t" + fnw.toString() + "\n");
                }
                for (VirtualVerse vv : chapter.createVirtualVerses()) {
                    String vnumber = "" + vv.getNumber();
                    boolean autoNumber = vnumber.equals(vv.getVerses().get(0).getNumber());
                    if (!autoNumber)
                        vnumber = "!" + vnumber;
                    bw.write(bookAbbr + "\t" + book.getShortName() + "\t" + cnumber + "\t" + vnumber + "\t" + bookHeading);
                    bookHeading = "";
                    StringWriter fnw = new StringWriter();
                    BrowserBibleVisitor bbv = new BrowserBibleVisitor(bw, fnw, nextFootnote, book.getId().isNT(), "");
                    for (Headline hl : vv.getHeadlines()) {
                        hl.accept(bbv.visitHeadline(hl.getDepth()));
                    }
                    bw.write("\t");
                    for (Verse v : vv.getVerses()) {
                        if (!autoNumber) {
                            bw.write("<span class=\"verse-num\">" + v.getNumber() + "&nbsp;</span>");
                        }
                        autoNumber = false;
                        bbv.nextVerse();
                        v.accept(bbv);
                    }
                    bbv.visitEnd();
                    bw.write("\t" + fnw.toString() + "\n");
                }
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) VirtualVerse(biblemulticonverter.data.VirtualVerse) Chapter(biblemulticonverter.data.Chapter) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) 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 50 with Chapter

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

the class Compact 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() + "\t" + book.getId().getOsisID() + "\t" + book.getShortName() + "\t" + book.getLongName() + "\n");
        boolean firstChapter = true;
        int verseNum;
        for (Chapter ch : book.getChapters()) {
            if (firstChapter)
                firstChapter = false;
            else
                w.write('+');
            if (ch.getProlog() != null) {
                w.write("0 ");
                ch.getProlog().accept(new CompactVisitor(w, false));
                w.write('\n');
            }
            verseNum = 1;
            for (Verse v : ch.getVerses()) {
                if (v.getNumber().equals("" + verseNum)) {
                    StringWriter sw = new StringWriter();
                    v.accept(new CompactVisitor(sw, false));
                    String s = sw.toString();
                    if (!s.matches("[A-Za-z].*"))
                        w.write(' ');
                    w.write(s);
                } else {
                    w.write(v.getNumber() + " ");
                    v.accept(new CompactVisitor(w, false));
                    Matcher m = Utils.compilePattern("([0-9]+).*").matcher(v.getNumber());
                    if (!m.matches()) {
                        throw new IllegalStateException();
                    }
                    verseNum = Integer.parseInt(m.group(1));
                }
                verseNum++;
                w.write('\n');
            }
        }
    }
}
Also used : StringWriter(java.io.StringWriter) Matcher(java.util.regex.Matcher) Book(biblemulticonverter.data.Book) Chapter(biblemulticonverter.data.Chapter) Verse(biblemulticonverter.data.Verse)

Aggregations

Chapter (biblemulticonverter.data.Chapter)64 Book (biblemulticonverter.data.Book)60 Verse (biblemulticonverter.data.Verse)57 FormattedText (biblemulticonverter.data.FormattedText)28 VirtualVerse (biblemulticonverter.data.VirtualVerse)25 MetadataBook (biblemulticonverter.data.MetadataBook)22 BookID (biblemulticonverter.data.BookID)20 ArrayList (java.util.ArrayList)20 Bible (biblemulticonverter.data.Bible)19 Headline (biblemulticonverter.data.FormattedText.Headline)19 File (java.io.File)18 BufferedWriter (java.io.BufferedWriter)15 IOException (java.io.IOException)14 FileOutputStream (java.io.FileOutputStream)13 OutputStreamWriter (java.io.OutputStreamWriter)12 EnumMap (java.util.EnumMap)9 HashMap (java.util.HashMap)9 Visitor (biblemulticonverter.data.FormattedText.Visitor)8 BufferedReader (java.io.BufferedReader)8 FileInputStream (java.io.FileInputStream)8