ソースを参照

add method to normalize verses

Pi 2 年 前
コミット
07f2d77891
1 ファイル変更13 行追加3 行削除
  1. 13 3
      src/main/java/PlJavaJSword.java

+ 13 - 3
src/main/java/PlJavaJSword.java

@@ -2,6 +2,7 @@ package one.shandan;
 
 import java.lang.String;
 import java.lang.Boolean;
+import java.security.AccessControlException;
 import org.crosswire.jsword.passage.VerseRangeFactory;
 import org.crosswire.jsword.versification.system.SystemDefault;
 import org.crosswire.jsword.versification.BibleBook;
@@ -12,18 +13,27 @@ import org.crosswire.jsword.versification.system.Versifications;
 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");
 
-  @Function(language="javau", onNullInput=RETURNS_NULL, effects=IMMUTABLE)
+  @Function(onNullInput=RETURNS_NULL, effects=IMMUTABLE, trust=SANDBOXED)
   public static Boolean isValidVerse(String reference) {
     try {
       VerseRangeFactory.fromString(kjv, reference);
+      return true;
     } catch (NoSuchVerseException ex) {
-      return false;
     }
-    return true;
+    return false;
+  }
+  @Function(onNullInput=RETURNS_NULL, effects=IMMUTABLE, trust=SANDBOXED)
+  public static String normalizeVerse(String reference){
+    try {
+      return VerseRangeFactory.fromString(kjv, reference).getName();
+    } catch (NoSuchVerseException ex) {
+      return null;
+    }
   }
 }