|
@@ -2,7 +2,7 @@ package one.shandan;
|
|
|
|
|
|
import java.lang.String;
|
|
|
import java.lang.Boolean;
|
|
|
-import java.security.AccessControlException;
|
|
|
+import java.util.Iterator;
|
|
|
import org.crosswire.jsword.passage.VerseRangeFactory;
|
|
|
import org.crosswire.jsword.versification.system.SystemDefault;
|
|
|
import org.crosswire.jsword.versification.BibleBook;
|
|
@@ -10,13 +10,22 @@ import org.crosswire.jsword.versification.BibleNames;
|
|
|
import org.crosswire.jsword.passage.NoSuchVerseException;
|
|
|
import org.crosswire.jsword.versification.Versification;
|
|
|
import org.crosswire.jsword.versification.system.Versifications;
|
|
|
+import org.crosswire.jsword.book.Books;
|
|
|
+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.Content;
|
|
|
import org.postgresql.pljava.annotation.Function;
|
|
|
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;
|
|
|
|
|
|
public class PlJavaJSword {
|
|
|
- private static Versification kjv = Versifications.instance().getVersification("KJV");
|
|
|
+ private static final String DEFAULT_BOOK = "KJV";
|
|
|
+ private static final String DEFAULT_VERSIFICATION = "KJV";
|
|
|
+ private static final Versification kjv = Versifications.instance().getVersification(DEFAULT_VERSIFICATION);
|
|
|
+ private static final Books BOOKS = Books.installed();
|
|
|
|
|
|
@Function(onNullInput=RETURNS_NULL, effects=IMMUTABLE, trust=SANDBOXED)
|
|
|
public static Boolean isValidVerse(String reference) {
|
|
@@ -35,5 +44,39 @@ public class PlJavaJSword {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
+ @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;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Key key = book.getKey(reference);
|
|
|
+ String ret = "";
|
|
|
+ for (Iterator<Content> i = book.getOsisIterator(key, false, false); i.hasNext();){
|
|
|
+ ret = ret + i.next().getValue();
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ } catch (NoSuchKeyException ex){
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Key key = book.getKey(reference);
|
|
|
+ String ret = "";
|
|
|
+ for (Iterator<Content> i = book.getOsisIterator(key, false, false); i.hasNext();){
|
|
|
+ ret = ret + i.next().getValue();
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ } catch (NoSuchKeyException ex){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|