[jsword-svn] r1805 - in trunk/jsword/src: main/java/org/crosswire/jsword/bridge main/java/org/crosswire/jsword/passage test/java/org/crosswire/jsword/bridge

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Sun Apr 20 12:42:33 MST 2008


Author: dmsmith
Date: 2008-04-20 12:42:31 -0700 (Sun, 20 Apr 2008)
New Revision: 1805

Modified:
   trunk/jsword/src/main/java/org/crosswire/jsword/bridge/DwrBridge.java
   trunk/jsword/src/main/java/org/crosswire/jsword/passage/Passage.java
   trunk/jsword/src/test/java/org/crosswire/jsword/bridge/DwrBridgeTest.java
Log:
improved DwrBridge to allow getting a slice of data
fixed spelling mistakes.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/bridge/DwrBridge.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/bridge/DwrBridge.java	2008-04-20 00:26:20 UTC (rev 1804)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/bridge/DwrBridge.java	2008-04-20 19:42:31 UTC (rev 1805)
@@ -105,12 +105,12 @@
      * @param bookInitials the book to use
      * @param reference a reference, appropriate for the book, for one or more keys
      */
-    public String getOSISString(String bookInitials, String reference, int maxKeyCount) throws BookException, NoSuchKeyException
+    public String getOSISString(String bookInitials, String reference, int start, int count) throws BookException, NoSuchKeyException
     {
         String result = ""; //$NON-NLS-1$
         try
         {
-            SAXEventProvider sep = getOSISProvider(bookInitials, reference, maxKeyCount);
+            SAXEventProvider sep = getOSISProvider(bookInitials, reference, start, count);
             if (sep != null)
             {
                 ContentHandler ser = new SerializingContentHandler();
@@ -235,24 +235,31 @@
      * 
      * @param bookInitials the book to use
      * @param reference a reference, appropriate for the book, of one or more entries
-     * @param maxKeyCount the maximum number of entries to use
+     * @param start the starting point where 0 is the first.
+     * @param count the maximum number of entries to use
      * 
      * @throws NoSuchKeyException 
      */
-    private BookData getBookData(String bookInitials, String reference, int maxKeyCount) throws NoSuchKeyException
+    private BookData getBookData(String bookInitials, String reference, int start, int count) throws NoSuchKeyException
     {
         Book book = BookInstaller.getInstalledBook(bookInitials);
-        if (book == null || reference == null || maxKeyCount < 1)
+        if (book == null || reference == null || count < 1)
         {
             return null;
         }
 
-        // TODO(dms): add trim to the key interface.
+        // TODO(dms): add trim(count) and trim(start, count) to the key interface.
         Key key = null;
         if (BookCategory.BIBLE.equals(book.getBookCategory()))
         {
             key = book.getKey(reference);
-            ((Passage) key).trimVerses(maxKeyCount);
+            Passage remainder = ((Passage) key);
+            if (start > 0)
+            {
+                remainder = remainder.trimVerses(start);
+            }
+            remainder.trimVerses(count);
+            key = remainder;
         }
         else if (BookCategory.GENERAL_BOOK.equals(book.getBookCategory()))
         {
@@ -264,15 +271,22 @@
             key = book.getKey(reference);
             
             // Do we need to trim?
-            if (key.getCardinality() > maxKeyCount)
+            if (start > 0 || key.getCardinality() > count)
             {
                 Iterator iter = key.iterator();
                 key = book.createEmptyKeyList();
-                int count = 0;
+                int i = 0;
                 while (iter.hasNext())
                 {
-                    if (++count >= maxKeyCount)
+                    i++;
+                    if (i <= start)
                     {
+                        // skip it
+                        iter.next();
+                        continue;
+                    }
+                    if (i >= count)
+                    {
                         break;
                     }
                     key.addAll((Key) iter.next());
@@ -289,9 +303,9 @@
      * @param bookInitials the book to use
      * @param reference a reference, appropriate for the book, of one or more entries
      */
-    private SAXEventProvider getOSISProvider(String bookInitials, String reference, int maxKeyCount) throws BookException, NoSuchKeyException
+    private SAXEventProvider getOSISProvider(String bookInitials, String reference, int start, int count) throws BookException, NoSuchKeyException
     {
-        BookData data = getBookData(bookInitials, reference, maxKeyCount);
+        BookData data = getBookData(bookInitials, reference, start, count);
         SAXEventProvider provider = null;
         if (data != null)
         {

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/Passage.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/Passage.java	2008-04-20 00:26:20 UTC (rev 1804)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/Passage.java	2008-04-20 19:42:31 UTC (rev 1805)
@@ -49,7 +49,7 @@
  *     huge problem? Are there many syntax errors that would be lost? Probably not.
  * <li>The specific version would stop enhancements like add("Gen 1:1");
  *     (But this is just syntactical sugar anyway).
- * <li>The specific version allows funcionality by is-a as well as has-a.
+ * <li>The specific version allows functionality by is-a as well as has-a.
  *     But a Passage is fundamentally different so this is not that much use.
  * <li>At the end of the day I expect people to use getName() instead of toString()
  *     and blur(), both of which are Passage things not Collection things. So
@@ -92,7 +92,7 @@
     /**
      * Determine whether there are two or more ranges.
      *
-     * @param restrict Do we break ranges at chapter/book boundries
+     * @param restrict Do we break ranges at chapter/book boundaries
      * @return whether there are two or more ranges
      * @see VerseRange
      */
@@ -103,7 +103,7 @@
      * Returns the number of fragments in this collection.
      * This does not mean the Passage needs to use VerseRanges, just that it
      * understands the concept.
-     * @param restrict Do we break ranges at chapter/book boundries
+     * @param restrict Do we break ranges at chapter/book boundaries
      * @return the number of VerseRanges in this collection
      * @see VerseRange
      */
@@ -117,7 +117,7 @@
      * <code>count</code> in the Passage, then the passage remains
      * unchanged, and null is returned.
      * @param count The maximum number of Verses to allow in this collection
-     * @return A new Passage conatining the remaining verses or null
+     * @return A new Passage containing the remaining verses or null
      * @see Verse
      */
     Passage trimVerses(int count);
@@ -130,8 +130,8 @@
      * greater than <code>count</code> in the Passage, then the passage
      * remains unchanged, and null is returned.
      * @param count The maximum number of VerseRanges to allow in this collection
-     * @param restrict Do we break ranges at chapter/book boundries
-     * @return A new Passage conatining the remaining verses or null
+     * @param restrict Do we break ranges at chapter/book boundaries
+     * @return A new Passage containing the remaining verses or null
      * @see VerseRange
      */
     Passage trimRanges(int count, RestrictionType restrict);
@@ -171,7 +171,7 @@
     /**
      * Get a specific VerseRange from this collection
      * @param offset The verse range offset (legal values are 0 to countRanges()-1)
-     * @param restrict Do we break ranges at chapter/book boundries
+     * @param restrict Do we break ranges at chapter/book boundaries
      * @return The Verse Range
      * @throws ArrayIndexOutOfBoundsException If the offset is out of range
      */
@@ -230,7 +230,7 @@
     void writeDescription(Writer out) throws IOException;
 
     /**
-     * For preformance reasons we may well want to hint to the Passage that we
+     * For performance reasons we may well want to hint to the Passage that we
      * have done editing it for now and that it is safe to cache certain
      * values to speed up future reads. Any action taken by this method will be
      * undone simply by making a future edit, and the only loss in calling

Modified: trunk/jsword/src/test/java/org/crosswire/jsword/bridge/DwrBridgeTest.java
===================================================================
--- trunk/jsword/src/test/java/org/crosswire/jsword/bridge/DwrBridgeTest.java	2008-04-20 00:26:20 UTC (rev 1804)
+++ trunk/jsword/src/test/java/org/crosswire/jsword/bridge/DwrBridgeTest.java	2008-04-20 19:42:31 UTC (rev 1805)
@@ -56,9 +56,9 @@
     {
         try
         {
-            String verse = dwrBridge.getOSISString("KJV", "Gen 1:1", 100); //$NON-NLS-1$ //$NON-NLS-2$
+            String verse = dwrBridge.getOSISString("KJV", "Gen 1:1", 0, 100); //$NON-NLS-1$ //$NON-NLS-2$
             assertEquals(verse, "<div><title type=\"x-gen\">Genesis 1:1</title><verse osisID=\"Gen.1.1\"><w lemma=\"strong:H07225\">In the beginning</w> <w lemma=\"strong:H0430\">God</w> <w lemma=\"strong:H0853 strong:H01254\" morph=\"strongMorph:TH8804\">created</w> <w lemma=\"strong:H08064\">the heaven</w> <w lemma=\"strong:H0853\">and</w> <w lemma=\"strong:H0776\">the earth</w>.</verse></div>"); //$NON-NLS-1$
-            String hdef = dwrBridge.getOSISString("StrongsHebrew", "H07225", 100); //$NON-NLS-1$ //$NON-NLS-2$
+            String hdef = dwrBridge.getOSISString("StrongsHebrew", "H07225", 0, 100); //$NON-NLS-1$ //$NON-NLS-2$
             assertEquals(hdef, "<div><title>07225</title>7225  re'shiyth  ray-sheeth'\r<lb></lb>\r<lb></lb> from the same as 7218; the first, in place, time, order or\r<lb></lb> rank (specifically, a firstfruit):--beginning, chief(-est),\r<lb></lb> first(-fruits, part, time), principal thing.\r<lb></lb> see HEBREW for 07218</div>"); //$NON-NLS-1$
         }
         catch (BookException e)




More information about the jsword-svn mailing list