Selaa lähdekoodia

Initial commit

Daniel Sheffield 2 vuotta sitten
sitoutus
66755a2edd
3 muutettua tiedostoa jossa 151 lisäystä ja 0 poistoa
  1. 107 0
      pom.xml
  2. 29 0
      src/main/java/PlJavaJSword.java
  3. 15 0
      src/test/java/TestPlJavaJSword.java

+ 107 - 0
pom.xml

@@ -0,0 +1,107 @@
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation=
+ "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+>
+  <modelVersion>4.0.0</modelVersion>
+
+  <!-- Above is all boilerplate. Next: your project's "Maven coordinates" -->
+
+  <groupId>one.shandan</groupId>
+  <artifactId>pljava-jsword</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+
+  <!-- Coordinates are nice, but so are names and descriptions for humans. -->
+
+  <name>JSword for Postgresql</name>
+  <description>Provides postgresql functions for JSword</description>
+
+  <!--
+    Many Maven plugins care what character set encoding your files are in.
+    For this example I've chosen the most restrictive (US-ASCII). Change if
+    your files use a different encoding, but be sure not to lie. You should
+    be sure the encoding named here IS the way your source files are coded.
+  -->
+  
+  <properties>
+    <project.build.sourceEncoding>US-ASCII</project.build.sourceEncoding>
+  </properties>
+
+  <!-- Here's where you say your project depends on a pljava-api version. -->
+
+  <dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.36</version>
+    </dependency>
+    <dependency>
+      <groupId>org.postgresql</groupId>
+      <artifactId>pljava-api</artifactId>
+      <version>1.6.4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.crosswire</groupId>
+      <artifactId>jsword</artifactId>
+      <version>2.0-beta</version>
+      <scope>system</scope>
+      <systemPath>${pom.basedir}/lib/jsword-2.0-beta.jar</systemPath>
+    </dependency>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-engine</artifactId>
+      <version>5.3.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <!-- The rest here is pretty much boilerplate. -->
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.22.0</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.8.1</version>
+        <configuration>
+          <release>9</release>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>2.6</version>
+        <configuration>
+          <archive>
+            <manifest>
+              <!-- This identifies and version-stamps the jar.
+                 Not essential, but easy and useful. -->
+              <addDefaultImplementationEntries>
+                true
+              </addDefaultImplementationEntries>
+            </manifest>
+
+            <manifestSections>
+              <!-- This identifies a file in the jar named
+                 pljava.ddr as an SQLJDeploymentDescriptor. -->
+              <manifestSection>
+                <name>pljava.ddr</name>
+                <manifestEntries>
+                  <SQLJDeploymentDescriptor>
+                    true
+                  </SQLJDeploymentDescriptor>
+                </manifestEntries>
+              </manifestSection>
+            </manifestSections>
+          </archive>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

+ 29 - 0
src/main/java/PlJavaJSword.java

@@ -0,0 +1,29 @@
+package one.shandan;
+
+import java.lang.String;
+import java.lang.Boolean;
+import org.crosswire.jsword.passage.VerseRangeFactory;
+import org.crosswire.jsword.versification.system.SystemDefault;
+import org.crosswire.jsword.versification.BibleBook;
+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.postgresql.pljava.annotation.Function;
+import static org.postgresql.pljava.annotation.Function.Effects.IMMUTABLE;
+import static org.postgresql.pljava.annotation.Function.OnNullInput.RETURNS_NULL;
+
+public class PlJavaJSword {
+  private static Versification kjv = Versifications.instance().getVersification("KJV");
+
+  @Function(language="javau", onNullInput=RETURNS_NULL, effects=IMMUTABLE)
+  public static Boolean isValidVerse(String reference) {
+    try {
+      VerseRangeFactory.fromString(kjv, reference);
+    } catch (NoSuchVerseException ex) {
+      return false;
+    }
+    return true;
+  }
+}
+

+ 15 - 0
src/test/java/TestPlJavaJSword.java

@@ -0,0 +1,15 @@
+package one.shandan;
+import one.shandan.PlJavaJSword;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class TestPlJavaJSword {
+  @Test
+  public void testIsValidVerseValidVerse(){
+    assertEquals(true, PlJavaJSword.isValidVerse("Gen 1:1"));
+  }
+  @Test
+  public void testIsValidVerseInvalidVerse(){
+    assertEquals(false, PlJavaJSword.isValidVerse("Bogus 1:1"));
+  }
+}