Search in sources :

Example 1 with Ref

use of biblemulticonverter.schema.usx.Ref in project BibleMultiConverter by schierlm.

the class USX method parseCharContent.

private void parseCharContent(List<Object> content, ParatextCharacterContentContainer container, ParatextBook result, ImportContext context) throws IOException {
    for (Object o : content) {
        if (o instanceof Optbreak) {
            // is ignored in USFM as well
            System.out.println("WARNING: Skipping optional break");
        } else if (o instanceof Ref) {
            Ref r = (Ref) o;
            try {
                container.getContent().add(ParatextCharacterContent.Reference.parse(r.getLoc(), r.getContent()));
            } catch (IllegalArgumentException e) {
                String location = unmarshallerLocationListener.getHumanReadableLocation(o);
                System.out.println("WARNING: Unsupported structured reference format at " + location + " - replaced by plain text: " + r.getLoc());
                final ParatextCharacterContent.Text text = ParatextCharacterContent.Text.from(r.getContent());
                if (text != null) {
                    container.getContent().add(text);
                }
            }
        } else if (o instanceof String) {
            final ParatextCharacterContent.Text text = ParatextCharacterContent.Text.from((String) o);
            if (text != null) {
                container.getContent().add(text);
            }
        } else if (o instanceof Figure) {
            System.out.println("WARNING: Skipping figure");
        } else if (o instanceof Char) {
            Char chr = (Char) o;
            if (CHAR_STYLE_UNSUPPORTED.contains(chr.getStyle())) {
                parseCharContent(chr.getContent(), container, result, context);
            } else {
                AutoClosingFormatting f = new AutoClosingFormatting(CHAR_STYLE_MAP.get(chr.getStyle()), false);
                String lemma = chr.getLemma();
                if (f.getKind() == AutoClosingFormattingKind.WORDLIST && lemma != null && !lemma.isEmpty()) {
                    f.getAttributes().put("lemma", lemma);
                }
                container.getContent().add(f);
                parseCharContent(chr.getContent(), f, result, context);
            }
        } else if (o instanceof Verse) {
            ImportUtilities.closeOpenVerse(result, context.openVerse);
            context.openVerse = handleVerse(result, (Verse) o);
            container.getContent().add(context.openVerse);
        } else if (o instanceof Note) {
            Note note = (Note) o;
            FootnoteXref nx = new FootnoteXref(NOTE_STYLE_MAP.get(note.getStyle()), note.getCaller());
            container.getContent().add(nx);
            parseCharContent(note.getContent(), nx, result, context);
        } else {
            throw new IOException("Unsupported character content element: " + o.getClass().getName());
        }
    }
}
Also used : AutoClosingFormatting(biblemulticonverter.format.paratext.ParatextCharacterContent.AutoClosingFormatting) IOException(java.io.IOException) FootnoteXref(biblemulticonverter.format.paratext.ParatextCharacterContent.FootnoteXref) Optbreak(biblemulticonverter.schema.usx.Optbreak) Figure(biblemulticonverter.schema.usx.Figure) Ref(biblemulticonverter.schema.usx.Ref) Char(biblemulticonverter.schema.usx.Char) Note(biblemulticonverter.schema.usx.Note) Verse(biblemulticonverter.schema.usx.Verse)

Aggregations

AutoClosingFormatting (biblemulticonverter.format.paratext.ParatextCharacterContent.AutoClosingFormatting)1 FootnoteXref (biblemulticonverter.format.paratext.ParatextCharacterContent.FootnoteXref)1 Char (biblemulticonverter.schema.usx.Char)1 Figure (biblemulticonverter.schema.usx.Figure)1 Note (biblemulticonverter.schema.usx.Note)1 Optbreak (biblemulticonverter.schema.usx.Optbreak)1 Ref (biblemulticonverter.schema.usx.Ref)1 Verse (biblemulticonverter.schema.usx.Verse)1 IOException (java.io.IOException)1