Ejemplo n.º 1
0
  public static Key prevChapter(Key key) {
    Verse verse;
    // Get verse to work with
    if (Utils.isVerse(key)) {
      verse = (Verse) key;
    } else if (Utils.isVerseRange(key)) {
      verse = ((VerseRange) key).getStart();
    } else {
      throw new RuntimeException("Unsupported Type for next chapter key");
    }

    // Check if start of Bible
    if ((verse.getChapter() == 1 && verse.getBook().equals(BibleBook.GEN))) {
      return key;
    } else {
      return new VerseRange(
          verse.getFirstVerseInChapter().subtract(1).getFirstVerseInChapter(),
          verse.getFirstVerseInChapter().subtract(1));
    }

    //		if(TextUtility.isVerse((key))){
    //			//Check if it is the first book of Genesis
    //			if (((Verse) key).getChapter() == 1 && ((Verse) key).getBook().equals(BibleBook.GEN)){
    //				return key;
    //			}
    //			return new VerseRange(((Verse)
    // key).getFirstVerseInChapter().subtract(1).getFirstVerseInChapter(), ((Verse)
    // key).getFirstVerseInChapter().subtract(1));
    //		} else if (TextUtility.isVerseRange((key))) {
    //			//TODO: what if the book is not a bible book?
    //
    //			//Check if it is the first book of Genesis
    //			if (((VerseRange) key).getStart().getChapter() == 1 && ((VerseRange)
    // key).getStart().getBook().equals(BibleBook.GEN)){
    //				return key;
    //			}
    //			//Else just the chapter reference
    //			return new VerseRange(((VerseRange)
    // key).getStart().getFirstVerseInChapter().subtract(1).getFirstVerseInChapter(),((VerseRange)
    // key).getStart().getFirstVerseInChapter().subtract(1));
    //		} else {
    //			throw new RuntimeException("Unsupported Type for next chapter key");
    //		}
  }
Ejemplo n.º 2
0
  public static Key nextChapter(Key key) {
    Verse verse;
    // Get verse to work with
    if (Utils.isVerse(key)) {
      verse = (Verse) key;
    } else if (Utils.isVerseRange(key)) {
      verse = ((VerseRange) key).getEnd();
    } else {
      throw new RuntimeException("Unsupported Type for next chapter key");
    }

    // Check if end of Bible
    if (verse.getLastVerseInBook().equals(verse.getLastVerseInChapter())
        && verse.getBook().equals(BibleBook.REV)) {
      return key;
    } else {
      return new VerseRange(
          verse.getLastVerseInChapter().add(1).getFirstVerseInChapter(),
          verse.getLastVerseInChapter().add(1).getLastVerseInChapter());
    }

    //		if(TextUtility.isVerse((key))){
    //			//Does not return next but simply returns current chapter
    //			return new VerseRange(((Verse) key).getFirstVerseInChapter(), ((Verse)
    // key).getLastVerseInChapter());
    //		} else if (TextUtility.isVerseRange((key))) {
    //			//Else just the chapter reference
    //			if (((VerseRange) key).getEnd().getLastVerseInBook().equals(((VerseRange) key).getEnd())
    // && ((VerseRange) key).getEnd().getBook().equals(BibleBook.REV)){
    //				return key;
    //			}
    //			return new VerseRange(((VerseRange)
    // key).getEnd().getLastVerseInChapter().add(1),((VerseRange)
    // key).getEnd().getLastVerseInChapter().add(1).getLastVerseInChapter());
    //		} else {
    //			throw new RuntimeException("Unsupported Type for next chapter key");
    //		}
  }
Ejemplo n.º 3
0
 /**
  * Get the Key object of the current key's chapter given a specific verse
  *
  * @param key
  * @param verse
  * @return
  */
 public static Verse getVerseKey(Key key, int verse) {
   try {
     if (Utils.isVerse((key))) {
       // Returns current chapter
       Verse currentVerse = (Verse) key;
       return new Verse(currentVerse.getBook(), currentVerse.getChapter(), verse);
     } else if (Utils.isVerseRange((key))) {
       Verse currentVerse = ((VerseRange) key).getStart();
       return new Verse(currentVerse.getBook(), currentVerse.getChapter(), verse);
     } else {
     }
   } catch (NoSuchVerseException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   throw new RuntimeException("Unsupported Type for next chapter key");
 }
Ejemplo n.º 4
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.crosswire.jsword.book.raw.Insts#getIndexes(org.crosswire.jsword.passage
  * .Verse)
  */
 public int[] getIndexes(Verse verse) {
   return getIndexes(verse.getOrdinal());
 }
