Search in sources :

Example 1 with BibleVersificationSystem

use of biblemulticonverter.schema.versification.openscriptures.BibleVersificationSystem in project BibleMultiConverter by schierlm.

the class OpenScriptures method doImport.

@Override
public void doImport(VersificationSet versifications, String... importArgs) throws Exception {
    File inputFile = new File(importArgs[0]);
    ValidateXML.validateFileBeforeParsing(getSchema(), inputFile);
    JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
    Unmarshaller u = ctx.createUnmarshaller();
    BibleVersificationSystem doc = (BibleVersificationSystem) u.unmarshal(inputFile);
    List<Reference> allRefs = new ArrayList<>();
    for (BibleBookVersification bbv : doc.getBibleBookVersification()) {
        BookID bid = REFERENCE_ABBREVIATIONS.get(bbv.getReferenceAbbreviation());
        if (bid == null) {
            System.out.println("WARNING: Skipping " + bbv.getNameEnglish() + " [" + bbv.getReferenceAbbreviation() + "]");
            continue;
        }
        if (bbv.getNumChapters() != bbv.getNumVerses().size())
            System.out.println("WARNING: Chapter count " + bbv.getNumChapters() + " of " + bid + " does not match verse info " + bbv.getNumVerses().size());
        for (NumVerses nv : bbv.getNumVerses()) {
            if (nv.getChapter() == 0 && bbv.getNumVerses().size() == 1) {
                System.out.println("WARNING: Changing chapter " + bid + " 0 to 1");
                nv.setChapter(1);
            }
            if (nv.getCombinedVerses() != null || nv.getReorderedVerses() != null)
                System.out.println("WARNING: Unsupported attribute for " + bid + " " + nv.getChapter());
            Set<Integer> omitted = new HashSet<>();
            if (nv.getOmittedVerses() != null) {
                for (String num : nv.getOmittedVerses().split(",")) {
                    omitted.add(Integer.parseInt(num));
                }
            }
            for (int j = 1; j <= nv.getValue(); j++) {
                if (!omitted.contains(j)) {
                    allRefs.add(new Reference(bid, nv.getChapter(), "" + j));
                }
            }
        }
    }
    versifications.getVersifications().add(Versification.fromReferenceList(importArgs[1], doc.getHeader().getWork().getTitle(), null, allRefs));
}
Also used : Reference(biblemulticonverter.data.Versification.Reference) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) BibleVersificationSystem(biblemulticonverter.schema.versification.openscriptures.BibleVersificationSystem) BibleBookVersification(biblemulticonverter.schema.versification.openscriptures.BibleBookVersification) BookID(biblemulticonverter.data.BookID) NumVerses(biblemulticonverter.schema.versification.openscriptures.NumVerses) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

BookID (biblemulticonverter.data.BookID)1 Reference (biblemulticonverter.data.Versification.Reference)1 BibleBookVersification (biblemulticonverter.schema.versification.openscriptures.BibleBookVersification)1 BibleVersificationSystem (biblemulticonverter.schema.versification.openscriptures.BibleVersificationSystem)1 NumVerses (biblemulticonverter.schema.versification.openscriptures.NumVerses)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1