[jsword-svn] r2114 - in trunk/jsword/src: main/java/org/crosswire/jsword/passage test/java test/java/org/crosswire/jsword/book/sword

dmsmith at crosswire.org dmsmith at crosswire.org
Sat Mar 12 09:35:31 MST 2011


Author: dmsmith
Date: 2011-03-12 09:35:31 -0700 (Sat, 12 Mar 2011)
New Revision: 2114

Added:
   trunk/jsword/src/test/java/org/crosswire/jsword/book/sword/GenBookTest.java
Modified:
   trunk/jsword/src/main/java/org/crosswire/jsword/passage/TreeKey.java
   trunk/jsword/src/test/java/JSwordAllTests.java
Log:
JS-174 Fixed infinite recursion in TreeKey for getOsisID and getOsisRef. Also fixed getRootName.
This fix introduces another problem. The osisID is not valid.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/TreeKey.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/TreeKey.java	2011-03-11 01:44:22 UTC (rev 2113)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/TreeKey.java	2011-03-12 16:35:31 UTC (rev 2114)
@@ -158,6 +158,42 @@
         return (TreeKey) super.clone();
     }
 
+    @Override
+    public String getRootName() {
+        String rootName = getName();
+        for (Key parentKey = this; parentKey != null && parentKey.getName().length() > 0; parentKey = parentKey.getParent()) {
+            rootName = parentKey.getName();
+        }
+        return rootName;
+    }
+
+    @Override
+    public String getOsisRef() {
+        return getOsisID();
+    }
+
+    @Override
+    public String getOsisID() {
+        StringBuilder b = new StringBuilder(100);
+        b.append(osisify(getName()));
+        for (Key parentKey = this.getParent(); parentKey != null && parentKey.getName().length() > 0; parentKey = parentKey.getParent()) {
+            b.insert(0, ".");
+            b.insert(0, osisify(parentKey.getName()));
+        }
+        // Remove the leading .
+        return b.toString();
+    }
+
+    private String osisify(String str) {
+        // FIXME(DMS): An osisID cannot have lots of stuff that a name can have.
+        // It can only have _, a-z, A-Z, 0-9.
+        // Need to normalize the name by
+        // replacing ' ' with '_'
+        // Stripping punctuation, accents, ...
+        // ...
+        return str.replace(' ', '_');
+    }
+
     /**
      * The parent of this key.
      */

Modified: trunk/jsword/src/test/java/JSwordAllTests.java
===================================================================
--- trunk/jsword/src/test/java/JSwordAllTests.java	2011-03-11 01:44:22 UTC (rev 2113)
+++ trunk/jsword/src/test/java/JSwordAllTests.java	2011-03-12 16:35:31 UTC (rev 2114)
@@ -82,6 +82,7 @@
 
         suite.addTestSuite(org.crosswire.jsword.book.sword.ConfigEntryTableTest.class);
         suite.addTestSuite(org.crosswire.jsword.book.sword.RawFileBackendTest.class);
+        suite.addTestSuite(org.crosswire.jsword.book.sword.GenBookTest.class);
         suite.addTestSuite(org.crosswire.jsword.book.sword.SwordBookDriverTest.class);
         suite.addTestSuite(org.crosswire.jsword.book.sword.SwordBookMetaDataTest.class);
         suite.addTestSuite(org.crosswire.jsword.book.sword.SwordBookTest.class);

Added: trunk/jsword/src/test/java/org/crosswire/jsword/book/sword/GenBookTest.java
===================================================================
--- trunk/jsword/src/test/java/org/crosswire/jsword/book/sword/GenBookTest.java	                        (rev 0)
+++ trunk/jsword/src/test/java/org/crosswire/jsword/book/sword/GenBookTest.java	2011-03-12 16:35:31 UTC (rev 2114)
@@ -0,0 +1,51 @@
+package org.crosswire.jsword.book.sword;
+
+import java.io.IOException;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.crosswire.jsword.book.Book;
+import org.crosswire.jsword.book.BookException;
+import org.crosswire.jsword.book.Books;
+import org.crosswire.jsword.passage.Key;
+import org.crosswire.jsword.passage.NoSuchKeyException;
+
+/**
+ * A Raw File format that allows for each verse to have it's own storage.
+ * 
+ * @see gnu.lgpl.License for license details.<br>
+ *      The copyright to this program is held by it's authors.
+ * @author mbergmann
+ */
+public class GenBookTest extends TestCase {
+
+    @Override
+    protected void setUp() throws Exception {
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+    }
+
+    public void testCreate() throws IOException, BookException {
+        Book book = Books.installed().getBook("Pilgrim"); // Bunyan's Pilgrim's Progress
+        if (book != null) {
+            Key key = null;
+            try {
+                key = book.getKey("THE FIRST STAGE");
+            } catch (NoSuchKeyException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+            if (key != null) {
+                try {
+                    assertEquals("PART_II.THE_FIRST_STAGE", key.getOsisID());
+                } catch(RuntimeException e) {
+                   Assert.fail("Could not get the osisID for a GenBook key.");
+                }
+            }
+        }
+    }
+
+}




More information about the jsword-svn mailing list