Search in sources :

Example 1 with FormattedTextType

use of biblemulticonverter.schema.roundtripxml.FormattedTextType in project BibleMultiConverter by schierlm.

the class RoundtripXML method parseContent.

private void parseContent(Visitor<RuntimeException> visitor, List<Serializable> contentList) throws IOException {
    for (Serializable content : contentList) {
        if (content instanceof String) {
            visitor.visitText((String) content);
        } else if (content instanceof JAXBElement<?>) {
            Object value = ((JAXBElement<?>) content).getValue();
            Visitor<RuntimeException> next;
            if (value instanceof FormattedTextType.Headline) {
                next = visitor.visitHeadline(((FormattedTextType.Headline) value).getDepth());
            } else if (value instanceof FormattedTextType.Footnote) {
                next = visitor.visitFootnote();
            } else if (value instanceof FormattedTextType.CrossReference) {
                FormattedTextType.CrossReference xr = (FormattedTextType.CrossReference) value;
                next = visitor.visitCrossReference(xr.getBookAbbr(), BookID.fromOsisId(xr.getBook()), xr.getFirstChapter(), xr.getFirstVerse(), xr.getLastChapter(), xr.getLastVerse());
            } else if (value instanceof FormattedTextType.LineBreak) {
                visitor.visitLineBreak(LineBreakKind.valueOf(((FormattedTextType.LineBreak) value).getKind().name()));
                continue;
            } else if (value instanceof FormattedTextType.DictionaryEntry) {
                FormattedTextType.DictionaryEntry de = (FormattedTextType.DictionaryEntry) value;
                next = visitor.visitDictionaryEntry(de.getDictionary(), de.getEntry());
            } else if (value instanceof FormattedTextType.GrammarInformation) {
                FormattedTextType.GrammarInformation gi = (FormattedTextType.GrammarInformation) value;
                int[] strongs = null;
                if (!gi.getStrongs().isEmpty()) {
                    strongs = new int[gi.getStrongs().size()];
                    for (int i = 0; i < strongs.length; i++) {
                        strongs[i] = gi.getStrongs().get(i);
                    }
                }
                String[] rmacs = null;
                if (!gi.getRmac().isEmpty()) {
                    rmacs = (String[]) gi.getRmac().toArray(new String[gi.getRmac().size()]);
                }
                int[] sidxs = null;
                if (!gi.getSourceIndices().isEmpty()) {
                    sidxs = new int[gi.getSourceIndices().size()];
                    for (int i = 0; i < sidxs.length; i++) {
                        sidxs[i] = gi.getSourceIndices().get(i);
                    }
                }
                next = visitor.visitGrammarInformation(strongs, rmacs, sidxs);
            } else if (value instanceof FormattedTextType.FormattingInstruction) {
                next = visitor.visitFormattingInstruction(FormattingInstructionKind.valueOf(((FormattedTextType.FormattingInstruction) value).getKind().name()));
            } else if (value instanceof FormattedTextType.CssFormatting) {
                next = visitor.visitCSSFormatting(((FormattedTextType.CssFormatting) value).getCss());
            } else if (value instanceof FormattedTextType.ExtraAttribute) {
                FormattedTextType.ExtraAttribute xa = (FormattedTextType.ExtraAttribute) value;
                next = visitor.visitExtraAttribute(ExtraAttributePriority.valueOf(xa.getPrio().name()), xa.getCategory(), xa.getKey(), xa.getValue());
            } else if (value instanceof FormattedTextType.Variation) {
                List<String> vars = ((FormattedTextType.Variation) value).getVariations();
                next = visitor.visitVariationText((String[]) vars.toArray(new String[vars.size()]));
            } else if (value instanceof FormattedTextType.RawHTML) {
                FormattedTextType.RawHTML rh = (FormattedTextType.RawHTML) value;
                visitor.visitRawHTML(RawHTMLMode.valueOf(rh.getMode().name()), rh.getValue());
                continue;
            } else if (value instanceof FormattedTextType.VerseSeparator) {
                visitor.visitVerseSeparator();
                continue;
            } else {
                throw new IOException("Invalid JAXBElement value: " + value.getClass());
            }
            parseContent(next, ((FormattedTextType) value).getContent());
        } else {
            throw new IOException("Invalid content: " + content.getClass());
        }
    }
}
Also used : RawHTML(biblemulticonverter.schema.roundtripxml.FormattedTextType.RawHTML) LineBreak(biblemulticonverter.schema.roundtripxml.FormattedTextType.LineBreak) Serializable(java.io.Serializable) Visitor(biblemulticonverter.data.FormattedText.Visitor) RawHTML(biblemulticonverter.schema.roundtripxml.FormattedTextType.RawHTML) CrossReference(biblemulticonverter.schema.roundtripxml.FormattedTextType.CrossReference) FormattedTextType(biblemulticonverter.schema.roundtripxml.FormattedTextType) CssFormatting(biblemulticonverter.schema.roundtripxml.FormattedTextType.CssFormatting) IOException(java.io.IOException) CrossReference(biblemulticonverter.schema.roundtripxml.FormattedTextType.CrossReference) Variation(biblemulticonverter.schema.roundtripxml.FormattedTextType.Variation)

Aggregations

Visitor (biblemulticonverter.data.FormattedText.Visitor)1 FormattedTextType (biblemulticonverter.schema.roundtripxml.FormattedTextType)1 CrossReference (biblemulticonverter.schema.roundtripxml.FormattedTextType.CrossReference)1 CssFormatting (biblemulticonverter.schema.roundtripxml.FormattedTextType.CssFormatting)1 LineBreak (biblemulticonverter.schema.roundtripxml.FormattedTextType.LineBreak)1 RawHTML (biblemulticonverter.schema.roundtripxml.FormattedTextType.RawHTML)1 Variation (biblemulticonverter.schema.roundtripxml.FormattedTextType.Variation)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1