use of biblemulticonverter.logos.tools.LogosVersificationDetector in project BibleMultiConverter by schierlm.
the class LogosRenumberedDiffable method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
String outputFile = exportArgs[0];
VersificationScheme scheme = null;
if (exportArgs.length == 2) {
if (!exportArgs[1].matches("Bible[A-Z0-9]*")) {
System.out.println("Invalid versification: " + exportArgs[1]);
return;
}
scheme = new LogosVersificationDetector().loadScheme(exportArgs[1]);
if (scheme == null) {
System.out.println("Invalid versification: " + exportArgs[1]);
return;
}
}
for (Book book : bible.getBooks()) {
int cnumber = 0;
for (Chapter chap : book.getChapters()) {
cnumber++;
if (chap.getProlog() != null) {
FormattedText newProlog = new FormattedText();
chap.getProlog().accept(new MapXrefVisitor(newProlog.getAppendVisitor(), scheme));
newProlog.finished();
chap.setProlog(newProlog);
}
for (int j = 0; j < chap.getVerses().size(); j++) {
Verse v = chap.getVerses().get(j);
Verse nv = new Verse(mapVerse(book.getAbbr(), book.getId(), cnumber, v.getNumber(), scheme, ""));
v.accept(new MapXrefVisitor(nv.getAppendVisitor(), scheme));
nv.finished();
chap.getVerses().set(j, nv);
}
}
}
new Diffable().doExport(bible, new String[] { outputFile });
}
use of biblemulticonverter.logos.tools.LogosVersificationDetector in project BibleMultiConverter by schierlm.
the class LogosHTML method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
String versemap = exportArgs.length == 1 ? "Bible" : exportArgs[1];
Properties bookDatatypeMap = null;
VersificationScheme scheme;
if (versemap.startsWith("author:")) {
bookDatatypeMap = new Properties();
try (InputStream in = new FileInputStream(versemap.substring(7))) {
bookDatatypeMap.load(in);
}
versemap = null;
scheme = new LogosVersificationDetector().loadScheme("Bible");
} else {
if (!versemap.matches("Bible[A-Z0-9]*")) {
System.out.println("Invalid versification: " + versemap);
return;
}
scheme = new LogosVersificationDetector().loadScheme(versemap);
if (scheme == null) {
System.out.println("Invalid versification: " + versemap);
return;
}
}
footnoteCounter = 0;
grammarCounter = 0;
String title = bible.getName();
String verseSeparator = "<br />";
lineSeparator = "<br />";
boolean noChapterHeadings = false;
if (exportArgs.length > 3 && exportArgs[3].equals("-inline")) {
verseSeparator = " ";
lineSeparator = "<br /> ";
} else if (exportArgs.length > 3 && exportArgs[3].equals("-nochapter")) {
verseSeparator = " ";
lineSeparator = "<br /> ";
noChapterHeadings = true;
}
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(exportArgs[0])), StandardCharsets.UTF_8))) {
bw.write("<html><head>\n" + "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\n" + "<style>" + "body, h1, h2, h3, h4, h5, h6 { font-family: \"Times New Roman\";}\n" + "a { color: black; text-decoration: none;}\n" + "a.sdfootnotesym, a.sdendnotesym { font-style: italic;}\n" + "h1 {font-size: 24pt;}\n" + "h2 {font-size: 22pt;}\n" + "h3 {font-size: 20pt;}\n" + "h4 {font-size: 18pt;}\n" + "h5 {font-size: 16pt;}\n" + "h6 {font-size: 14pt;}\n" + "</style>\n" + "</head><body lang=\"de-DE\">\n");
if (exportArgs.length > 2 && !exportArgs[2].equals("-")) {
StringWriter sw = new StringWriter();
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(exportArgs[2]), StandardCharsets.UTF_8))) {
char[] buffer = new char[4096];
int len;
while ((len = br.read(buffer)) != -1) sw.write(buffer, 0, len);
}
String template = sw.toString();
template = template.replace("${name}", bible.getName());
MetadataBook mb = bible.getMetadataBook();
if (mb != null) {
bible.getBooks().remove(0);
for (String key : mb.getKeys()) template = template.replace("${" + key + "}", mb.getValue(key));
}
bw.write(template);
} else {
bw.write("<h1>" + title.replace("&", "&").replace("<", "<").replace(">", ">") + "</h1>\n");
}
StringWriter footnotes = new StringWriter();
for (Book book : bible.getBooks()) {
BitSet[] chapterVerses;
String milestone;
if (bookDatatypeMap != null) {
milestone = bookDatatypeMap.getProperty(book.getId().getOsisID());
chapterVerses = milestone == null ? null : ALL_CHAPTER_VERSES;
} else {
chapterVerses = scheme.getCoveredBooks().get(book.getId());
String babbr = LOGOS_BOOKS.get(book.getId());
milestone = babbr == null ? null : (versemap + ":" + babbr + " %c:%v");
}
if (milestone == null && book.getId().getZefID() < 0 && book.getChapters().size() == 1) {
Chapter chapter = book.getChapters().get(0);
if (chapter.getVerses().size() == 0 && chapter.getProlog() != null) {
// prolog only book
bw.write("<h2>");
if (book.getId() == BookID.DICTIONARY_ENTRY) {
if (bible.getName().toUpperCase().contains("STRONG") && book.getShortName().matches("[GH][1-9][0-9]*")) {
bw.write("[[@" + (book.getShortName().startsWith("G") ? "Greek" : "Hebrew") + "Strongs:" + book.getShortName() + "]]");
} else {
bw.write("[[@Headword:" + book.getAbbr() + "]]");
if (!book.getAbbr().equals(book.getShortName())) {
bw.write("[[@Headword:" + book.getShortName() + "]]");
}
if (!book.getLongName().equals(book.getShortName())) {
bw.write("[[@Headword:" + book.getLongName() + "]]");
}
}
}
bw.write(book.getLongName() + "</h2>\n");
footnoteNumber = 0;
chapter.getProlog().accept(new LogosVisitor(bw, "", footnotes, false, versemap, scheme, null, null, null, 2));
bw.write("\n<br/>\n");
continue;
}
}
if (milestone == null) {
System.out.println("WARNING: Skipping book " + book.getId());
continue;
}
bw.write("<h2>[[@" + formatMilestone(milestone, "", "") + "]]" + book.getLongName() + " (" + book.getAbbr() + ")</h2>\n");
int cnumber = 0;
for (Chapter chapter : book.getChapters()) {
cnumber++;
if (!chapter.getVerses().isEmpty() && chapter.getVerses().get(0).getNumber().endsWith(".p")) {
Chapter prologue = new Chapter();
BitSet prologueVerses = new BitSet(100);
prologueVerses.set(1, 100);
while (!chapter.getVerses().isEmpty() && chapter.getVerses().get(0).getNumber().endsWith(".p")) {
Verse v = chapter.getVerses().remove(0);
Verse vv = new Verse(v.getNumber().replace(".p", ""));
v.accept(vv.getAppendVisitor());
vv.finished();
prologue.getVerses().add(vv);
}
exportChapter(milestone, "Prologue", prologue, versemap, scheme, verseSeparator, noChapterHeadings, bw, footnotes, book, chapterVerses, prologueVerses);
}
BitSet thisChapterVerses = chapterVerses != null && cnumber <= chapterVerses.length ? chapterVerses[cnumber - 1] : null;
exportChapter(milestone, "" + cnumber, chapter, versemap, scheme, verseSeparator, noChapterHeadings, bw, footnotes, book, chapterVerses, thisChapterVerses);
}
}
bw.write(footnotes.toString());
bw.write("</body></html>");
}
}
Aggregations