use of biblemulticonverter.schema.zef2005.ObjectFactory in project cxf by apache.
the class AbstractTypeTestClient2 method testStructWithSubstitutionGroup.
@Test
public void testStructWithSubstitutionGroup() throws Exception {
if (!shouldRunTest("StructWithSubstitutionGroup")) {
return;
}
SgBaseTypeA baseA = new SgBaseTypeA();
baseA.setVarInt(new BigInteger("1"));
SgDerivedTypeB derivedB = new SgDerivedTypeB();
derivedB.setVarInt(new BigInteger("32"));
derivedB.setVarString("foo");
ObjectFactory objectFactory = new ObjectFactory();
StructWithSubstitutionGroup x = new StructWithSubstitutionGroup();
JAXBElement<? extends SgBaseTypeA> elementA = objectFactory.createSg01BaseElementA(baseA);
x.setSg01BaseElementA(elementA);
StructWithSubstitutionGroup yOrig = new StructWithSubstitutionGroup();
JAXBElement<? extends SgBaseTypeA> elementB = objectFactory.createSg01DerivedElementB(derivedB);
yOrig.setSg01BaseElementA(elementB);
Holder<StructWithSubstitutionGroup> y = new Holder<StructWithSubstitutionGroup>(yOrig);
Holder<StructWithSubstitutionGroup> z = new Holder<StructWithSubstitutionGroup>();
StructWithSubstitutionGroup ret;
if (testDocLiteral) {
ret = docClient.testStructWithSubstitutionGroup(x, y, z);
} else if (testXMLBinding) {
ret = xmlClient.testStructWithSubstitutionGroup(x, y, z);
} else {
ret = rpcClient.testStructWithSubstitutionGroup(x, y, z);
}
if (!perfTestOnly) {
assertTrue("testStructWithSubstitutionGroup(): Incorrect value for inout param", equals(x, y.value));
assertTrue("testStructWithSubstitutionGroup(): Incorrect value for out param", equals(yOrig, z.value));
assertTrue("testStructWithSubstitutionGroup(): Incorrect return value", equals(x, ret));
}
}
use of biblemulticonverter.schema.zef2005.ObjectFactory in project BibleMultiConverter by schierlm.
the class ZefDic method createXMLBible.
protected Dictionary createXMLBible(Bible bible) throws Exception {
final ObjectFactory of = new ObjectFactory();
Dictionary doc = of.createDictionary();
doc.setDicversion("1");
doc.setRevision("1");
doc.setRefbible("any");
doc.setType(TEnumDicType.X_DICTIONARY);
String title = null;
if (bible.getName().matches("X_(DICTIONARY|COMMENTARY|STRONG|DAILY)@.*")) {
String[] parts = bible.getName().split("@", 2);
doc.setType(TEnumDicType.valueOf(parts[0]));
doc.setRefbible(parts[1]);
} else {
title = bible.getName();
}
doc.setINFORMATION(of.createTINFORMATION());
doc.getINFORMATION().getTitleOrCreatorOrDescription().add(new JAXBElement<String>(new QName("title"), String.class, title));
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.version.toString())) {
doc.setDicversion(value);
} else if (key.equals(MetadataBookKey.revision.toString())) {
doc.setRevision(value);
} else if (Arrays.asList(INFORMATION_KEYS).contains(key)) {
doc.getINFORMATION().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().equals(BookID.DICTIONARY_ENTRY)) {
System.out.println("WARNING: Unable to export book " + bk.getAbbr());
continue;
}
final TItem item = of.createTItem();
if (!bk.getLongName().equals(bk.getShortName())) {
TItem itm = of.createTItem();
itm.setId(bk.getShortName());
appendTextElement(itm, "title", bk.getLongName());
TParagraph para2 = of.createTParagraph();
SeeType see = of.createSeeType();
see.setContent(bk.getLongName());
para2.getContent().add(new JAXBElement<SeeType>(new QName("see"), SeeType.class, see));
itm.getContent().add(new JAXBElement<TParagraph>(new QName("description"), TParagraph.class, para2));
doc.getItem().add(itm);
}
item.setId(bk.getLongName());
doc.getItem().add(item);
class ZefState {
TParagraph para = of.createTParagraph();
boolean eatParagraph = false;
public void flushPara(TItem item) {
item.getContent().add(new JAXBElement<TParagraph>(new QName("description"), TParagraph.class, para));
para = of.createTParagraph();
}
}
final ZefState state = new ZefState();
FormattedText text = bk.getChapters().get(0).getProlog();
class LevelVisitor implements Visitor<RuntimeException> {
final List<Serializable> target;
private LevelVisitor(ZefState state) {
target = state.para.getContent();
}
private LevelVisitor(MyAnyType parent) {
target = parent.getContent();
}
private LevelVisitor(TStyle parent) {
target = parent.getContent();
}
@Override
public int visitElementTypes(String elementTypes) throws RuntimeException {
return 0;
}
@Override
public Visitor<RuntimeException> visitHeadline(int depth) throws RuntimeException {
System.out.println("WARNING: Nested headlines are not supported");
return null;
}
@Override
public void visitStart() throws RuntimeException {
}
@Override
public void visitText(String text) throws RuntimeException {
if (text.length() > 0)
target.add(text);
}
@Override
public Visitor<RuntimeException> visitFootnote() throws RuntimeException {
System.out.println("WARNING: footnotes are not supported");
return null;
}
@Override
public Visitor<RuntimeException> visitCrossReference(String bookAbbr, BookID book, int firstChapter, String firstVerse, int lastChapter, String lastVerse) throws RuntimeException {
if (firstChapter != lastChapter || !firstVerse.equals(lastVerse))
System.out.println("WARNING: Cross references to verse ranges are not supported");
BibLinkType b = of.createBibLinkType();
b.setBn("" + book.getZefID());
b.setCn1("" + firstChapter);
b.setVn1(firstVerse);
target.add(new JAXBElement<BibLinkType>(new QName("bib_link"), BibLinkType.class, b));
return null;
}
@Override
public Visitor<RuntimeException> visitFormattingInstruction(FormattingInstructionKind kind) throws RuntimeException {
String tag;
switch(kind) {
case BOLD:
tag = "strong";
break;
case ITALIC:
tag = "em";
break;
case SUPERSCRIPT:
tag = "sup";
break;
case SUBSCRIPT:
tag = "sub";
break;
default:
return visitCSSFormatting(kind.getCss());
}
MyAnyType mat = of.createMyAnyType();
target.add(new JAXBElement<MyAnyType>(new QName(tag), MyAnyType.class, mat));
return new LevelVisitor(mat);
}
@Override
public Visitor<RuntimeException> visitCSSFormatting(String css) throws RuntimeException {
TStyle style = of.createTStyle();
style.setCss(css);
target.add(of.createTStyleSTYLE(style));
return new LevelVisitor(style);
}
@Override
public void visitVerseSeparator() throws RuntimeException {
System.out.println("WARNING: Verse separators are not supported");
}
@Override
public void visitLineBreak(LineBreakKind kind) throws RuntimeException {
System.out.println("WARNING: Nested line breaks are not supported");
}
@Override
public Visitor<RuntimeException> visitGrammarInformation(int[] strongs, String[] rmac, int[] sourceIndices) throws RuntimeException {
System.out.println("WARNING: Grammar information is not supported");
return null;
}
@Override
public Visitor<RuntimeException> visitDictionaryEntry(String dictionary, String entry) throws RuntimeException {
if (dictionary.equals("reflink")) {
RefLinkType r = of.createRefLinkType();
r.setMscope(entry.substring(1).replace('-', ';'));
target.add(new JAXBElement<RefLinkType>(new QName("reflink"), RefLinkType.class, r));
} else {
SeeType see = of.createSeeType();
see.setTarget(dictionary.equals("dict") ? "x-self" : dictionary);
see.setContent(entry);
target.add(new JAXBElement<SeeType>(new QName("see"), SeeType.class, see));
}
return null;
}
@Override
public void visitRawHTML(RawHTMLMode mode, String raw) throws RuntimeException {
System.out.println("WARNING: Raw html output not supported");
}
@Override
public Visitor<RuntimeException> visitVariationText(String[] variations) throws RuntimeException {
throw new IllegalStateException("Variations not supported");
}
@Override
public Visitor<RuntimeException> visitExtraAttribute(ExtraAttributePriority prio, String category, String key, String value) throws RuntimeException {
return prio.handleVisitor(category, this);
}
@Override
public boolean visitEnd() throws RuntimeException {
return false;
}
}
;
text.accept(new Visitor<RuntimeException>() {
@Override
public int visitElementTypes(String elementTypes) throws RuntimeException {
return 0;
}
@Override
public Visitor<RuntimeException> visitHeadline(int depth) throws RuntimeException {
MyAnyType mat = of.createMyAnyType();
JAXBElement<MyAnyType> elem = new JAXBElement<>(new QName("title"), MyAnyType.class, mat);
if (depth == 1) {
state.flushPara(item);
item.getContent().add(elem);
} else {
state.para.getContent().add(elem);
}
return new LevelVisitor(mat);
}
@Override
public void visitStart() throws RuntimeException {
}
@Override
public void visitText(String text) throws RuntimeException {
new LevelVisitor(state).visitText(text);
}
@Override
public Visitor<RuntimeException> visitFootnote() throws RuntimeException {
System.out.println("WARNING: footnotes are not supported");
return null;
}
@Override
public Visitor<RuntimeException> visitCrossReference(String bookAbbr, BookID book, int firstChapter, String firstVerse, int lastChapter, String lastVerse) throws RuntimeException {
return new LevelVisitor(state).visitCrossReference(bookAbbr, book, firstChapter, firstVerse, lastChapter, lastVerse);
}
@Override
public Visitor<RuntimeException> visitFormattingInstruction(FormattingInstructionKind kind) throws RuntimeException {
return new LevelVisitor(state).visitFormattingInstruction(kind);
}
@Override
public Visitor<RuntimeException> visitCSSFormatting(String css) throws RuntimeException {
return new LevelVisitor(state).visitCSSFormatting(css);
}
@Override
public void visitVerseSeparator() throws RuntimeException {
System.out.println("WARNING: Verse separators are not supported");
}
@Override
public void visitLineBreak(LineBreakKind kind) throws RuntimeException {
if (state.eatParagraph) {
state.eatParagraph = false;
} else {
state.flushPara(item);
state.para = of.createTParagraph();
}
}
@Override
public Visitor<RuntimeException> visitGrammarInformation(int[] strongs, String[] rmac, int[] sourceIndices) throws RuntimeException {
System.out.println("WARNING: Grammar information is not supported");
return null;
}
@Override
public Visitor<RuntimeException> visitDictionaryEntry(String dictionary, String entry) throws RuntimeException {
return new LevelVisitor(state).visitDictionaryEntry(dictionary, entry);
}
@Override
public void visitRawHTML(RawHTMLMode mode, String raw) throws RuntimeException {
System.out.println("WARNING: Raw html output not supported");
}
@Override
public Visitor<RuntimeException> visitVariationText(String[] variations) throws RuntimeException {
throw new IllegalStateException("Variations not supported");
}
@Override
public Visitor<RuntimeException> visitExtraAttribute(ExtraAttributePriority prio, String category, String key, String value) throws RuntimeException {
if (prio == ExtraAttributePriority.KEEP_CONTENT && category.equals("zefdic")) {
// "zefdic", "field", "pronunciation");
return null;
} else {
return prio.handleVisitor(category, this);
}
}
@Override
public boolean visitEnd() throws RuntimeException {
return false;
}
});
state.flushPara(item);
}
return doc;
}
use of biblemulticonverter.schema.zef2005.ObjectFactory in project BibleMultiConverter by schierlm.
the class ZefDicMyBible method createXMLBible.
protected Dictionary createXMLBible(Bible bible, String[] idfields) throws Exception {
final ObjectFactory of = new ObjectFactory();
Dictionary doc = of.createDictionary();
doc.setRevision("1");
doc.setINFORMATION(of.createTINFORMATION());
doc.getINFORMATION().getTitleOrCreatorOrDescription().add(of.createTINFORMATIONTitle(bible.getName()));
Map<String, String> xrefMap = new HashMap<String, String>();
if (!idfields[0].equals("abbr")) {
for (Book bk : bible.getBooks()) {
String value;
switch(idfields[0].toLowerCase()) {
case "abbr":
value = bk.getAbbr();
break;
case "short":
value = bk.getShortName();
break;
case "long":
value = bk.getLongName();
break;
default:
value = null;
}
if (value != null && !value.equals(bk.getAbbr())) {
xrefMap.put(bk.getAbbr(), value);
}
}
}
for (Book bk : bible.getBooks()) {
if (bk.getId().equals(BookID.METADATA))
continue;
if (!bk.getId().equals(BookID.DICTIONARY_ENTRY)) {
System.out.println("WARNING: Unable to export book " + bk.getAbbr());
continue;
}
List<String> ids = new ArrayList<>();
for (String idfield : idfields) {
String value;
switch(idfield.toLowerCase()) {
case "abbr":
value = bk.getAbbr();
break;
case "short":
value = bk.getShortName();
break;
case "long":
value = bk.getLongName();
break;
default:
continue;
}
if (!ids.contains(value))
ids.add(value);
}
if (ids.isEmpty()) {
System.out.println("WARNING: Skipping book " + bk.getAbbr() + "due to missing ID.");
continue;
}
for (int i = 1; i < ids.size(); i++) {
TItem item = of.createTItem();
item.setId(ids.get(i));
TParagraph para = of.createTParagraph();
SeeType see = of.createSeeType();
see.setContent(ids.get(0));
para.getContent().add(of.createSee(see));
item.getContent().add(of.createTParagraphDescription(para));
doc.getItem().add(item);
}
final TItem item = of.createTItem();
item.setId(ids.get(0));
doc.getItem().add(item);
TParagraph description = of.createTParagraph();
item.getContent().add(of.createTParagraphDescription(description));
bk.getChapters().get(0).getProlog().accept(new ZefDicVisitor(description.getContent(), xrefMap));
}
return doc;
}
use of biblemulticonverter.schema.zef2005.ObjectFactory in project BibleMultiConverter by schierlm.
the class ZefaniaXMLMyBible method doExport.
@Override
public void doExport(Bible bible, String... exportArgs) throws Exception {
new StrippedDiffable().mergeIntroductionPrologs(bible);
final ObjectFactory f = new ObjectFactory();
XMLBIBLE doc = f.createXMLBIBLE();
doc.setBiblename(bible.getName());
doc.setType(EnumModtyp.X_BIBLE);
BigInteger revision = null;
MetadataBook metadata = bible.getMetadataBook();
if (metadata != null) {
for (MetadataBookKey key : Arrays.asList(MetadataBookKey.revision, MetadataBookKey.version, MetadataBookKey.date, MetadataBookKey.title)) {
String digits = metadata.getValue(key);
if (digits == null)
continue;
digits = digits.replaceAll("[^0-9]+", "");
if (!digits.isEmpty()) {
revision = new BigInteger(digits);
break;
}
}
}
if (revision == null) {
String digits = bible.getName().replaceAll("[^0-9]+", "");
if (!digits.isEmpty()) {
revision = new BigInteger(digits);
}
}
if (revision != null) {
doc.setRevision(revision);
}
doc.setINFORMATION(f.createINFORMATION());
List<DIV> prologs = new ArrayList<DIV>();
for (Book bk : bible.getBooks()) {
if (bk.getId().equals(BookID.METADATA))
continue;
int bsnumber = bk.getId().getZefID();
final BIBLEBOOK book = f.createBIBLEBOOK();
book.setBnumber(BigInteger.valueOf(bsnumber));
book.setBname(bk.getShortName());
book.setBsname(bk.getAbbr());
doc.getBIBLEBOOK().add(book);
int cnumber = 0;
for (Chapter cch : bk.getChapters()) {
cnumber++;
if (cch.getProlog() != null) {
DIV xx = f.createDIV();
prologs.add(xx);
NOTE xxx = f.createNOTE();
xx.setNOTE(xxx);
xxx.setType("x-studynote");
NOTE prolog = xxx;
DIV vers = f.createDIV();
prolog.getContent().add("<p>");
prolog.getContent().add(vers);
prolog.getContent().add("</p>");
vers.setNOTE(f.createNOTE());
final List<List<Object>> targetStack = new ArrayList<List<Object>>();
targetStack.add(vers.getNOTE().getContent());
cch.getProlog().accept(new Visitor<IOException>() {
@Override
public Visitor<IOException> visitHeadline(int depth) throws IOException {
if (depth > 6)
depth = 6;
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
targetStack.get(0).add("<h" + depth + ">");
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
targetStack.get(0).add("</h" + depth + ">");
targetStack.add(0, s.getContent());
return this;
}
@Override
public void visitVerseSeparator() throws IOException {
STYLE x = f.createSTYLE();
x.setCss("color:gray");
x.getContent().add("/");
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, x));
}
@Override
public void visitText(String text) throws IOException {
targetStack.get(0).add(text);
}
@Override
public Visitor<IOException> visitFormattingInstruction(FormattedText.FormattingInstructionKind kind) throws IOException {
String startTag, endTag;
if (kind.getHtmlTag() != null) {
startTag = "<" + kind.getHtmlTag() + ">";
endTag = "</" + kind.getHtmlTag() + ">";
} else {
startTag = "<span style=\"" + kind.getCss() + "\">";
endTag = "</span>";
}
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
targetStack.get(0).add(startTag);
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
targetStack.get(0).add(endTag);
targetStack.add(0, s.getContent());
return this;
}
@Override
public Visitor<IOException> visitFootnote() throws IOException {
System.out.println("WARNING: Footnotes in prolog are not supported");
return null;
}
@Override
public Visitor<IOException> visitCrossReference(String bookAbbr, BookID book, int firstChapter, String firstVerse, int lastChapter, String lastVerse) throws IOException {
System.out.println("WARNING: Cross references in prologs are not supported");
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
targetStack.add(0, s.getContent());
return this;
}
@Override
public Visitor<IOException> visitVariationText(String[] variations) throws IOException {
throw new RuntimeException("Variations not supported");
}
@Override
public void visitLineBreak(LineBreakKind kind) throws IOException {
BR br = f.createBR();
br.setArt(kind == LineBreakKind.PARAGRAPH ? EnumBreak.X_P : EnumBreak.X_NL);
targetStack.get(0).add(" ");
targetStack.get(0).add(kind == LineBreakKind.PARAGRAPH ? "<p>" : "<br>");
targetStack.get(0).add(br);
}
@Override
public Visitor<IOException> visitGrammarInformation(int[] strongs, String[] rmac, int[] sourceIndices) throws IOException {
throw new RuntimeException("Grammar tags in prologs not supported");
}
@Override
public FormattedText.Visitor<IOException> visitDictionaryEntry(String dictionary, String entry) throws IOException {
throw new RuntimeException("Dictionary entries in prologs not supported");
}
@Override
public void visitRawHTML(RawHTMLMode mode, String raw) throws IOException {
throw new RuntimeException("Raw HTML in prologs not supported");
}
@Override
public Visitor<IOException> visitCSSFormatting(String css) throws IOException {
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
targetStack.get(0).add("<span style=\"" + css + "\">");
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
targetStack.get(0).add("</span>");
targetStack.add(0, s.getContent());
return this;
}
@Override
public int visitElementTypes(String elementTypes) throws IOException {
return 0;
}
@Override
public Visitor<IOException> visitExtraAttribute(ExtraAttributePriority prio, String category, String key, String value) throws IOException {
if (prio == ExtraAttributePriority.KEEP_CONTENT)
return visitCSSFormatting("-zef-extra-attribute-" + category + "-" + key + ": " + value);
else if (prio == ExtraAttributePriority.SKIP)
return null;
throw new RuntimeException("Extra attributes not supported");
}
@Override
public void visitStart() throws IOException {
}
@Override
public boolean visitEnd() throws IOException {
targetStack.remove(0);
return false;
}
});
if (targetStack.size() != 0)
throw new RuntimeException();
}
if (cch.getVerses().size() == 0)
continue;
CHAPTER chapter = f.createCHAPTER();
chapter.setCnumber(BigInteger.valueOf(cnumber));
book.getCHAPTER().add(chapter);
for (VirtualVerse vv : cch.createVirtualVerses()) {
for (Headline h : vv.getHeadlines()) {
CAPTION caption = f.createCAPTION();
EnumCaptionType[] types = new EnumCaptionType[] { null, EnumCaptionType.X_H_1, EnumCaptionType.X_H_2, EnumCaptionType.X_H_3, EnumCaptionType.X_H_4, EnumCaptionType.X_H_5, EnumCaptionType.X_H_6, EnumCaptionType.X_H_6, EnumCaptionType.X_H_6, EnumCaptionType.X_H_6 };
caption.setType(types[h.getDepth()]);
caption.setVref(BigInteger.valueOf(vv.getNumber()));
final StringBuilder sb = new StringBuilder();
h.accept(new FormattedText.VisitorAdapter<RuntimeException>(null) {
@Override
protected void beforeVisit() throws RuntimeException {
throw new IllegalStateException();
}
@Override
public Visitor<RuntimeException> visitFormattingInstruction(FormattingInstructionKind kind) throws RuntimeException {
System.out.println("WARNING: Formatting instructions in captions are not supported (stripped)");
return this;
}
@Override
public Visitor<RuntimeException> visitFootnote() throws RuntimeException {
System.out.println("WARNING: Footnotes in captions are not supported (stripped)");
return null;
}
@Override
public Visitor<RuntimeException> visitCSSFormatting(String css) throws RuntimeException {
System.out.println("WARNING: CSS Formatting in captions are not supported (stripped)");
return this;
}
@Override
public Visitor<RuntimeException> visitExtraAttribute(ExtraAttributePriority prio, String category, String key, String value) throws RuntimeException {
return prio.handleVisitor(category, this);
}
public void visitText(String text) throws RuntimeException {
sb.append(text);
}
});
caption.getContent().add(sb.toString());
chapter.getPROLOGOrCAPTIONOrVERS().add(caption);
}
VERS vers = f.createVERS();
vers.setVnumber(BigInteger.valueOf(vv.getNumber()));
for (DIV prolog : prologs) {
vers.getContent().add(prolog);
}
prologs.clear();
chapter.getPROLOGOrCAPTIONOrVERS().add(vers);
boolean first = true;
for (Verse v : vv.getVerses()) {
if (!first || !v.getNumber().equals("" + vv.getNumber())) {
STYLE x = f.createSTYLE();
x.setCss("font-weight: bold");
x.getContent().add("(" + v.getNumber() + ")");
vers.getContent().add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, x));
vers.getContent().add(" ");
}
first = false;
final List<List<Object>> targetStack = new ArrayList<List<Object>>();
targetStack.add(vers.getContent());
v.accept(new FormattedText.Visitor<IOException>() {
@Override
public void visitVerseSeparator() throws IOException {
STYLE x = f.createSTYLE();
x.setCss("color:gray");
x.getContent().add("/");
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, x));
}
@Override
public void visitText(String text) throws IOException {
targetStack.get(0).add(text);
}
@Override
public FormattedText.Visitor<IOException> visitFormattingInstruction(biblemulticonverter.data.FormattedText.FormattingInstructionKind kind) throws IOException {
STYLE x = f.createSTYLE();
x.setCss(kind.getCss());
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, x));
targetStack.add(0, x.getContent());
return this;
}
@Override
public Visitor<IOException> visitFootnote() throws IOException {
DIV x = f.createDIV();
targetStack.get(0).add(x);
NOTE n = f.createNOTE();
x.setNOTE(n);
n.setType("x-studynote");
final List<List<Object>> footnoteStack = new ArrayList<List<Object>>();
footnoteStack.add(n.getContent());
return new Visitor<IOException>() {
@Override
public void visitStart() throws IOException {
}
@Override
public void visitVerseSeparator() throws IOException {
STYLE x = f.createSTYLE();
x.setCss("color:gray");
x.getContent().add("/");
footnoteStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, x));
}
@Override
public void visitText(String text) throws IOException {
footnoteStack.get(0).add(text);
}
@Override
public void visitLineBreak(LineBreakKind kind) throws IOException {
BR br = f.createBR();
br.setArt(kind == LineBreakKind.PARAGRAPH ? EnumBreak.X_P : EnumBreak.X_NL);
footnoteStack.get(0).add(" ");
footnoteStack.get(0).add(br);
}
@Override
public Visitor<IOException> visitFormattingInstruction(FormattedText.FormattingInstructionKind kind) throws IOException {
String startTag, endTag;
if (kind.getHtmlTag() != null) {
startTag = "<" + kind.getHtmlTag() + ">";
endTag = "</" + kind.getHtmlTag() + ">";
} else {
startTag = "<span style=\"" + kind.getCss() + "\">";
endTag = "</span>";
}
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
footnoteStack.get(0).add(startTag);
footnoteStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
footnoteStack.get(0).add(endTag);
footnoteStack.add(0, s.getContent());
return this;
}
@Override
public Visitor<IOException> visitFootnote() throws IOException {
throw new RuntimeException("Footnotes in footnotes are not supported");
}
@Override
public Visitor<IOException> visitGrammarInformation(int[] strongs, String[] rmac, int[] sourceIndices) throws IOException {
GRAM gram = f.createGRAM();
if (strongs != null) {
StringBuilder entryBuilder = new StringBuilder();
for (int i = 0; i < strongs.length; i++) {
entryBuilder.append((i > 0 ? " " : "") + strongs[i]);
}
String entry = entryBuilder.toString();
gram.setStr(entry);
}
if (rmac != null) {
StringBuilder entryBuilder = new StringBuilder();
for (int i = 0; i < rmac.length; i++) {
if (i > 0)
entryBuilder.append(' ');
entryBuilder.append(rmac[i]);
}
gram.setRmac(entryBuilder.toString());
}
footnoteStack.get(0).add(new JAXBElement<GRAM>(new QName("gr"), GRAM.class, gram));
footnoteStack.add(0, gram.getContent());
return this;
}
@Override
public FormattedText.Visitor<IOException> visitDictionaryEntry(String dictionary, String entry) throws IOException {
GRAM gram = f.createGRAM();
gram.setStr(entry);
footnoteStack.get(0).add(new JAXBElement<GRAM>(new QName("gr"), GRAM.class, gram));
footnoteStack.add(0, gram.getContent());
return this;
}
@Override
public void visitRawHTML(RawHTMLMode mode, String raw) throws IOException {
if (mode != RawHTMLMode.ONLINE)
footnoteStack.get(0).add(raw);
}
@Override
public Visitor<IOException> visitVariationText(String[] variations) throws IOException {
throw new RuntimeException("Variations not supported");
}
@Override
public FormattedText.Visitor<IOException> visitCrossReference(String bookAbbr, BookID book, int firstChapter, String firstVerse, int lastChapter, String lastVerse) throws IOException {
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
int bookID = book.getZefID();
String mscope, xmscope;
try {
int start = firstVerse.equals("^") ? 1 : Integer.parseInt(firstVerse.replaceAll("[a-zG]|[,/][0-9]*", ""));
int end;
if (firstChapter == lastChapter && !lastVerse.equals("$")) {
end = Integer.parseInt(lastVerse.replaceAll("[a-z]|[,/][0-9]*", ""));
} else {
end = -1;
}
mscope = bookID + "," + firstChapter + "," + start + "," + end;
xmscope = bookID + ";" + firstChapter + ";" + start + "-" + end;
} catch (NumberFormatException ex) {
ex.printStackTrace();
mscope = bookID + ",1,1,999";
xmscope = bookID + ";1;1-999";
}
if (footnoteStack.size() == 1) {
List<Object> outerList = targetStack.get(0);
XREF xref = new XREF();
xref.setMscope(xmscope);
outerList.add(outerList.size() - 1, xref);
}
footnoteStack.get(0).add("<a href=\"mybible:content=location&locations=" + mscope + "\">");
footnoteStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
footnoteStack.get(0).add("</a>");
footnoteStack.add(0, s.getContent());
return this;
}
public boolean visitEnd() throws IOException {
footnoteStack.remove(0);
return false;
}
@Override
public int visitElementTypes(String elementTypes) throws IOException {
return 0;
}
@Override
public Visitor<IOException> visitHeadline(int depth) throws IOException {
throw new RuntimeException("Headlines in footnotes not supported");
}
@Override
public Visitor<IOException> visitCSSFormatting(String css) throws IOException {
STYLE s = f.createSTYLE();
s.setCss("-zef-dummy: true");
footnoteStack.get(0).add("<span style=\"" + css + "\">");
footnoteStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, s));
footnoteStack.get(0).add("</span>");
footnoteStack.add(s.getContent());
return this;
}
@Override
public Visitor<IOException> visitExtraAttribute(ExtraAttributePriority prio, String category, String key, String value) throws IOException {
System.out.println("WARNING: Extra attributes not supported");
Visitor<IOException> result = prio.handleVisitor(category, this);
if (result != null)
footnoteStack.add(0, footnoteStack.get(0));
return result;
}
};
}
@Override
public FormattedText.Visitor<IOException> visitCrossReference(String bookAbbr, BookID book, int firstChapter, String firstVerse, int lastChapter, String lastVerse) throws IOException {
throw new RuntimeException("Xref outside of footnotes not supported!");
}
@Override
public void visitLineBreak(LineBreakKind kind) throws IOException {
BR br = f.createBR();
br.setArt(kind == LineBreakKind.PARAGRAPH ? EnumBreak.X_P : EnumBreak.X_NL);
targetStack.get(0).add(" ");
targetStack.get(0).add(br);
}
@Override
public Visitor<IOException> visitGrammarInformation(int[] strongs, String[] rmac, int[] sourceIndices) throws IOException {
GRAM gram = f.createGRAM();
if (strongs != null) {
StringBuilder entryBuilder = new StringBuilder();
for (int i = 0; i < strongs.length; i++) {
entryBuilder.append((i > 0 ? " " : "") + strongs[i]);
}
String entry = entryBuilder.toString();
gram.setStr(entry);
}
if (rmac != null) {
StringBuilder entryBuilder = new StringBuilder();
for (int i = 0; i < rmac.length; i++) {
if (i > 0)
entryBuilder.append(' ');
entryBuilder.append(rmac[i]);
}
gram.setRmac(entryBuilder.toString());
}
targetStack.get(0).add(new JAXBElement<GRAM>(new QName("gr"), GRAM.class, gram));
targetStack.add(0, gram.getContent());
return this;
}
@Override
public FormattedText.Visitor<IOException> visitDictionaryEntry(String dictionary, String entry) throws IOException {
GRAM gram = f.createGRAM();
gram.setStr(entry);
targetStack.get(0).add(new JAXBElement<GRAM>(new QName("gr"), GRAM.class, gram));
targetStack.add(0, gram.getContent());
return this;
}
@Override
public void visitRawHTML(RawHTMLMode mode, String raw) throws IOException {
throw new RuntimeException("Raw HTML is not supported");
}
@Override
public Visitor<IOException> visitVariationText(String[] variations) throws IOException {
throw new RuntimeException("Variations not supported");
}
@Override
public boolean visitEnd() throws IOException {
targetStack.remove(0);
return false;
}
@Override
public int visitElementTypes(String elementTypes) throws IOException {
return 0;
}
@Override
public Visitor<IOException> visitHeadline(int depth) throws IOException {
throw new RuntimeException("Headline in virtual verse is impossible");
}
@Override
public void visitStart() throws IOException {
}
@Override
public Visitor<IOException> visitCSSFormatting(String css) throws IOException {
STYLE x = f.createSTYLE();
x.setCss(css);
targetStack.get(0).add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, x));
targetStack.add(0, x.getContent());
return this;
}
@Override
public Visitor<IOException> visitExtraAttribute(ExtraAttributePriority prio, String category, String key, String value) throws IOException {
System.out.println("WARNING: Extra attributes not supported");
Visitor<IOException> result = prio.handleVisitor(category, this);
if (result != null)
targetStack.add(0, targetStack.get(0));
return result;
}
});
if (targetStack.size() != 0)
throw new RuntimeException();
}
}
}
if (book.getCHAPTER().size() == 0) {
doc.getBIBLEBOOK().remove(book);
}
}
final Document docc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
JAXBContext.newInstance(ObjectFactory.class.getPackage().getName()).createMarshaller().marshal(doc, docc);
docc.getDocumentElement().setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
docc.getDocumentElement().setAttribute("xsi:noNamespaceSchemaLocation", "zef2005.xsd");
docc.normalize();
maskWhitespaceNodes(docc.getDocumentElement());
try (FileOutputStream fos = new FileOutputStream(exportArgs[0])) {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(new DOMSource(docc), new StreamResult(fos));
}
}
use of biblemulticonverter.schema.zef2005.ObjectFactory in project BibleMultiConverter by schierlm.
the class ZefaniaXMLRoundtrip method createXMLBible.
protected XMLBIBLE createXMLBible(Bible bible) throws Exception {
ObjectFactory of = new ObjectFactory();
XMLBIBLE doc = of.createXMLBIBLE();
doc.setBiblename(bible.getName());
doc.setType(EnumModtyp.X_BIBLE);
doc.setINFORMATION(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(EnumStatus.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 (Arrays.asList(INFORMATION_KEYS).contains(key)) {
doc.getINFORMATION().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;
}
String shortname = removeRoundtripMarker(bk.getShortName());
String longname = removeRoundtripMarker(bk.getLongName());
BookID bookID = bk.getId();
BIBLEBOOK bb = of.createBIBLEBOOK();
bb.setBnumber(BigInteger.valueOf(bookID.getZefID()));
if (!shortname.equals("_" + bookID.getOsisID()))
bb.setBsname(shortname);
if (!longname.equals("_" + bookID.getEnglishName()))
bb.setBname(longname);
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.getCHAPTER().add(cc);
if (ccc.getProlog() != null) {
PROLOG prolog = of.createPROLOG();
prolog.setVref(BigInteger.ONE);
ccc.getProlog().accept(new CreateContentVisitor(of, prolog.getContent(), null, 0, null));
cc.getPROLOGOrCAPTIONOrVERS().add(prolog);
}
for (VirtualVerse vv : ccc.createVirtualVerses()) {
for (Headline h : vv.getHeadlines()) {
CAPTION caption = of.createCAPTION();
caption.setVref(BigInteger.valueOf(vv.getNumber()));
h.accept(new CreateContentVisitor(of, caption.getContent(), null, 0, null));
EnumCaptionType[] types = new EnumCaptionType[] { null, EnumCaptionType.X_H_1, EnumCaptionType.X_H_2, EnumCaptionType.X_H_3, EnumCaptionType.X_H_4, EnumCaptionType.X_H_5, EnumCaptionType.X_H_6, null, null, null };
caption.setType(types[h.getDepth()]);
cc.getPROLOGOrCAPTIONOrVERS().add(caption);
}
List<Object> remarksAndXrefs = new ArrayList<Object>();
VERS vers = of.createVERS();
vers.setVnumber(BigInteger.valueOf(vv.getNumber()));
for (Verse v : vv.getVerses()) {
if (!v.getNumber().equals("" + vv.getNumber())) {
STYLE verseNum = of.createSTYLE();
verseNum.setCss("font-weight: 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(), remarksAndXrefs, vv.getNumber(), null));
}
cc.getPROLOGOrCAPTIONOrVERS().add(vers);
cc.getPROLOGOrCAPTIONOrVERS().addAll(remarksAndXrefs);
}
}
doc.getBIBLEBOOK().add(bb);
}
return doc;
}
Aggregations