Search in sources :

Example 1 with ObjectFactory

use of biblemulticonverter.schema.usfx.ObjectFactory in project BibleMultiConverter by schierlm.

the class USFX method doExportBooks.

@Override
public void doExportBooks(List<ParatextBook> books, String... exportArgs) throws Exception {
    ObjectFactory of = new ObjectFactory();
    File file = new File(exportArgs[0]);
    Usfx usfx = of.createUsfx();
    for (ParatextBook book : books) {
        usfx.getContent().add(of.createUsfxBook(createBook(book)));
    }
    final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
    Marshaller m = ctx.createMarshaller();
    if (!Boolean.getBoolean("biblemulticonverter.skipxmlvalidation"))
        m.setSchema(getSchema());
    m.marshal(usfx, doc);
    doc.getDocumentElement().setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    doc.getDocumentElement().setAttribute("xsi:noNamespaceSchemaLocation", "usfx.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) ObjectFactory(biblemulticonverter.schema.usfx.ObjectFactory) StreamResult(javax.xml.transform.stream.StreamResult) Usfx(biblemulticonverter.schema.usfx.Usfx) JAXBContext(javax.xml.bind.JAXBContext) Document(org.w3c.dom.Document) File(java.io.File)

Aggregations

ObjectFactory (biblemulticonverter.schema.usfx.ObjectFactory)1 Usfx (biblemulticonverter.schema.usfx.Usfx)1 File (java.io.File)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 Transformer (javax.xml.transform.Transformer)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 Document (org.w3c.dom.Document)1