use of biblemulticonverter.schema.usx3.Note in project java-docs-samples by GoogleCloudPlatform.
the class Samples method createNote.
// [START create_note]
/**
* Creates and returns a new note
*
* @param noteId A user-specified identifier for the note.
* @param projectId the GCP project the note will be created under
* @return a Note object representing the new note
* @throws Exception on errors while closing the client
*/
public static Note createNote(String noteId, String projectId) throws Exception {
Note.Builder noteBuilder = Note.newBuilder();
noteBuilder.setVulnerabilityType(VulnerabilityType.newBuilder().build());
Note newNote = noteBuilder.build();
try (ContainerAnalysisClient client = ContainerAnalysisClient.create()) {
final String projectName = client.formatProjectName(projectId);
return client.createNote(projectName, noteId, newNote);
}
}
use of biblemulticonverter.schema.usx3.Note in project java-docs-samples by GoogleCloudPlatform.
the class SamplesTests method testUpdateNote.
@Test
public void testUpdateNote() throws Exception {
String descriptionText = "updated";
Note.Builder builder = Note.newBuilder(noteObj);
builder.setShortDescription(descriptionText);
Samples.updateNote(builder.build(), noteId, PROJECT_ID);
Note updated = Samples.getNote(noteId, PROJECT_ID);
assertEquals(descriptionText, updated.getShortDescription());
}
use of biblemulticonverter.schema.usx3.Note in project java-docs-samples by GoogleCloudPlatform.
the class SamplesTests method testCreateNote.
@Test
public void testCreateNote() throws Exception {
// note should have been created as part of set up. verify that it succeeded
Note n = Samples.getNote(noteId, PROJECT_ID);
assertEquals(n.getName(), noteObj.getName());
}
use of biblemulticonverter.schema.usx3.Note in project BibleMultiConverter by schierlm.
the class ZefaniaXMLMyBible method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
new StrippedDiffable().mergeIntroductionPrologs(bible);
final ObjectFactory f = new ObjectFactory();
XMLBIBLE doc = f.createXMLBIBLE();
doc.setBiblename(bible.getName());
doc.setType(EnumModtyp.X_BIBLE);
BigInteger revision = null;
MetadataBook metadata = bible.getMetadataBook();
if (metadata != null) {
for (MetadataBookKey key : Arrays.asList(MetadataBookKey.revision, MetadataBookKey.version, MetadataBookKey.date, MetadataBookKey.title)) {
String digits = metadata.getValue(key);
if (digits == null)
continue;
digits = digits.replaceAll("[^0-9]+", "");
if (!digits.isEmpty()) {
revision = new BigInteger(digits);
break;
}
}
}
if (revision == null) {
String digits = bible.getName().replaceAll("[^0-9]+", "");
if (!digits.isEmpty()) {
revision = new BigInteger(digits);
}
}
if (revision != null) {
doc.setRevision(revision);
}
doc.setINFORMATION(f.createINFORMATION());
List<DIV> prologs = new ArrayList<DIV>();
for (Book bk : bible.getBooks()) {
if (bk.getId().equals(BookID.METADATA))
continue;
int bsnumber = bk.getId().getZefID();
final BIBLEBOOK book = f.createBIBLEBOOK();
book.setBnumber(BigInteger.valueOf(bsnumber));
book.setBname(bk.getShortName());
book.setBsname(bk.getAbbr());
doc.getBIBLEBOOK().add(book);
int cnumber = 0;
for (Chapter cch : bk.getChapters()) {
cnumber++;
if (cch.getProlog() != null) {
DIV xx = f.createDIV();
prologs.add(xx);
NOTE xxx = f.createNOTE();
xx.setNOTE(xxx);
xxx.setType("x-studynote");
NOTE prolog = xxx;
DIV vers = f.createDIV();
prolog.getContent().add("<p>");
prolog.getContent().add(vers);
prolog.getContent().add("</p>");
vers.setNOTE(f.createNOTE());
final List<List<Object>> targetStack = new ArrayList<List<Object>>();
targetStack.add(vers.getNOTE().getContent());
cch.getProlog().accept(new Visitor<IOException>() {
@Override
public Visitor<IOException> visitHeadline(int depth) throws IOException {
if (depth > 6)
depth = 6;
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
targetStack.get(0).add("<h" + depth + ">");
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
targetStack.get(0).add("</h" + depth + ">");
targetStack.add(0, s.getContent());
return this;
}
@Override
public void visitVerseSeparator() throws IOException {
STYLE x = f.createSTYLE();
x.setCss("color:gray");
x.getContent().add("/");
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, x));
}
@Override
public void visitText(String text) throws IOException {
targetStack.get(0).add(text);
}
@Override
public Visitor<IOException> visitFormattingInstruction(FormattedText.FormattingInstructionKind kind) throws IOException {
String startTag, endTag;
if (kind.getHtmlTag() != null) {
startTag = "<" + kind.getHtmlTag() + ">";
endTag = "</" + kind.getHtmlTag() + ">";
} else {
startTag = "<span style=\"" + kind.getCss() + "\">";
endTag = "</span>";
}
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
targetStack.get(0).add(startTag);
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
targetStack.get(0).add(endTag);
targetStack.add(0, s.getContent());
return this;
}
@Override
public Visitor<IOException> visitFootnote() throws IOException {
System.out.println("WARNING: Footnotes in prolog are not supported");
return null;
}
@Override
public Visitor<IOException> visitCrossReference(String bookAbbr, BookID book, int firstChapter, String firstVerse, int lastChapter, String lastVerse) throws IOException {
System.out.println("WARNING: Cross references in prologs are not supported");
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
targetStack.add(0, s.getContent());
return this;
}
@Override
public Visitor<IOException> visitVariationText(String[] variations) throws IOException {
throw new RuntimeException("Variations not supported");
}
@Override
public void visitLineBreak(LineBreakKind kind) throws IOException {
BR br = f.createBR();
br.setArt(kind == LineBreakKind.PARAGRAPH ? EnumBreak.X_P : EnumBreak.X_NL);
targetStack.get(0).add(" ");
targetStack.get(0).add(kind == LineBreakKind.PARAGRAPH ? "<p>" : "<br>");
targetStack.get(0).add(br);
}
@Override
public Visitor<IOException> visitGrammarInformation(char[] strongsPrefixes, int[] strongs, String[] rmac, int[] sourceIndices) throws IOException {
throw new RuntimeException("Grammar tags in prologs not supported");
}
@Override
public FormattedText.Visitor<IOException> visitDictionaryEntry(String dictionary, String entry) throws IOException {
throw new RuntimeException("Dictionary entries in prologs not supported");
}
@Override
public void visitRawHTML(RawHTMLMode mode, String raw) throws IOException {
if (mode != RawHTMLMode.ONLINE)
targetStack.get(0).add(raw);
}
@Override
public Visitor<IOException> visitCSSFormatting(String css) throws IOException {
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
targetStack.get(0).add("<span style=\"" + css + "\">");
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
targetStack.get(0).add("</span>");
targetStack.add(0, s.getContent());
return this;
}
@Override
public int visitElementTypes(String elementTypes) throws IOException {
return 0;
}
@Override
public Visitor<IOException> visitExtraAttribute(ExtraAttributePriority prio, String category, String key, String value) throws IOException {
if (prio == ExtraAttributePriority.KEEP_CONTENT)
return visitCSSFormatting("-zef-extra-attribute-" + category + "-" + key + ": " + value);
else if (prio == ExtraAttributePriority.SKIP)
return null;
throw new RuntimeException("Extra attributes not supported");
}
@Override
public void visitStart() throws IOException {
}
@Override
public boolean visitEnd() throws IOException {
targetStack.remove(0);
return false;
}
});
if (targetStack.size() != 0)
throw new RuntimeException();
}
if (cch.getVerses().size() == 0)
continue;
CHAPTER chapter = f.createCHAPTER();
chapter.setCnumber(BigInteger.valueOf(cnumber));
book.getCHAPTER().add(chapter);
for (VirtualVerse vv : cch.createVirtualVerses()) {
for (Headline h : vv.getHeadlines()) {
CAPTION caption = f.createCAPTION();
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, EnumCaptionType.X_H_6, EnumCaptionType.X_H_6, EnumCaptionType.X_H_6 };
caption.setType(types[h.getDepth()]);
caption.setVref(BigInteger.valueOf(vv.getNumber()));
final StringBuilder sb = new StringBuilder();
h.accept(new FormattedText.VisitorAdapter<RuntimeException>(null) {
@Override
protected void beforeVisit() throws RuntimeException {
throw new IllegalStateException();
}
@Override
public Visitor<RuntimeException> visitFormattingInstruction(FormattingInstructionKind kind) throws RuntimeException {
System.out.println("WARNING: Formatting instructions in captions are not supported (stripped)");
return this;
}
@Override
public Visitor<RuntimeException> visitFootnote() throws RuntimeException {
System.out.println("WARNING: Footnotes in captions are not supported (stripped)");
return null;
}
@Override
public Visitor<RuntimeException> visitCSSFormatting(String css) throws RuntimeException {
System.out.println("WARNING: CSS Formatting in captions are not supported (stripped)");
return this;
}
@Override
public Visitor<RuntimeException> visitExtraAttribute(ExtraAttributePriority prio, String category, String key, String value) throws RuntimeException {
return prio.handleVisitor(category, this);
}
public void visitText(String text) throws RuntimeException {
sb.append(text);
}
});
caption.getContent().add(sb.toString());
chapter.getPROLOGOrCAPTIONOrVERS().add(caption);
}
VERS vers = f.createVERS();
vers.setVnumber(BigInteger.valueOf(vv.getNumber()));
for (DIV prolog : prologs) {
vers.getContent().add(prolog);
}
prologs.clear();
chapter.getPROLOGOrCAPTIONOrVERS().add(vers);
boolean first = true;
for (Verse v : vv.getVerses()) {
if (!first || !v.getNumber().equals("" + vv.getNumber())) {
STYLE x = f.createSTYLE();
x.setCss("font-weight: bold");
x.getContent().add("(" + v.getNumber() + ")");
vers.getContent().add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, x));
vers.getContent().add(" ");
}
first = false;
final List<List<Object>> targetStack = new ArrayList<List<Object>>();
targetStack.add(vers.getContent());
v.accept(new FormattedText.Visitor<IOException>() {
@Override
public void visitVerseSeparator() throws IOException {
STYLE x = f.createSTYLE();
x.setCss("color:gray");
x.getContent().add("/");
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, x));
}
@Override
public void visitText(String text) throws IOException {
targetStack.get(0).add(text);
}
@Override
public FormattedText.Visitor<IOException> visitFormattingInstruction(biblemulticonverter.data.FormattedText.FormattingInstructionKind kind) throws IOException {
STYLE x = f.createSTYLE();
x.setCss(kind.getCss());
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, x));
targetStack.add(0, x.getContent());
return this;
}
@Override
public Visitor<IOException> visitFootnote() throws IOException {
DIV x = f.createDIV();
targetStack.get(0).add(x);
NOTE n = f.createNOTE();
x.setNOTE(n);
n.setType("x-studynote");
final List<List<Object>> footnoteStack = new ArrayList<List<Object>>();
footnoteStack.add(n.getContent());
return new Visitor<IOException>() {
@Override
public void visitStart() throws IOException {
}
@Override
public void visitVerseSeparator() throws IOException {
STYLE x = f.createSTYLE();
x.setCss("color:gray");
x.getContent().add("/");
footnoteStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, x));
}
@Override
public void visitText(String text) throws IOException {
footnoteStack.get(0).add(text);
}
@Override
public void visitLineBreak(LineBreakKind kind) throws IOException {
BR br = f.createBR();
br.setArt(kind == LineBreakKind.PARAGRAPH ? EnumBreak.X_P : EnumBreak.X_NL);
footnoteStack.get(0).add(" ");
footnoteStack.get(0).add(br);
}
@Override
public Visitor<IOException> visitFormattingInstruction(FormattedText.FormattingInstructionKind kind) throws IOException {
String startTag, endTag;
if (kind.getHtmlTag() != null) {
startTag = "<" + kind.getHtmlTag() + ">";
endTag = "</" + kind.getHtmlTag() + ">";
} else {
startTag = "<span style=\"" + kind.getCss() + "\">";
endTag = "</span>";
}
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
footnoteStack.get(0).add(startTag);
footnoteStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
footnoteStack.get(0).add(endTag);
footnoteStack.add(0, s.getContent());
return this;
}
@Override
public Visitor<IOException> visitFootnote() throws IOException {
throw new RuntimeException("Footnotes in footnotes are not supported");
}
@Override
public Visitor<IOException> visitGrammarInformation(char[] strongsPrefixes, int[] strongs, String[] rmac, int[] sourceIndices) throws IOException {
GRAM gram = f.createGRAM();
if (strongs != null) {
StringBuilder entryBuilder = new StringBuilder();
for (int i = 0; i < strongs.length; i++) {
entryBuilder.append((i > 0 ? " " : "") + strongs[i]);
}
String entry = entryBuilder.toString();
gram.setStr(entry);
}
if (rmac != null) {
StringBuilder entryBuilder = new StringBuilder();
for (int i = 0; i < rmac.length; i++) {
if (i > 0)
entryBuilder.append(' ');
entryBuilder.append(rmac[i]);
}
gram.setRmac(entryBuilder.toString());
}
footnoteStack.get(0).add(new JAXBElement<GRAM>(new QName("gr"), GRAM.class, gram));
footnoteStack.add(0, gram.getContent());
return this;
}
@Override
public FormattedText.Visitor<IOException> visitDictionaryEntry(String dictionary, String entry) throws IOException {
GRAM gram = f.createGRAM();
gram.setStr(entry);
footnoteStack.get(0).add(new JAXBElement<GRAM>(new QName("gr"), GRAM.class, gram));
footnoteStack.add(0, gram.getContent());
return this;
}
@Override
public void visitRawHTML(RawHTMLMode mode, String raw) throws IOException {
if (mode != RawHTMLMode.ONLINE)
footnoteStack.get(0).add(raw);
}
@Override
public Visitor<IOException> visitVariationText(String[] variations) throws IOException {
throw new RuntimeException("Variations not supported");
}
@Override
public FormattedText.Visitor<IOException> visitCrossReference(String bookAbbr, BookID book, int firstChapter, String firstVerse, int lastChapter, String lastVerse) throws IOException {
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
int bookID = book.getZefID();
String mscope, xmscope;
try {
int start = firstVerse.equals("^") ? 1 : Integer.parseInt(firstVerse.replaceAll("[a-zG]|[,/][0-9]*", ""));
int end;
if (firstChapter == lastChapter && !lastVerse.equals("$")) {
end = Integer.parseInt(lastVerse.replaceAll("[a-z]|[,/][0-9]*", ""));
} else {
end = -1;
}
mscope = bookID + "," + firstChapter + "," + start + "," + end;
xmscope = bookID + ";" + firstChapter + ";" + start + "-" + end;
} catch (NumberFormatException ex) {
ex.printStackTrace();
mscope = bookID + ",1,1,999";
xmscope = bookID + ";1;1-999";
}
if (footnoteStack.size() == 1) {
List<Object> outerList = targetStack.get(0);
XREF xref = new XREF();
xref.setMscope(xmscope);
outerList.add(outerList.size() - 1, xref);
}
footnoteStack.get(0).add("<a href=\"mybible:content=location&locations=" + mscope + "\">");
footnoteStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
footnoteStack.get(0).add("</a>");
footnoteStack.add(0, s.getContent());
return this;
}
public boolean visitEnd() throws IOException {
footnoteStack.remove(0);
return false;
}
@Override
public int visitElementTypes(String elementTypes) throws IOException {
return 0;
}
@Override
public Visitor<IOException> visitHeadline(int depth) throws IOException {
throw new RuntimeException("Headlines in footnotes not supported");
}
@Override
public Visitor<IOException> visitCSSFormatting(String css) throws IOException {
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
footnoteStack.get(0).add("<span style=\"" + css + "\">");
footnoteStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
footnoteStack.get(0).add("</span>");
footnoteStack.add(s.getContent());
return this;
}
@Override
public Visitor<IOException> visitExtraAttribute(ExtraAttributePriority prio, String category, String key, String value) throws IOException {
System.out.println("WARNING: Extra attributes not supported");
Visitor<IOException> result = prio.handleVisitor(category, this);
if (result != null)
footnoteStack.add(0, footnoteStack.get(0));
return result;
}
};
}
@Override
public FormattedText.Visitor<IOException> visitCrossReference(String bookAbbr, BookID book, int firstChapter, String firstVerse, int lastChapter, String lastVerse) throws IOException {
throw new RuntimeException("Xref outside of footnotes not supported!");
}
@Override
public void visitLineBreak(LineBreakKind kind) throws IOException {
BR br = f.createBR();
br.setArt(kind == LineBreakKind.PARAGRAPH ? EnumBreak.X_P : EnumBreak.X_NL);
targetStack.get(0).add(" ");
targetStack.get(0).add(br);
}
@Override
public Visitor<IOException> visitGrammarInformation(char[] strongsPrefixes, int[] strongs, String[] rmac, int[] sourceIndices) throws IOException {
GRAM gram = f.createGRAM();
if (strongs != null) {
StringBuilder entryBuilder = new StringBuilder();
for (int i = 0; i < strongs.length; i++) {
entryBuilder.append((i > 0 ? " " : "") + strongs[i]);
}
String entry = entryBuilder.toString();
gram.setStr(entry);
}
if (rmac != null) {
StringBuilder entryBuilder = new StringBuilder();
for (int i = 0; i < rmac.length; i++) {
if (i > 0)
entryBuilder.append(' ');
entryBuilder.append(rmac[i]);
}
gram.setRmac(entryBuilder.toString());
}
targetStack.get(0).add(new JAXBElement<GRAM>(new QName("gr"), GRAM.class, gram));
targetStack.add(0, gram.getContent());
return this;
}
@Override
public FormattedText.Visitor<IOException> visitDictionaryEntry(String dictionary, String entry) throws IOException {
GRAM gram = f.createGRAM();
gram.setStr(entry);
targetStack.get(0).add(new JAXBElement<GRAM>(new QName("gr"), GRAM.class, gram));
targetStack.add(0, gram.getContent());
return this;
}
@Override
public void visitRawHTML(RawHTMLMode mode, String raw) throws IOException {
throw new RuntimeException("Raw HTML is not supported");
}
@Override
public Visitor<IOException> visitVariationText(String[] variations) throws IOException {
throw new RuntimeException("Variations not supported");
}
@Override
public boolean visitEnd() throws IOException {
targetStack.remove(0);
return false;
}
@Override
public int visitElementTypes(String elementTypes) throws IOException {
return 0;
}
@Override
public Visitor<IOException> visitHeadline(int depth) throws IOException {
throw new RuntimeException("Headline in virtual verse is impossible");
}
@Override
public void visitStart() throws IOException {
}
@Override
public Visitor<IOException> visitCSSFormatting(String css) throws IOException {
STYLE x = f.createSTYLE();
x.setCss(css);
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, x));
targetStack.add(0, x.getContent());
return this;
}
@Override
public Visitor<IOException> visitExtraAttribute(ExtraAttributePriority prio, String category, String key, String value) throws IOException {
System.out.println("WARNING: Extra attributes not supported");
Visitor<IOException> result = prio.handleVisitor(category, this);
if (result != null)
targetStack.add(0, targetStack.get(0));
return result;
}
});
if (targetStack.size() != 0)
throw new RuntimeException();
}
}
}
if (book.getCHAPTER().size() == 0) {
doc.getBIBLEBOOK().remove(book);
}
}
final Document docc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
JAXBContext.newInstance(ObjectFactory.class.getPackage().getName()).createMarshaller().marshal(doc, docc);
docc.getDocumentElement().setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
docc.getDocumentElement().setAttribute("xsi:noNamespaceSchemaLocation", "zef2005.xsd");
docc.normalize();
maskWhitespaceNodes(docc.getDocumentElement());
try (FileOutputStream fos = new FileOutputStream(exportArgs[0])) {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(new DOMSource(docc), new StreamResult(fos));
}
}
use of biblemulticonverter.schema.usx3.Note in project BibleMultiConverter by schierlm.
the class USX3 method doImportBook.
@Override
protected ParatextBook doImportBook(File inputFile) throws Exception {
if (!inputFile.getName().toLowerCase().endsWith(".usx"))
return null;
ValidateXML.validateFileBeforeParsing(getSchema(), inputFile);
JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
XMLInputFactory xif = XMLInputFactory.newFactory();
XMLStreamReader xsr = xif.createXMLStreamReader(new FileInputStream(inputFile));
Unmarshaller u = ctx.createUnmarshaller();
u.setListener(unmarshallerLocationListener);
unmarshallerLocationListener.setXMLStreamReader(inputFile.getName(), xsr);
Usx doc = (Usx) u.unmarshal(xsr);
xsr.close();
ParatextBook.ParatextID id = ParatextBook.ParatextID.fromIdentifier(doc.getBook().getCode().toUpperCase());
if (id == null) {
System.out.println("WARNING: Skipping book with unknown ID: " + doc.getBook().getCode());
return null;
}
ParatextBook result = new ParatextBook(id, doc.getBook().getContent());
ParatextCharacterContent charContent = null;
for (Object o : doc.getParaOrTableOrChapter()) {
if (o instanceof Para) {
Para para = (Para) o;
if (BOOK_HEADER_ATTRIBUTE_TAGS.contains(para.getStyle().value())) {
String value = "";
for (Object oo : para.getContent()) {
if (oo instanceof String) {
value += ((String) oo).replaceAll("[ \r\n\t]+", " ");
} else {
throw new RuntimeException("Unsupported content in attribute: " + oo.getClass());
}
}
result.getAttributes().put(para.getStyle().value(), value);
charContent = null;
} else if (para.getStyle() == ParaStyle.PB) {
if (charContent == null) {
charContent = new ParatextCharacterContent();
result.getContent().add(charContent);
}
charContent.getContent().add(new ParatextCharacterContent.AutoClosingFormatting(ParatextCharacterContent.AutoClosingFormattingKind.PAGE_BREAK, false));
} else if (PARA_STYLE_UNSUPPORTED.contains(para.getStyle())) {
// skip
charContent = null;
} else {
result.getContent().add(new ParatextBook.ParagraphStart(PARA_STYLE_MAP.get(para.getStyle())));
charContent = null;
if (!para.getContent().isEmpty()) {
charContent = new ParatextCharacterContent();
result.getContent().add(charContent);
parseCharContent(para.getContent(), charContent);
}
}
} else if (o instanceof Table) {
Table table = (Table) o;
for (Row row : table.getRow()) {
result.getContent().add(new ParatextBook.ParagraphStart(ParatextBook.ParagraphKind.TABLE_ROW));
for (Object oo : row.getVerseOrCell()) {
if (oo instanceof Verse) {
Verse verse = (Verse) oo;
ParatextCharacterContent.ParatextCharacterContentPart verseStartOrEnd = handleVerse(verse);
charContent = new ParatextCharacterContent();
result.getContent().add(charContent);
charContent.getContent().add(verseStartOrEnd);
} else if (oo instanceof Cell) {
Cell cell = (Cell) oo;
result.getContent().add(new ParatextBook.TableCellStart(cell.getStyle().value()));
charContent = new ParatextCharacterContent();
result.getContent().add(charContent);
parseCharContent(cell.getContent(), charContent);
} else {
throw new IOException("Unsupported table row element: " + o.getClass().getName());
}
}
}
charContent = null;
} else if (o instanceof Chapter) {
Chapter chapter = (Chapter) o;
if (chapter.getSid() != null) {
// Assume start chapter
result.getContent().add(new ParatextBook.ChapterStart(new ChapterIdentifier(result.getId(), ((Chapter) o).getNumber().intValue())));
} else if (chapter.getEid() != null) {
// Assume end chapter
ChapterIdentifier location = ChapterIdentifier.fromLocationString(chapter.getEid());
if (location == null) {
throw new IOException("Invalid chapter eid found: " + chapter.getEid());
}
result.getContent().add(new ParatextBook.ChapterEnd(location));
} else {
throw new IOException("Invalid chapter found, both sid and eid are undefined: " + chapter);
}
charContent = null;
} else if (o instanceof Note) {
if (charContent == null) {
charContent = new ParatextCharacterContent();
result.getContent().add(charContent);
}
Note note = (Note) o;
ParatextCharacterContent.FootnoteXref nx = new ParatextCharacterContent.FootnoteXref(NOTE_STYLE_MAP.get(note.getStyle()), note.getCaller());
charContent.getContent().add(nx);
parseCharContent(note.getContent(), nx);
} else if (o instanceof Sidebar) {
System.out.println("WARNING: Skipping sidebar (study bible content)");
charContent = null;
} else {
throw new IOException("Unsupported book level element: " + o.getClass().getName());
}
}
return result;
}
Aggregations