use of biblemulticonverter.data.MetadataBook in project BibleMultiConverter by schierlm.
the class SimpleJSON method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportArgs[0]), StandardCharsets.UTF_8))) {
SimpleJSONVisitor sjv = new SimpleJSONVisitor(bw);
bw.write("\t{\"osis\": [{\"osisText\": [{\"osisRefWork\": {\"_value\": \"" + json(bible.getName()) + "\"}," + "\t\t\"header\": [{\"work\": [{");
MetadataBook mdbk = bible.getMetadataBook();
for (MetadataBookKey key : Arrays.asList(MetadataBookKey.title, MetadataBookKey.creator, MetadataBookKey.contributors, MetadataBookKey.identifier, MetadataBookKey.subject, MetadataBookKey.date, MetadataBookKey.description, MetadataBookKey.publisher, MetadataBookKey.type, MetadataBookKey.source, MetadataBookKey.language, MetadataBookKey.coverage, MetadataBookKey.rights)) {
if (key != MetadataBookKey.title)
bw.write(',');
String value = mdbk == null ? null : mdbk.getValue(key);
bw.write("\"" + key.toString() + "\": [{\"_text\": \"" + json(value == null ? "" : value) + "\"}]");
}
bw.write("}]}],\t\"div\": [");
boolean first = true;
for (Book bk : bible.getBooks()) {
if (bk.getChapters().isEmpty() || bk.getChapters().get(0).getVerses().isEmpty()) {
System.out.println("WARNING: Skipping empty book " + bk.getAbbr());
continue;
}
if (!first)
bw.write(',');
bw.write("\t{\"name\": {\"_value\": \"" + json(bk.getLongName()) + "\"},\"osisID\": {\"_value\": \"" + json(bk.getId().getOsisID()) + "\"},\"chapter\": [");
first = true;
for (int ch = 1; ch <= bk.getChapters().size(); ch++) {
if (!first)
bw.write(',');
Chapter cc = bk.getChapters().get(ch - 1);
bw.write("\t{\"cnumber\":" + ch + ",\n\"verse\": [");
first = true;
for (VirtualVerse vv : cc.createVirtualVerses()) {
if (!first)
bw.write(',');
bw.write("\t{\"osisID\": {\"_value\": \"" + json(bk.getId().getOsisID() + "." + ch + "." + vv.getNumber()) + "\"},\"vnumber\":" + vv.getNumber() + ",\"_text\": \"");
for (Verse v : vv.getVerses()) {
if (!v.getNumber().equals("" + vv.getNumber())) {
bw.write(" (" + v.getNumber() + ") ");
}
v.accept(sjv);
}
bw.write("\"}");
first = false;
}
bw.write("]}");
first = false;
}
bw.write("]}");
first = false;
}
bw.write("]}]}]}\n");
}
}
use of biblemulticonverter.data.MetadataBook in project BibleMultiConverter by schierlm.
the class YCHPalmBible method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
String filename = exportArgs[0];
String description = bible.getName();
MetadataBook metadata = bible.getMetadataBook();
if (metadata != null) {
String metaDescription = bible.getMetadataBook().getValue(MetadataBookKey.description);
if (metaDescription != null)
description = metaDescription;
}
try (final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "windows-1252"))) {
bw.write("<PARSERINFO ENCODE=\"Cp1252\" WORDTYPE=\"SPCSEP\">");
bw.newLine();
bw.write("<BIBLE NAME=\"" + bible.getName() + "\" INFO=\"" + description + "\">");
bw.newLine();
Visitor<IOException> contentVisitor = new FormattedText.VisitorAdapter<IOException>(null) {
@Override
public void visitVerseSeparator() throws IOException {
// strip
}
@Override
public void visitText(String text) throws IOException {
bw.write(text);
}
@Override
public Visitor<IOException> visitFormattingInstruction(FormattingInstructionKind kind) throws IOException {
return this;
}
@Override
public Visitor<IOException> visitCSSFormatting(String css) throws IOException {
return this;
}
@Override
public void visitLineBreak(LineBreakKind kind) throws IOException {
bw.write(" ");
}
};
for (Book bk : bible.getBooks()) {
int zefID = bk.getId().getZefID();
if (zefID < 1 || zefID >= PALM_BOOK_NUMBERS.length || PALM_BOOK_NUMBERS[zefID] == 0) {
System.out.println("WARNING: Skipping unsupported book " + bk.getAbbr() + " (" + bk.getId().getOsisID() + ")");
continue;
}
bw.write("<BOOK NAME=\"" + bk.getShortName() + "\" NUMBER=\"" + PALM_BOOK_NUMBERS[bk.getId().getZefID()] + "\" SHORTCUT=\"" + bk.getAbbr() + "\">");
bw.newLine();
String longtitle = bk.getLongName();
int chapter = 0, verse;
for (Chapter chap : bk.getChapters()) {
chapter++;
if (chap.getProlog() != null)
System.out.println("WARNING: Skipping prolog (prologs not supported)!");
verse = 1;
String chaptext = CHAPTER_NAME + " " + chapter;
bw.write("<CHAPTER>");
bw.newLine();
for (VirtualVerse v : chap.createVirtualVerses()) {
while (v.getNumber() > verse) {
bw.write("<VERSE></VERSE>");
bw.newLine();
verse++;
}
if (v.getNumber() != verse)
throw new RuntimeException("Verse is " + v.getNumber() + ", should be " + verse);
boolean needVersText = false;
bw.write("<VERSE>");
if (longtitle != null) {
bw.write("<BOOKTEXT>" + longtitle);
longtitle = null;
needVersText = true;
}
if (chaptext != null) {
bw.write("<CHAPTEXT>" + chaptext);
chaptext = null;
needVersText = true;
}
for (Headline hl : v.getHeadlines()) {
bw.write("<DESCTEXT>");
hl.accept(contentVisitor);
needVersText = true;
}
if (needVersText)
bw.write("<VERSTEXT>");
for (Verse vv : v.getVerses()) {
if (!vv.getNumber().equals("" + v.getNumber())) {
bw.write("{" + vv.getNumber() + "} ");
}
vv.accept(contentVisitor);
}
bw.write("</VERSE>");
verse++;
bw.newLine();
}
bw.write("</CHAPTER>");
bw.newLine();
}
bw.write("</BOOK>");
bw.newLine();
}
bw.write("</BIBLE>");
bw.newLine();
}
}
use of biblemulticonverter.data.MetadataBook in project BibleMultiConverter by schierlm.
the class ZefDic method parseBible.
protected Bible parseBible(Dictionary doc) throws Exception {
Bible result = new Bible(doc.getType().toString() + "@" + doc.getRefbible());
MetadataBook metadata = new MetadataBook();
if (doc.getDicversion() != null) {
metadata.setValue(MetadataBookKey.version, doc.getDicversion());
}
if (doc.getRevision() != null) {
metadata.setValue(MetadataBookKey.revision, doc.getRevision());
}
for (JAXBElement<?> elem : doc.getINFORMATION().getTitleOrCreatorOrDescription()) {
if (elem.getValue() == null)
continue;
String value = normalize(elem.getValue().toString(), true).trim();
if (value.length() == 0)
value = "-empty-";
metadata.setValue(elem.getName().getLocalPart(), value);
}
metadata.finished();
if (metadata.getKeys().size() > 0)
result.getBooks().add(metadata.getBook());
int counter = 0;
for (TItem item : doc.getItem()) {
String id = item.getId();
String internalId = id;
if (!id.matches(Utils.BOOK_ABBR_REGEX))
internalId = "L" + (++counter);
Book bk = new Book(internalId, BookID.DICTIONARY_ENTRY, id, id);
result.getBooks().add(bk);
FormattedText prolog = new FormattedText();
bk.getChapters().add(new Chapter());
bk.getChapters().get(0).setProlog(prolog);
Visitor<RuntimeException> vv = prolog.getAppendVisitor();
String strongId = item.getStrongId();
if (strongId != null) {
Visitor<RuntimeException> vvvv = vv.visitExtraAttribute(ExtraAttributePriority.KEEP_CONTENT, "zefdic", "itemfield", "strongid");
vvvv.visitFormattingInstruction(FormattingInstructionKind.BOLD).visitText("Strong-ID: ");
vvvv.visitText(strongId);
vv.visitLineBreak(LineBreakKind.PARAGRAPH);
}
for (Object s : item.getContent()) {
if (s instanceof String) {
if (((String) s).trim().length() > 0)
throw new RuntimeException((String) s);
} else if (s instanceof JAXBElement) {
Object v = ((JAXBElement<?>) s).getValue();
if (!((JAXBElement<?>) s).getName().getNamespaceURI().equals("")) {
throw new RuntimeException(((JAXBElement<?>) s).getName().getNamespaceURI());
}
String nn = ((JAXBElement<?>) s).getName().getLocalPart();
if (v instanceof TParagraph && nn.equals("description")) {
TParagraph para = (TParagraph) v;
if (para.getId() != null)
throw new RuntimeException(para.getId());
Visitor<RuntimeException> vvv = vv.visitExtraAttribute(ExtraAttributePriority.KEEP_CONTENT, "zefdic", "field", "description");
for (Object oo : para.getContent()) {
if (oo instanceof String) {
vvv.visitText(normalize((String) oo, false));
} else if (oo instanceof JAXBElement) {
Object ovv = ((JAXBElement<?>) oo).getValue();
if (!((JAXBElement<?>) oo).getName().getNamespaceURI().equals("")) {
throw new RuntimeException(((JAXBElement<?>) oo).getName().getNamespaceURI());
}
String nnn = ((JAXBElement<?>) oo).getName().getLocalPart();
if (nnn.equals("br") && ovv instanceof String) {
if (((String) ovv).trim().length() > 0)
throw new RuntimeException((String) ovv);
vvv.visitLineBreak(LineBreakKind.NEWLINE);
} else if (nnn.equals("title") && ovv instanceof String) {
vvv.visitHeadline(2).visitText(((String) ovv).trim().replaceAll(" +", " "));
} else if (nnn.equals("sub") && ovv instanceof String) {
vvv.visitFormattingInstruction(FormattingInstructionKind.SUBSCRIPT).visitText(normalize((String) ovv, false));
} else if (nnn.equals("reflink") && ovv instanceof RefLinkType) {
RefLinkType r = (RefLinkType) ovv;
if (r.getTarget() != null || r.getContent() == null || r.getContent().length() > 0)
System.out.println("WARNING: Unsupported reflink attributes " + r.getTarget() + "|" + r.getContent());
if (r.getMscope() == null)
r.setMscope(r.getContent());
vv.visitDictionaryEntry("reflink", r.getMscope().replace(';', '-'));
} else if (nnn.equals("see") && ovv instanceof SeeType) {
SeeType see = (SeeType) ovv;
if (see.getTarget() != null && !see.getTarget().equals("x-self"))
throw new RuntimeException(see.getTarget());
vv.visitDictionaryEntry("dict", see.getContent());
} else if (nnn.equals("bib_link") && ovv instanceof BibLinkType) {
BibLinkType bl = (BibLinkType) ovv;
Visitor<RuntimeException> fn = vv.visitFootnote();
fn.visitText(FormattedText.XREF_MARKER);
BookID bid = BookID.fromZefId(Integer.parseInt(bl.getBn()));
int chapter = Integer.parseInt(bl.getCn1());
fn.visitCrossReference(bid.getOsisID(), bid, chapter, bl.getVn1(), chapter, bl.getVn1()).visitText(bid.getOsisID() + " " + chapter + ":" + bl.getVn1());
} else if (nnn.equals("greek") && ovv instanceof String) {
vv.visitExtraAttribute(ExtraAttributePriority.KEEP_CONTENT, "zefdic", "tag", "greek").visitText(normalize((String) ovv, false));
} else if (nnn.equals("em") && ovv instanceof String) {
vvv.visitFormattingInstruction(FormattingInstructionKind.ITALIC).visitText(normalize((String) ovv, false));
} else if (nnn.equals("strong") && ovv instanceof String) {
vvv.visitFormattingInstruction(FormattingInstructionKind.BOLD).visitText(normalize((String) ovv, false));
} else if (nnn.equals("q") && ovv instanceof String) {
vv.visitExtraAttribute(ExtraAttributePriority.KEEP_CONTENT, "zefdic", "tag", "q").visitText(normalize((String) ovv, false));
} else {
throw new RuntimeException(nnn + "/" + ovv.getClass().getName());
}
} else {
throw new RuntimeException(oo.getClass().getName());
}
}
vv.visitLineBreak(LineBreakKind.PARAGRAPH);
} else if (v instanceof String || v instanceof MyAnyType) {
Visitor<RuntimeException> vvvv;
boolean addParagraph = false;
if (nn.equals("title")) {
vvvv = vv.visitHeadline(1);
} else if (nn.equals("strong_id")) {
vvvv = vv.visitExtraAttribute(ExtraAttributePriority.KEEP_CONTENT, "zefdic", "field", "strongid");
vvvv.visitFormattingInstruction(FormattingInstructionKind.BOLD).visitText("Strong-ID: ");
addParagraph = true;
} else if (nn.equals("transliteration")) {
vvvv = vv.visitExtraAttribute(ExtraAttributePriority.KEEP_CONTENT, "zefdic", "field", "transliteration");
vvvv.visitFormattingInstruction(FormattingInstructionKind.BOLD).visitText("Transliteration: ");
addParagraph = true;
} else if (nn.equals("pronunciation")) {
vvvv = vv.visitExtraAttribute(ExtraAttributePriority.KEEP_CONTENT, "zefdic", "field", "pronunciation");
vvvv.visitFormattingInstruction(FormattingInstructionKind.BOLD).visitText("Pronunciation: ");
addParagraph = true;
} else {
throw new RuntimeException(nn);
}
if (v instanceof MyAnyType) {
parseElement(vvvv, (MyAnyType) v);
} else if (v instanceof String) {
vvvv.visitText(normalize((String) v, false));
}
if (addParagraph) {
vv.visitLineBreak(LineBreakKind.PARAGRAPH);
}
} else {
throw new RuntimeException(nn + "/" + v.getClass().getName());
}
} else {
throw new RuntimeException("" + s.getClass());
}
}
prolog.trimWhitespace();
prolog.finished();
}
return result;
}
use of biblemulticonverter.data.MetadataBook 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;
}
use of biblemulticonverter.data.MetadataBook 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;
}
Aggregations