use of biblemulticonverter.data.Chapter 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());
}
}
use of biblemulticonverter.data.Chapter 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() + " "));
}
}
}
}
use of biblemulticonverter.data.Chapter 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\"> " + 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>");
}
}
use of biblemulticonverter.data.Chapter 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>");
}
use of biblemulticonverter.data.Chapter in project BibleMultiConverter by schierlm.
the class SWORD method doImport.
protected Bible doImport(Book book) throws Exception {
OSISHelper helper = new OSISHelper();
Bible result = new Bible(book.getName());
TransformerHandler th = ((SAXTransformerFactory) SAXTransformerFactory.newInstance()).newTransformerHandler();
Map<BookID, biblemulticonverter.data.Book> parsedBooks = new EnumMap<>(BookID.class);
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
List<Verse> allVerses = new ArrayList<>();
Verse nextCandidate = null;
for (Iterator<?> iter = book.getGlobalKeyList().iterator(); iter.hasNext(); ) {
Verse v = (Verse) iter.next();
while (nextCandidate != null && !nextCandidate.equals(v)) {
if (book.contains(nextCandidate)) {
System.out.println("WARNING: Verse (after) skipped by iterator: " + nextCandidate);
allVerses.add(nextCandidate);
}
nextCandidate = nextCandidate.getVersification().add(nextCandidate, 1);
}
Verse prevCandidate = v.getVersification().subtract(v, 1);
List<Verse> versesSkippedBefore = new ArrayList<>();
while (prevCandidate != null && !allVerses.contains(prevCandidate) && !versesSkippedBefore.contains(prevCandidate)) {
versesSkippedBefore.add(0, prevCandidate);
prevCandidate = prevCandidate.getVersification().subtract(prevCandidate, 1);
}
for (Verse vv : versesSkippedBefore) {
if (book.contains(vv)) {
System.out.println("WARNING: Verse (before) skipped by iterator: " + vv);
allVerses.add(vv);
}
}
allVerses.add(v);
nextCandidate = v.getVersification().add(v, 1);
}
while (nextCandidate != null) {
if (book.contains(nextCandidate)) {
System.out.println("WARNING: Verse (at end) skipped by iterator: " + nextCandidate);
allVerses.add(nextCandidate);
}
Verse nextNextCandidate = nextCandidate.getVersification().add(nextCandidate, 1);
if (nextCandidate.equals(nextNextCandidate))
break;
nextCandidate = nextNextCandidate;
}
for (Verse v : allVerses) {
BookID bkid = biblemulticonverter.sword.BookMapping.MAPPING.get(v.getBook());
biblemulticonverter.data.Book bk = parsedBooks.get(bkid);
if (!parsedBooks.containsKey(bkid)) {
bk = new biblemulticonverter.data.Book(bkid.getOsisID().replace("x-Intr", "Intr"), bkid, bkid.getEnglishName(), bkid.getEnglishName());
parsedBooks.put(bkid, bk);
bk.getChapters().add(new Chapter());
result.getBooks().add(bk);
}
int chapterNum = v.getChapter(), verseNum = v.getVerse();
while (bk.getChapters().size() < chapterNum) bk.getChapters().add(new Chapter());
Chapter chapter = bk.getChapters().get(chapterNum == 0 ? 0 : chapterNum - 1);
FormattedText verse;
if (verseNum == 0) {
verse = new FormattedText();
if (chapter.getProlog() != null) {
chapter.getProlog().accept(verse.getAppendVisitor());
}
chapter.setProlog(verse);
} else {
if (chapterNum == 0)
throw new IllegalStateException("Verse " + verseNum + " in chapter 0 is invalid");
verse = new biblemulticonverter.data.Verse("" + verseNum);
chapter.getVerses().add((biblemulticonverter.data.Verse) verse);
}
Element root = doc.createElement("verse");
th.setResult(new DOMResult(root));
new BookData(book, v).getSAXEventProvider().provideSAXEvents(th);
if (root.getChildNodes().getLength() == 1 && root.getFirstChild() instanceof Element && root.getFirstChild().getNodeName().equals("div") && root.getFirstChild().getChildNodes().getLength() >= 1 && root.getFirstChild().getFirstChild().getNodeName().equals("title")) {
Element div = (Element) root.getFirstChild();
root.removeChild(div);
div.removeChild(div.getFirstChild());
while (div.getFirstChild() != null) {
Node child = div.getFirstChild();
div.removeChild(child);
root.appendChild(child);
}
} else {
throw new RuntimeException("Unexpected OSIS structure!");
}
helper.handleVerse(root, verse);
if (verse.getElementTypes(1).length() == 0) {
System.out.println("WARNING: Empty verse " + bk.getAbbr() + " " + chapterNum + ":" + verseNum);
if (verse instanceof biblemulticonverter.data.Verse)
chapter.getVerses().remove(verse);
else
chapter.setProlog(null);
}
}
for (biblemulticonverter.data.Book bk : parsedBooks.values()) {
while (!bk.getChapters().isEmpty()) {
Chapter ch = bk.getChapters().get(bk.getChapters().size() - 1);
if (ch.getProlog() == null && ch.getVerses().isEmpty()) {
bk.getChapters().remove(ch);
} else {
break;
}
}
if (bk.getChapters().isEmpty()) {
result.getBooks().remove(bk);
}
}
return result;
}
Aggregations