Search in sources :

Example 1 with XMLBIBLE

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

the class HaggaiXML method doExport.

@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
    File file = new File(exportArgs[0]);
    XMLBIBLE xmlbible = createXMLBible(bible);
    final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
    Marshaller m = ctx.createMarshaller();
    m.setSchema(getSchema());
    m.marshal(new JAXBElement<XMLBIBLE>(new QName("XMLBIBLE"), XMLBIBLE.class, xmlbible), doc);
    doc.getDocumentElement().setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    doc.getDocumentElement().setAttribute("xsi:noNamespaceSchemaLocation", "haggai_20130620.xsd");
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    transformer.transform(new DOMSource(doc), new StreamResult(file));
}
Also used : Marshaller(javax.xml.bind.Marshaller) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) XMLBIBLE(biblemulticonverter.schema.haggai.XMLBIBLE) QName(javax.xml.namespace.QName) JAXBContext(javax.xml.bind.JAXBContext) Document(org.w3c.dom.Document) File(java.io.File)

Example 2 with XMLBIBLE

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

the class HaggaiXML method doImport.

@Override
public Bible doImport(File inputFile) throws Exception {
    ValidateXML.validateFileBeforeParsing(getSchema(), inputFile);
    JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
    Unmarshaller u = ctx.createUnmarshaller();
    XMLBIBLE doc = (XMLBIBLE) ((JAXBElement<?>) u.unmarshal(inputFile)).getValue();
    return parseBible(doc);
}
Also used : XMLBIBLE(biblemulticonverter.schema.haggai.XMLBIBLE) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 3 with XMLBIBLE

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

the class HaggaiXML method createXMLBible.

