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));
}
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);
}
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;
}
Aggregations