[jsword-svn] jsword/java/jsword/org/crosswire/jsword/book/sword s
jswordcvs at crosswire.org
jswordcvs at crosswire.org
Tue Jan 3 06:25:37 MST 2006
Update of /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/sword
In directory www.crosswire.org:/tmp/cvs-serv24436/java/jsword/org/crosswire/jsword/book/sword
Modified Files:
BookType.java RawLDBackend.java
Added Files:
SwordDailyDevotion.java
Log Message:
Unify Daily Devotions and Readings into a single behavior.
--- NEW FILE: SwordDailyDevotion.java ---
/**
* Distribution Licence:
* JSword is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2 as published by
* the Free Software Foundation. This program is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* The License is available on the internet at:
* http://www.gnu.org/copyleft/gpl.html
* or by writing to:
* Free Software Foundation, Inc.
* 59 Temple Place - Suite 330
* Boston, MA 02111-1307, USA
*
* The copyright to this program is held by it's authors.
*/
package org.crosswire.jsword.book.sword;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.crosswire.jsword.book.sword.RawLDBackend.IndexKey;
import org.crosswire.jsword.passage.Key;
import org.crosswire.jsword.passage.PreferredKey;
/**
* A book that has a preferred key of today's date.
*
* @see gnu.lgpl.License for license details.
* The copyright to this program is held by it's authors.
* @author DM Smith [ dmsmith555 at yahoo dot com]
*/
public class SwordDailyDevotion extends SwordDictionary implements PreferredKey
{
/**
* Simple ctor
*/
public SwordDailyDevotion(SwordBookMetaData sbmd, AbstractBackend backend)
{
super(sbmd, backend);
}
/* (non-Javadoc)
* @see org.crosswire.jsword.passage.PreferredKey#getPreferred()
*/
public Key getPreferred()
{
return new IndexKey(NAME_DF.format(new Date()));
}
/**
* Date formatter
*/
private static final DateFormat NAME_DF = new SimpleDateFormat("d MMMM"); //$NON-NLS-1$
}
Index: BookType.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/sword/BookType.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** BookType.java 27 Jul 2005 23:25:45 -0000 1.2
--- BookType.java 3 Jan 2006 13:25:34 -0000 1.3
***************
*** 182,185 ****
--- 182,189 ----
protected Book getBook(SwordBookMetaData sbmd, AbstractBackend backend)
{
+ if (sbmd.getBookCategory().equals(BookCategory.DAILY_DEVOTIONS))
+ {
+ return new SwordDailyDevotion(sbmd, backend);
+ }
return new SwordDictionary(sbmd, backend);
}
***************
*** 203,206 ****
--- 207,214 ----
protected Book getBook(SwordBookMetaData sbmd, AbstractBackend backend)
{
+ if (sbmd.getBookCategory().equals(BookCategory.DAILY_DEVOTIONS))
+ {
+ return new SwordDailyDevotion(sbmd, backend);
+ }
return new SwordDictionary(sbmd, backend);
}
***************
*** 224,227 ****
--- 232,239 ----
protected Book getBook(SwordBookMetaData sbmd, AbstractBackend backend)
{
+ if (sbmd.getBookCategory().equals(BookCategory.DAILY_DEVOTIONS))
+ {
+ return new SwordDailyDevotion(sbmd, backend);
+ }
return new SwordDictionary(sbmd, backend);
}
Index: RawLDBackend.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/sword/RawLDBackend.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** RawLDBackend.java 27 Jul 2005 23:25:45 -0000 1.23
--- RawLDBackend.java 3 Jan 2006 13:25:34 -0000 1.24
***************
*** 25,28 ****
--- 25,32 ----
import java.io.IOException;
import java.io.RandomAccessFile;
+ import java.text.DateFormat;
+ import java.text.SimpleDateFormat;
+ import java.util.Calendar;
+ import java.util.GregorianCalendar;
import org.crosswire.common.activate.Activator;
***************
*** 32,36 ****
--- 36,43 ----
import org.crosswire.common.util.Logger;
import org.crosswire.common.util.Reporter;
+ import org.crosswire.common.util.StringUtil;
+ import org.crosswire.jsword.book.BookCategory;
import org.crosswire.jsword.book.BookException;
+ import org.crosswire.jsword.book.BookMetaData;
import org.crosswire.jsword.book.DataPolice;
import org.crosswire.jsword.passage.DefaultKeyList;
***************
*** 129,133 ****
checkActive();
! Key reply = new DefaultKeyList(null, getBookMetaData().getName());
int entrysize = OFFSETSIZE + datasize;
--- 136,146 ----
checkActive();
! BookMetaData bmd = getBookMetaData();
! Key reply = new DefaultKeyList(null, bmd.getName());
!
! boolean isDailyDevotional = bmd.getBookCategory().equals(BookCategory.DAILY_DEVOTIONS);
! // We use 1972 because it is a leap year.
! Calendar greg = new GregorianCalendar(1972, Calendar.JANUARY, 1);
! DateFormat NAME_DF = new SimpleDateFormat("d MMMM"); //$NON-NLS-1$
int entrysize = OFFSETSIZE + datasize;
***************
*** 185,188 ****
--- 198,210 ----
keytitle = keytitle.substring(0, keytitle.length() - 1);
}
+
+ if (isDailyDevotional)
+ {
+ String[] parts = StringUtil.splitAll(keytitle, '.');
+ greg.set(Calendar.MONTH, Integer.parseInt(parts[0]) - 1);
+ greg.set(Calendar.DATE, Integer.parseInt(parts[1]));
+ keytitle = NAME_DF.format(greg.getTime());
+ }
+
Key key = new IndexKey(keytitle, offset, size, reply);
***************
*** 193,196 ****
--- 215,222 ----
log.error("Ignoring entry", ex); //$NON-NLS-1$
}
+ catch (NumberFormatException e)
+ {
+ log.error("Ignoring entry", e); //$NON-NLS-1$
+ }
}
***************
*** 317,320 ****
--- 343,357 ----
}
+ /**
+ * Setup with the key name. Use solely for searching.
+ */
+ protected IndexKey(String text)
+ {
+ super(text, text, null);
+
+ this.offset = -1;
+ this.size = -1;
+ }
+
/* (non-Javadoc)
* @see java.lang.Object#clone()
More information about the jsword-svn
mailing list