Search in sources :

Example 1 with NOTE

use of biblemulticonverter.schema.haggai.NOTE in project BibleMultiConverter by schierlm.

the class HaggaiXML method parseContent.

private boolean parseContent(Visitor<RuntimeException> visitor, List<? extends Object> contentList, Map<BookID, String> abbrMap) throws IOException {
    boolean contentFound = false;
    for (Object n : contentList) {
        if (n instanceof String) {
            String value = normalize((String) n, false);
            visitor.visitText(value);
            contentFound |= value.trim().length() > 0;
        } else if (n instanceof JAXBElement<?>) {
            String name = ((JAXBElement<?>) n).getName().toString();
            Object nn = ((JAXBElement<?>) n).getValue();
            if (name.equals("STYLE") && nn instanceof STYLE) {
                TStyleFix fs = ((STYLE) nn).getFs();
                FormattingInstructionKind kind;
                switch(fs) {
                    case BOLD:
                        kind = FormattingInstructionKind.BOLD;
                        break;
                    case DIVINE_NAME:
                        kind = FormattingInstructionKind.DIVINE_NAME;
                        break;
                    case EMPHASIS:
                    case ITALIC:
                        kind = FormattingInstructionKind.ITALIC;
                        break;
                    case LINE_THROUGH:
                        kind = FormattingInstructionKind.STRIKE_THROUGH;
                        break;
                    case SUB:
                        kind = FormattingInstructionKind.SUBSCRIPT;
                        break;
                    case SUPER:
                        kind = FormattingInstructionKind.SUPERSCRIPT;
                        break;
                    case UNDERLINE:
                        kind = FormattingInstructionKind.UNDERLINE;
                        break;
                    case UPPERCASE:
                    case ACROSTIC:
                    case ILLUMINATED:
                    case LOWERCASE:
                    case NORMAL:
                    case OVERLINE:
                    case SMALL_CAPS:
                    default:
                        kind = null;
                        break;
                }
                if (kind == null)
                    throw new IOException(fs.toString());
                Visitor<RuntimeException> contentVisitor = visitor;
                if (kind != null) {
                    contentVisitor = contentVisitor.visitFormattingInstruction(kind);
                }
                List<Serializable> content = ((STYLE) nn).getContent();
                boolean subContentFound = parseContent(contentVisitor, content, abbrMap);
                if (!subContentFound)
                    visitEmptyMarker(contentVisitor);
            } else if ((name.equals("gr") || name.equals("GRAM")) && nn instanceof GRAM) {
                GRAM gram = (GRAM) nn;
                Visitor<RuntimeException> strongVisitor = visitor;
                int[] strongs = null;
                if (gram.getStr() != null) {
                    List<String> strongList = new ArrayList<String>(Arrays.asList(gram.getStr().trim().replaceAll(" ++", " ").replace("G", "").replace("H", "").split(" ")));
                    for (int i = 0; i < strongList.size(); i++) {
                        if (!strongList.get(i).matches("[0-9]+")) {
                            System.out.println("WARNING: Skipping invalid Strong number " + strongList.get(i));
                            strongList.remove(i);
                            i--;
                        }
                    }
                    strongs = new int[strongList.size()];
                    for (int i = 0; i < strongs.length; i++) {
                        strongs[i] = Integer.parseInt(strongList.get(i));
                    }
                }
                String[] rmac = null;
                if (gram.getRmac() != null && gram.getRmac().length() > 0) {
                    List<String> rmacList = new ArrayList<String>(Arrays.asList(gram.getRmac().toUpperCase().split(" ")));
                    for (int i = 0; i < rmacList.size(); i++) {
                        String rmacValue = rmacList.get(i);
                        if (rmacValue.endsWith("-"))
                            rmacValue = rmacValue.substring(0, rmacValue.length() - 1);
                        rmacList.set(i, rmacValue);
                        if (!rmacValue.matches(Utils.RMAC_REGEX)) {
                            System.out.println("WARNING: Skipping invalid RMAC: " + rmacValue);
                            rmacList.remove(i);
                            i--;
                        }
                        rmac = (String[]) rmacList.toArray(new String[rmacList.size()]);
                    }
                }
                if (strongs != null && strongs.length == 0)
                    strongs = null;
                if (rmac != null && rmac.length == 0)
                    rmac = null;
                if (strongs != null || rmac != null)
                    strongVisitor = strongVisitor.visitGrammarInformation(strongs, rmac, null);
                if (!parseContent(strongVisitor, gram.getContent(), abbrMap) && strongVisitor != visitor) {
                    visitEmptyMarker(strongVisitor);
                }
            } else if (name.equals("NOTE") && nn instanceof NOTE) {
                NOTE note = (NOTE) nn;
                if (note.getContent().size() == 0)
                    continue;
                Visitor<RuntimeException> v;
                v = visitor.visitFootnote();
                boolean subContentFound = parseContent(v, note.getContent(), abbrMap);
                if (!subContentFound)
                    visitEmptyMarker(v);
                contentFound = true;
            } else if (name.equals("BR")) {
                visitor.visitLineBreak(LineBreakKind.NEWLINE);
                contentFound = true;
            } else {
                throw new IOException(name);
            }
            contentFound = true;
        } else {
            throw new IOException(n.getClass().toString());
        }
    }
    return contentFound;
}
Also used : Visitor(biblemulticonverter.data.FormattedText.Visitor) STYLE(biblemulticonverter.schema.haggai.STYLE) ArrayList(java.util.ArrayList) FormattingInstructionKind(biblemulticonverter.data.FormattedText.FormattingInstructionKind) JAXBElement(javax.xml.bind.JAXBElement) IOException(java.io.IOException) GRAM(biblemulticonverter.schema.haggai.GRAM) NOTE(biblemulticonverter.schema.haggai.NOTE) List(java.util.List) ArrayList(java.util.ArrayList) TStyleFix(biblemulticonverter.schema.haggai.TStyleFix)

Aggregations

FormattingInstructionKind (biblemulticonverter.data.FormattedText.FormattingInstructionKind)1 Visitor (biblemulticonverter.data.FormattedText.Visitor)1 GRAM (biblemulticonverter.schema.haggai.GRAM)1 NOTE (biblemulticonverter.schema.haggai.NOTE)1 STYLE (biblemulticonverter.schema.haggai.STYLE)1 TStyleFix (biblemulticonverter.schema.haggai.TStyleFix)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JAXBElement (javax.xml.bind.JAXBElement)1