[jsword-svn] r1281 - trunk/jsword/src/main/java/org/crosswire/jsword/passage

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Fri Apr 20 09:27:07 MST 2007


Author: dmsmith
Date: 2007-04-20 09:27:07 -0700 (Fri, 20 Apr 2007)
New Revision: 1281

Modified:
   trunk/jsword/src/main/java/org/crosswire/jsword/passage/VerseRange.java
Log:
Improved the generation of OSISRefs.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/VerseRange.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/VerseRange.java	2007-04-20 10:55:14 UTC (rev 1280)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/VerseRange.java	2007-04-20 16:27:07 UTC (rev 1281)
@@ -248,12 +248,48 @@
     {
         try
         {
-            // If this is in 2 separate books
             int startBook = start.getBook();
             int endBook = end.getBook();
+            int startChapter = start.getChapter();
+            int endChapter = end.getChapter();
+
+            // If this is in 2 separate books
             if (startBook != endBook)
             {
-                return start.getOsisRef() + VerseRange.RANGE_PREF_DELIM + end.getOsisRef();
+                StringBuffer buf = new StringBuffer();
+                if (start.isStartOfBook())
+                {
+                    buf.append(BibleInfo.getOSISName(startBook));
+                }
+                else if (start.isStartOfChapter())
+                {
+                    buf.append(BibleInfo.getOSISName(startBook));
+                    buf.append(Verse.VERSE_OSIS_DELIM);
+                    buf.append(startChapter);
+                }
+                else
+                {
+                    buf.append(start.getOsisRef());
+                }
+
+                buf.append(VerseRange.RANGE_PREF_DELIM);
+
+                if (end.isEndOfBook())
+                {
+                    buf.append(BibleInfo.getOSISName(endBook));
+                }
+                else if (end.isEndOfChapter())
+                {
+                    buf.append(BibleInfo.getOSISName(endBook));
+                    buf.append(Verse.VERSE_OSIS_DELIM);
+                    buf.append(endChapter);
+                }
+                else
+                {
+                    buf.append(end.getOsisRef());
+                }
+
+                return buf.toString();
             }
 
             // This range is exactly a whole book
@@ -265,25 +301,56 @@
                 return BibleInfo.getOSISName(startBook);
             }
 
-            // If this is 2 separate chapters
-            int startChapter = start.getChapter();
-            int endChapter = end.getChapter();
+            // If this is 2 separate chapters in the same book
             if (startChapter != endChapter)
             {
-                return start.getOsisRef() + VerseRange.RANGE_PREF_DELIM + end.getOsisRef();
+                StringBuffer buf = new StringBuffer();
+                if (start.isStartOfChapter())
+                {
+                    buf.append(BibleInfo.getOSISName(startBook));
+                    buf.append(Verse.VERSE_OSIS_DELIM);
+                    buf.append(startChapter);
+                }
+                else
+                {
+                    buf.append(start.getOsisRef());
+                }
+
+                buf.append(VerseRange.RANGE_PREF_DELIM);
+
+                if (end.isEndOfChapter())
+                {
+                    buf.append(BibleInfo.getOSISName(endBook));
+                    buf.append(Verse.VERSE_OSIS_DELIM);
+                    buf.append(endChapter);
+                }
+                else
+                {
+                    buf.append(end.getOsisRef());
+                }
+
+                return buf.toString();
             }
 
             // If this range is exactly a whole chapter
             if (isWholeChapter())
             {
                 // Just report the name of the book and the chapter
-                return BibleInfo.getOSISName(startBook) + Verse.VERSE_OSIS_DELIM + startChapter;
+                StringBuffer buf = new StringBuffer();
+                buf.append(BibleInfo.getOSISName(startBook));
+                buf.append(Verse.VERSE_OSIS_DELIM);
+                buf.append(startChapter);
+                return buf.toString();
             }
 
             // If this is 2 separate verses
             if (start.getVerse() != end.getVerse())
             {
-                return start.getOsisRef() + VerseRange.RANGE_PREF_DELIM + end.getOsisRef();
+                StringBuffer buf = new StringBuffer();
+                buf.append(start.getOsisRef());
+                buf.append(VerseRange.RANGE_PREF_DELIM);
+                buf.append(end.getOsisRef());
+                return buf.toString();
             }
 
             // The range is a single verse




More information about the jsword-svn mailing list