|
@@ -3,6 +3,8 @@ package one.shandan;
|
|
|
import java.lang.String;
|
|
|
import java.lang.Boolean;
|
|
|
import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.ArrayList;
|
|
|
import org.crosswire.jsword.passage.VerseRangeFactory;
|
|
|
import org.crosswire.jsword.versification.system.SystemDefault;
|
|
|
import org.crosswire.jsword.versification.BibleBook;
|
|
@@ -14,8 +16,14 @@ import org.crosswire.jsword.book.Book;
|
|
|
import org.crosswire.jsword.book.BookException;
|
|
|
import org.crosswire.jsword.passage.Key;
|
|
|
import org.crosswire.jsword.passage.NoSuchKeyException;
|
|
|
+import org.jdom2.Attribute;
|
|
|
+import org.jdom2.Element;
|
|
|
+import org.jdom2.Text;
|
|
|
import org.jdom2.Content;
|
|
|
+import org.jdom2.Content.CType;
|
|
|
import org.postgresql.pljava.annotation.Function;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import static org.postgresql.pljava.annotation.Function.Effects.IMMUTABLE;
|
|
|
import static org.postgresql.pljava.annotation.Function.OnNullInput.RETURNS_NULL;
|
|
|
import static org.postgresql.pljava.annotation.Function.Trust.SANDBOXED;
|
|
@@ -25,6 +33,7 @@ public class PlJavaJSword {
|
|
|
private static final String DEFAULT_VERSIFICATION = "KJV";
|
|
|
private static final Versification kjv = Versifications.instance().getVersification(DEFAULT_VERSIFICATION);
|
|
|
private static final Books BOOKS = Books.installed();
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(PlJavaJSword.class);
|
|
|
|
|
|
@Function(onNullInput=RETURNS_NULL, effects=IMMUTABLE, trust=SANDBOXED)
|
|
|
public static Boolean isValidVerse(String reference) {
|
|
@@ -43,42 +52,63 @@ public class PlJavaJSword {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
+ private static String parseVerse(Iterator<Content> content){
|
|
|
+ String verse = "";
|
|
|
+ while (content.hasNext()){
|
|
|
+ Content c = content.next();
|
|
|
+ if (c.getCType() == CType.Element){
|
|
|
+ Element e = (Element)c;
|
|
|
+ if (e.getName() != "note"){
|
|
|
+ verse += " " + e.getValue().trim();
|
|
|
+ } else {
|
|
|
+ verse += " ";
|
|
|
+ }
|
|
|
+ } else if (c.getCType() == CType.Text){
|
|
|
+ Text t = (Text)c;
|
|
|
+ verse += t.getValue().trim();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return verse.trim();
|
|
|
+ }
|
|
|
+ private static String parseContent(Iterator<Content> content)
|
|
|
+ {
|
|
|
+ List<String> ret = new ArrayList<String>();
|
|
|
+ while (content.hasNext()){
|
|
|
+ Content c = content.next();
|
|
|
+ if (c.getCType() == CType.Element){
|
|
|
+ Element e = (Element)c;
|
|
|
+ if (e.getName() == "verse"){
|
|
|
+ String part = parseVerse(e.getContent().listIterator());
|
|
|
+ ret.add(part);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return String.join(" ", ret);
|
|
|
+ }
|
|
|
@Function(onNullInput=RETURNS_NULL, effects=IMMUTABLE, trust=SANDBOXED)
|
|
|
public static String getText(String translation, String reference) throws BookException {
|
|
|
Book book = BOOKS.getBook(translation);
|
|
|
if (book == null){
|
|
|
- return null;
|
|
|
+ return null;
|
|
|
}
|
|
|
try {
|
|
|
- Key key = book.getKey(reference);
|
|
|
- String ret = "";
|
|
|
- Iterator<Content> i = book.getOsisIterator(key, false);
|
|
|
- i.next();
|
|
|
- while (i.hasNext()){
|
|
|
- ret = ret + " " + i.next().getValue().trim();
|
|
|
- }
|
|
|
- return ret.trim();
|
|
|
+ Key key = book.getKey(reference);
|
|
|
+ return parseContent(book.getOsisIterator(key, false));
|
|
|
} catch (NoSuchKeyException ex){
|
|
|
- return null;
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
@Function(onNullInput=RETURNS_NULL, effects=IMMUTABLE, trust=SANDBOXED)
|
|
|
public static String getDefaultText(String reference) throws BookException {
|
|
|
Book book = BOOKS.getBook(DEFAULT_BOOK);
|
|
|
if (book == null){
|
|
|
- return null;
|
|
|
+ return null;
|
|
|
}
|
|
|
try {
|
|
|
- Key key = book.getKey(reference);
|
|
|
- String ret = "";
|
|
|
- Iterator<Content> i = book.getOsisIterator(key, false);
|
|
|
- i.next();
|
|
|
- while (i.hasNext()){
|
|
|
- ret = ret + " " + i.next().getValue().trim();
|
|
|
- }
|
|
|
- return ret.trim();
|
|
|
+ Key key = book.getKey(reference);
|
|
|
+ return parseContent(book.getOsisIterator(key, false));
|
|
|
} catch (NoSuchKeyException ex){
|
|
|
- return null;
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
}
|