protected XMLBIBLE createXMLBible(Bible bible) throws Exception {
    ObjectFactory of = new ObjectFactory();
    XMLBIBLE doc = of.createXMLBIBLE();
    doc.setBiblename(bible.getName());
    doc.setINFORMATION(new JAXBElement<INFORMATION>(new QName("INFORMATION"), INFORMATION.class, of.createINFORMATION()));
    MetadataBook metadata = bible.getMetadataBook();
    if (metadata != null) {
        for (String key : metadata.getKeys()) {
            String value = metadata.getValue(key);
            if (value.equals("-empty-"))
                value = "";
            if (key.equals(MetadataBookKey.status.toString())) {
                doc.setStatus(ModuleStatus.fromValue(value));
            } else if (key.equals(MetadataBookKey.version.toString())) {
                doc.setVersion(value);
            } else if (key.equals(MetadataBookKey.revision.toString())) {
                doc.setRevision(new BigInteger(value));
            } else if (!key.contains("@")) {
                Pattern regex = INFORMATION_FIELDS.get(MetadataBookKey.valueOf(key));
                if (regex != null && regex.matcher(value).matches())
                    doc.getINFORMATION().getValue().getTitleOrCreatorOrDescription().add(new JAXBElement<String>(new QName(key), String.class, value));
            }
        }
    }
    for (Book bk : bible.getBooks()) {
        if (bk.getId().equals(BookID.METADATA))
            continue;
        if (bk.getId().getZefID() <= 0) {
            System.out.println("WARNING: Unable to export book " + bk.getAbbr());
            continue;
        }
        BIBLEBOOK bb = of.createBIBLEBOOK();
        bb.setBnumber(BigInteger.valueOf(bk.getId().getZefID()));
        bb.setBsname(bk.getShortName());
        bb.setBname(bk.getLongName());
        int cnumber = 0;
        for (Chapter ccc : bk.getChapters()) {
            cnumber++;
            if (ccc.getVerses().size() == 0)
                continue;
            CHAPTER cc = of.createCHAPTER();
            cc.setCnumber(BigInteger.valueOf(cnumber));
            bb.getCAPTIONOrPROLOGOrREMARK().add(new JAXBElement<CHAPTER>(new QName("CHAPTER"), CHAPTER.class, cc));
            if (ccc.getProlog() != null) {
                PROLOG prolog = of.createPROLOG();
                ccc.getProlog().accept(new CreateContentVisitor(of, prolog.getContent(), null));
                cc.getCAPTIONOrPARAGRAPHOrVERSE().add(new JAXBElement<PROLOG>(new QName("PROLOG"), PROLOG.class, prolog));
            }
            for (VirtualVerse vv : ccc.createVirtualVerses()) {
                for (Headline h : vv.getHeadlines()) {
                    CAPTION caption = of.createCAPTION();
                    h.accept(new CreateContentVisitor(of, caption.getContent(), null));
                    cc.getCAPTIONOrPARAGRAPHOrVERSE().add(new JAXBElement<CAPTION>(new QName("CAPTION"), CAPTION.class, caption));
                }
                VERSE vers = of.createVERSE();
                vers.setVnumber(BigInteger.valueOf(vv.getNumber()));
                for (Verse v : vv.getVerses()) {
                    if (!v.getNumber().equals("" + vv.getNumber())) {
                        STYLE verseNum = of.createSTYLE();
                        verseNum.setFs(TStyleFix.BOLD);
                        verseNum.getContent().add("(" + v.getNumber() + ")");
                        vers.getContent().add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, verseNum));
                        vers.getContent().add(" ");
                    }
                    v.accept(new CreateContentVisitor(of, vers.getContent(), vers));
                }
                cc.getCAPTIONOrPARAGRAPHOrVERSE().add(new JAXBElement<VERSE>(new QName("VERSE"), VERSE.class, vers));
            }
        }
        doc.getBIBLEBOOK().add(new JAXBElement<BIBLEBOOK>(new QName("BIBLEBOOK"), BIBLEBOOK.class, bb));
    }
    return doc;
}
Also used : VirtualVerse(biblemulticonverter.data.VirtualVerse) VERSE(biblemulticonverter.schema.haggai.VERSE) ObjectFactory(biblemulticonverter.schema.haggai.ObjectFactory) Book(biblemulticonverter.data.Book) MetadataBook(biblemulticonverter.data.MetadataBook) Headline(biblemulticonverter.data.FormattedText.Headline) PROLOG(biblemulticonverter.schema.haggai.PROLOG) MetadataBook(biblemulticonverter.data.MetadataBook) Pattern(java.util.regex.Pattern) XMLBIBLE(biblemulticonverter.schema.haggai.XMLBIBLE) INFORMATION(biblemulticonverter.schema.haggai.INFORMATION) QName(javax.xml.namespace.QName) Chapter(biblemulticonverter.data.Chapter) STYLE(biblemulticonverter.schema.haggai.STYLE) BIBLEBOOK(biblemulticonverter.schema.haggai.BIBLEBOOK) CHAPTER(biblemulticonverter.schema.haggai.CHAPTER) BigInteger(java.math.BigInteger) CAPTION(biblemulticonverter.schema.haggai.CAPTION) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Aggregations

XMLBIBLE (biblemulticonverter.schema.haggai.XMLBIBLE)3 JAXBContext (javax.xml.bind.JAXBContext)2 QName (javax.xml.namespace.QName)2 Book (biblemulticonverter.data.Book)1 Chapter (biblemulticonverter.data.Chapter)1 Headline (biblemulticonverter.data.FormattedText.Headline)1 MetadataBook (biblemulticonverter.data.MetadataBook)1 Verse (biblemulticonverter.data.Verse)1 VirtualVerse (biblemulticonverter.data.VirtualVerse)1 BIBLEBOOK (biblemulticonverter.schema.haggai.BIBLEBOOK)1 CAPTION (biblemulticonverter.schema.haggai.CAPTION)1 CHAPTER (biblemulticonverter.schema.haggai.CHAPTER)1 INFORMATION (biblemulticonverter.schema.haggai.INFORMATION)1 ObjectFactory (biblemulticonverter.schema.haggai.ObjectFactory)1 PROLOG (biblemulticonverter.schema.haggai.PROLOG)1 STYLE (biblemulticonverter.schema.haggai.STYLE)1 VERSE (biblemulticonverter.schema.haggai.VERSE)1 File (java.io.File)1 BigInteger (java.math.BigInteger)1 Pattern (java.util.regex.Pattern)1