use of biblemulticonverter.tools.MobiPocketBXR in project BibleMultiConverter by schierlm.
the class MobiPocket method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
footNotes.setLength(0);
crossRefs.setLength(0);
footNoteCount = 0;
chapref = "";
File exportFile = new File(exportArgs[0]);
String title = bible.getName();
File directory = exportFile.getParentFile();
String filename = exportFile.getName();
try (final BufferedWriter opfw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(directory, filename + ".opf")), "UTF-8"))) {
opfw.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<package unique-identifier=\"uid\">\r\n" + " <metadata>\r\n" + " <dc-metadata xmlns:dc=\"http://purl.org/metadata/dublin_core\" xmlns:oebpackage=\"http://openebook.org/namespaces/oeb-package/1.0/\">\r\n" + " <dc:Title>" + TITLEPREFIX + title + "</dc:Title>\r\n" + " <dc:Language>" + LANGUAGE + "</dc:Language>\r\n" + " </dc-metadata>\r\n" + " <x-metadata>\r\n" + " <DatabaseName>Bible" + filename + "</DatabaseName>\r\n" + " <output encoding=\"Windows-1252\"></output>\r\n" + " </x-metadata>\r\n" + " </metadata>\r\n" + " <manifest>\r\n" + " <item id=\"onlyfile\" media-type=\"text/x-oeb1-document\" href=\"" + filename + ".html\"></item>\r\n" + " </manifest>\r\n" + " <spine>\r\n" + " <itemref idref=\"onlyfile\" />\r\n" + " </spine>\r\n" + " <tours></tours>\r\n" + " <guide></guide>\r\n" + "</package>\r\n" + "");
}
boolean isDictionary = false;
for (Book bk : bible.getBooks()) {
if (bk.getId() == BookID.DICTIONARY_ENTRY) {
isDictionary = true;
break;
} else if (bk.getId().getZefID() > 0) {
isDictionary = false;
break;
}
}
try (final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(directory, filename + ".html")), "UTF-8"))) {
bw.write("<html><head>");
bw.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
bw.write("<style type=\"text/css\">body {font-family: Verdana, Arial, Helvetica, sans-serif}</style>");
bw.write("<title>" + TITLEPREFIX + title + "</title></head><body>");
bw.newLine();
bw.write("<h1>" + title + "</h1>");
if (isDictionary) {
bw.write("<a onclick=\"index_search()\">Suchen</a><br>");
}
bw.write("<h2>" + TOC + "</h2>");
bw.newLine();
List<String> books = new ArrayList<String>();
Map<String, Integer> maxChapter = new HashMap<String, Integer>();
Map<String, BookID> bookIDs = new HashMap<String, BookID>();
for (Book bk : bible.getBooks()) {
books.add(bk.getAbbr());
if (isDictionary) {
bw.write("<p><a href=\"#" + bk.getAbbr() + "\">" + bk.getLongName() + "</a></p>");
} else {
bw.write("<p><a href=\"#b" + bookRef(bk) + "\">" + bk.getLongName() + " (" + bk.getAbbr() + ")</a></p>");
}
bw.newLine();
maxChapter.put(bk.getAbbr(), bk.getChapters().size());
bookIDs.put(bk.getAbbr(), bk.getId());
}
try (final BufferedWriter bxw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(directory, filename + ".bxr")), "UTF-8"))) {
bxw.write(title);
bxw.newLine();
for (String bk : books) {
bxw.write(bk + "|" + bookRef(bk, bookIDs.get(bk)) + "|" + maxChapter.get(bk));
bxw.newLine();
}
}
bxrs.add(new MobiPocketBXR(filename, new File(directory, filename + ".bxr")));
final String lexiconName = (isDictionary ? "Bible" : "BibleDict") + filename;
for (Book bk : bible.getBooks()) {
if (bk.getId() == BookID.DICTIONARY_ENTRY) {
bw.write("<mbp:pagebreak><idx:entry>");
bw.newLine();
bw.write("<h2><a name=\"" + bk.getAbbr() + "\" external=\"yes\"><idx:orth>" + bk.getLongName() + "</idx:orth></a></h2>");
bw.newLine();
bw.write("<p>");
bw.newLine();
writeVerse(bw, bk.getChapters().get(0).getProlog(), bible, "", lexiconName);
bw.write("</p>");
bw.newLine();
writeFootNotes(bw);
bw.write("</idx:entry>");
} else {
bw.write("<mbp:pagebreak>");
bw.newLine();
chapref = "b" + bookRef(bk);
bw.write("<h2><a name=\"" + chapref + "\" external=\"yes\">" + bk.getLongName() + " (" + bk.getAbbr() + ")</a> (<a href=\"oeb:redirect?title=BibleNavigation#" + chapref + "\">Navigation</a>)</h2>");
bw.newLine();
int chapter = 0;
for (Chapter ch : bk.getChapters()) {
chapter++;
chapref = "b" + bookRef(bk) + "c" + chapter;
bw.write("<h3><a name=\"" + chapref + "\" external=\"yes\">" + bk.getAbbr() + " " + chapter + "</a> (<a href=\"oeb:redirect?title=BibleNavigation#" + chapref + "\">Navigation</a>)</h3>");
bw.newLine();
if (ch.getProlog() != null) {
bw.write("<small>");
bw.newLine();
writeVerse(bw, ch.getProlog(), bible, "", lexiconName);
bw.write("</small>");
bw.newLine();
}
for (final Verse v : ch.getVerses()) {
writeVerse(bw, v, bible, "<b>" + v.getNumber() + "</b> ", lexiconName);
}
writeFootNotes(bw);
}
}
}
}
}
Aggregations