use of biblemulticonverter.schema.usfx.Usfx 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));
}
use of biblemulticonverter.schema.usfx.Usfx in project BibleMultiConverter by schierlm.
the class USFX method doImportAllBooks.
@Override
protected List<ParatextBook> doImportAllBooks(File inputFile) throws Exception {
ValidateXML.validateFileBeforeParsing(getSchema(), inputFile);
JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
Unmarshaller u = ctx.createUnmarshaller();
Usfx doc = (Usfx) u.unmarshal(inputFile);
List<ParatextBook> result = new ArrayList<ParatextBook>();
for (Serializable s : doc.getContent()) {
if (s instanceof String) {
if (!s.toString().trim().isEmpty()) {
System.out.println("WARNING: Skipping text outside of book: " + s);
}
} else if (s instanceof JAXBElement<?>) {
JAXBElement<?> elem = (JAXBElement<?>) s;
if (elem.getName().getLocalPart().equals("book")) {
Usfx.Book book = (Usfx.Book) elem.getValue();
ParatextBook bk = parseBook(book);
if (bk != null)
result.add(bk);
} else {
System.out.println("WARNING: Skipping unsupported tag outside of book: " + elem.getName());
}
} else {
System.out.println("WARNING: Skipping unsupported content outside of book " + s);
}
}
result.sort(Comparator.comparing(ParatextBook::getId));
return result;
}
Aggregations