Ejemplo n.º 5
0
  public void dump(String name, String range)
      throws NoSuchKeyException, IOException, BookException {
    Books books = Books.installed();
    Book bible = books.getBook(name);
    BookMetaData bmd = bible.getBookMetaData();
    String lastBookName = "";
    int lastChapter = -1;
    StringBuffer buf = new StringBuffer();
    boolean inPreVerse = false;

    Key keys = bible.getKey(range);

    openOutputFile(bmd.getInitials(), !BY_BOOK);
    buildDocumentOpen(buf, bmd, range, !BY_BOOK);
    if (!BY_BOOK) {
      writeDocument(buf);
    }

    // Get a verse iterator
    for (Key key : keys) {
      Verse verse = (Verse) key;
      String raw = bible.getRawText(verse);
      String osisID = verse.getOsisID();
      String currentBookName = verse.getBook().getOSIS();
      int currentChapter = verse.getChapter();

      boolean newBookFound = !lastBookName.equals(currentBookName);

      if (newBookFound) {
        if (lastBookName.length() > 0) {
          if (currentChapter == 1) {
            if (inPreVerse) {
              buildPreVerseClose(buf);
              inPreVerse = false;
            }
            buildChapterClose(buf);
          }
          buildBookClose(buf);
          buildDocumentClose(buf, BY_BOOK);
          openOutputFile(lastBookName, BY_BOOK);
          writeDocument(buf);
          closeOutputFile(BY_BOOK);
        }

        buf = new StringBuffer();
        buildDocumentOpen(buf, bmd, currentBookName, BY_BOOK);
        buildBookOpen(buf, currentBookName);
      }

      if (newBookFound || lastChapter != currentChapter) {
        if (currentChapter != 1) {
          if (inPreVerse) {
            buildPreVerseClose(buf);
            inPreVerse = false;
          }
          buildChapterClose(buf);
        }
        buildChapterOpen(buf, currentBookName, currentChapter);
      }

      /* Output the verse */

      boolean foundPreVerse = false;
      String preVerseText = "";
      if (raw.indexOf(preVerseStart) != -1) {
        Matcher matcher = preVersePattern.matcher(raw);
        StringBuffer rawbuf = new StringBuffer();
        if (matcher.find()) {
          foundPreVerse = true;
          preVerseText = matcher.group(1);
          matcher.appendReplacement(rawbuf, "");
        }
        matcher.appendTail(rawbuf);
        raw = rawbuf.toString();
      }

      boolean foundPsalmTitle = false;
      String psalmTitleText = "";
      if (raw.indexOf(psalmTitleStart) != -1) {
        Matcher matcher = psalmTitlePattern.matcher(raw);
        StringBuffer rawbuf = new StringBuffer();
        if (matcher.find()) {
          foundPsalmTitle = true;
          psalmTitleText = matcher.group(1);
          matcher.appendReplacement(rawbuf, "");
        }
        matcher.appendTail(rawbuf);
        raw = rawbuf.toString();
      }

      if (foundPsalmTitle) {
        buildPsalmTitle(buf, psalmTitleText);
      }

      if (foundPreVerse && !preVerseText.equals(psalmTitleText)) {
        if (inPreVerse) {
          buildPreVerseClose(buf);
        }
        buildPreVerseOpen(buf, preVerseText);
        inPreVerse = true;
      }

      buildVerseOpen(buf, osisID);
      buf.append(raw);
      buildVerseClose(buf, osisID);

      lastChapter = currentChapter;
      lastBookName = currentBookName;
    }

    // Close everything that is open
    if (inPreVerse) {
      buildPreVerseClose(buf);
      inPreVerse = false;
    }

    buildChapterClose(buf);
    buildBookClose(buf);
    buildDocumentClose(buf, true);
    openOutputFile(lastBookName, BY_BOOK);
    writeDocument(buf);
    closeOutputFile(true);
  }