[jsword-svn] jsword/java/jsword/org/crosswire/jsword/book/basic s

jswordcvs at crosswire.org jswordcvs at crosswire.org
Fri Mar 18 18:56:49 MST 2005


Update of /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/basic
In directory www.crosswire.org:/tmp/cvs-serv10359/java/jsword/org/crosswire/jsword/book/basic

Modified Files:
	DefaultBookMetaData.java AbstractBookList.java 
	AbstractBook.java AbstractBookDriver.java 
	AbstractBookMetaData.java 
Log Message:
Made Book the primary interface to a module and put BookMetaData within it. All of BookMetaData is accessible through the Book interface.

Index: AbstractBookList.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/basic/AbstractBookList.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** AbstractBookList.java	31 Mar 2004 10:55:05 -0000	1.2
--- AbstractBookList.java	19 Mar 2005 01:56:47 -0000	1.3
***************
*** 6,13 ****
  import org.crosswire.common.util.CollectionUtil;
  import org.crosswire.common.util.EventListenerList;
  import org.crosswire.jsword.book.BookFilter;
  import org.crosswire.jsword.book.BookFilterIterator;
  import org.crosswire.jsword.book.BookList;
- import org.crosswire.jsword.book.BookMetaData;
  import org.crosswire.jsword.book.BooksEvent;
  import org.crosswire.jsword.book.BooksListener;
--- 6,13 ----
  import org.crosswire.common.util.CollectionUtil;
  import org.crosswire.common.util.EventListenerList;
+ import org.crosswire.jsword.book.Book;
  import org.crosswire.jsword.book.BookFilter;
  import org.crosswire.jsword.book.BookFilterIterator;
  import org.crosswire.jsword.book.BookList;
  import org.crosswire.jsword.book.BooksEvent;
  import org.crosswire.jsword.book.BooksListener;
***************
*** 42,50 ****
  {
      /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookList#getBookMetaDatas(org.crosswire.jsword.book.BookFilter)
       */
!     public List getBookMetaDatas(BookFilter filter)
      {
!         List temp = CollectionUtil.createList(new BookFilterIterator(getBookMetaDatas().iterator(), filter));
          return Collections.unmodifiableList(temp);
      }
--- 42,50 ----
  {
      /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookList#getBooks(org.crosswire.jsword.book.BookFilter)
       */
!     public List getBooks(BookFilter filter)
      {
!         List temp = CollectionUtil.createList(new BookFilterIterator(getBooks().iterator(), filter));
          return Collections.unmodifiableList(temp);
      }
***************
*** 69,76 ****
       * Kick of an event sequence
       * @param source The event source
!      * @param bmd The meta-data of the changed Bible
       * @param added Is it added?
       */
!     protected static synchronized void fireBooksChanged(Object source, BookMetaData bmd, boolean added)
      {
          // Guaranteed to return a non-null array
--- 69,76 ----
       * Kick of an event sequence
       * @param source The event source
!      * @param book The changed Book
       * @param added Is it added?
       */
!     protected static synchronized void fireBooksChanged(Object source, Book book, boolean added)
      {
          // Guaranteed to return a non-null array
***************
*** 86,90 ****
                  if (ev == null)
                  {
!                     ev = new BooksEvent(source, bmd, added);
                  }
  
--- 86,90 ----
                  if (ev == null)
                  {
!                     ev = new BooksEvent(source, book, added);
                  }
  

Index: AbstractBookMetaData.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/basic/AbstractBookMetaData.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** AbstractBookMetaData.java	6 Mar 2005 20:21:47 -0000	1.19
--- AbstractBookMetaData.java	19 Mar 2005 01:56:47 -0000	1.20
***************
*** 14,18 ****
  import org.crosswire.common.util.Logger;
  import org.crosswire.common.util.StringUtil;
- import org.crosswire.jsword.book.Book;
  import org.crosswire.jsword.book.BookDriver;
  import org.crosswire.jsword.book.BookMetaData;
--- 14,17 ----
***************
*** 47,58 ****
  {
      /* (non-Javadoc)
-      * @see org.crosswire.jsword.book.BookMetaData#getBook()
-      */
-     public Book getBook()
-     {
-         return book;
-     }
- 
-     /* (non-Javadoc)
       * @see org.crosswire.jsword.book.BookMetaData#getDriver()
       */
--- 46,49 ----
***************
*** 180,191 ****
  
      /**
-      * @param book The book to set.
-      */
-     public void setBook(Book book)
-     {
-         this.book = book;
-     }
- 
-     /**
       * @param driver The driver to set.
       */
--- 171,174 ----
***************
*** 195,199 ****
      }
  
- 
      /**
       * Get the language name from the language code. Note, this code does not support dialects.
--- 178,181 ----
***************
*** 386,390 ****
      private Map prop = new LinkedHashMap();
  
-     private Book book;
      private BookDriver driver;
      private String fullName;
--- 368,371 ----

Index: DefaultBookMetaData.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/basic/DefaultBookMetaData.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** DefaultBookMetaData.java	28 Feb 2005 02:21:40 -0000	1.16
--- DefaultBookMetaData.java	19 Mar 2005 01:56:47 -0000	1.17
***************
*** 4,7 ****
--- 4,8 ----
  
  import org.crosswire.common.util.StringUtil;
+ import org.crosswire.common.xml.XMLUtil;
  import org.crosswire.jsword.book.Book;
  import org.crosswire.jsword.book.BookDriver;
***************
*** 9,14 ****
--- 10,18 ----
  import org.crosswire.jsword.book.BookType;
  import org.crosswire.jsword.book.IndexStatus;
+ import org.crosswire.jsword.book.OSISUtil;
  import org.crosswire.jsword.book.search.IndexManager;
  import org.crosswire.jsword.book.search.IndexManagerFactory;
+ import org.jdom.Document;
+ import org.jdom.Element;
  
  /**
***************
*** 49,53 ****
      {
          setDriver(driver);
-         setBook(book);
  
          setProperties(prop);
--- 53,56 ----
***************
*** 71,78 ****
       * A call to setBook() is still required after this ctor is called
       */
!     public DefaultBookMetaData(BookDriver driver, Book book, String name, BookType type)
      {
          setDriver(driver);
-         setBook(book);
          setName(name);
          setType(type);
--- 74,80 ----
       * A call to setBook() is still required after this ctor is called
       */
!     public DefaultBookMetaData(BookDriver driver, String name, BookType type)
      {
          setDriver(driver);
          setName(name);
          setType(type);
***************
*** 191,194 ****
--- 193,239 ----
      }
  
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#toOSIS()
+      */
+     public Document toOSIS()
+     {
+         OSISUtil.ObjectFactory factory = OSISUtil.factory();
+         Element ele = factory.createTable();
+         // initials, description, key, language, 
+         addRow(ele, "Initials", getInitials()); //$NON-NLS-1$
+         addRow(ele, "Description", getFullName()); //$NON-NLS-1$
+         addRow(ele, "Key", getType().toString()); //$NON-NLS-1$
+         addRow(ele, "Language", getLanguage()); //$NON-NLS-1$
+         return new Document(ele);
+     }
+ 
+     private void addRow(Element table, String key, String value)
+     {
+         if (value == null)
+         {
+             return;
+         }
+ 
+         OSISUtil.ObjectFactory factory = OSISUtil.factory();
+ 
+         Element rowEle = factory.createRow();
+ 
+         Element nameEle = factory.createCell();
+         Element hiEle = factory.createHI();
+         hiEle.setAttribute("rend", "bold"); //$NON-NLS-1$ //$NON-NLS-2$
+         nameEle.addContent(hiEle);
+         Element valueElement = factory.createCell();
+         rowEle.addContent(nameEle);
+         rowEle.addContent(valueElement);
+ 
+         // I18N(DMS): use name to lookup translation.
+         hiEle.addContent(key);
+ 
+         String expandedValue = XMLUtil.escape(value);
+         valueElement.addContent(expandedValue);
+ 
+         table.addContent(rowEle);
+     }
+ 
      private BookType type;
      private String name;

Index: AbstractBookDriver.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/basic/AbstractBookDriver.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** AbstractBookDriver.java	19 Nov 2003 22:48:16 -0000	1.7
--- AbstractBookDriver.java	19 Mar 2005 01:56:47 -0000	1.8
***************
*** 4,8 ****
  import org.crosswire.jsword.book.BookDriver;
  import org.crosswire.jsword.book.BookException;
- import org.crosswire.jsword.book.BookMetaData;
  
  /**
--- 4,7 ----
***************
*** 49,59 ****
      }
  
!     /**
!      * Delete this Book from the system.
!      * Take care with this method for obvious reasons. For most implemenations
!      * of Book etc, this method will throw up because most will be read-only.
!      * @throws BookException If the Book can't be deleted.
       */
!     public void delete(BookMetaData dead) throws BookException
      {
          throw new BookException(Msg.DRIVER_READONLY);
--- 48,63 ----
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDriver#isDeletable(org.crosswire.jsword.book.Book)
       */
!     public boolean isDeletable(Book dead)
!     {
!         return false;
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDriver#delete(org.crosswire.jsword.book.Book)
!      */
!     public void delete(Book dead) throws BookException
      {
          throw new BookException(Msg.DRIVER_READONLY);

Index: AbstractBook.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/basic/AbstractBook.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** AbstractBook.java	9 Oct 2004 21:45:04 -0000	1.11
--- AbstractBook.java	19 Mar 2005 01:56:47 -0000	1.12
***************
*** 1,12 ****
  package org.crosswire.jsword.book.basic;
  
  import org.crosswire.common.activate.Lock;
- import org.crosswire.common.util.ClassUtil;
  import org.crosswire.jsword.book.Book;
  import org.crosswire.jsword.book.BookException;
  import org.crosswire.jsword.book.BookMetaData;
  import org.crosswire.jsword.book.search.Searcher;
  import org.crosswire.jsword.book.search.SearcherFactory;
  import org.crosswire.jsword.passage.Key;
  
  /**
--- 1,18 ----
  package org.crosswire.jsword.book.basic;
  
+ import java.beans.PropertyChangeListener;
+ import java.util.Map;
+ 
  import org.crosswire.common.activate.Lock;
  import org.crosswire.jsword.book.Book;
+ import org.crosswire.jsword.book.BookDriver;
  import org.crosswire.jsword.book.BookException;
  import org.crosswire.jsword.book.BookMetaData;
+ import org.crosswire.jsword.book.BookType;
+ import org.crosswire.jsword.book.IndexStatus;
  import org.crosswire.jsword.book.search.Searcher;
  import org.crosswire.jsword.book.search.SearcherFactory;
  import org.crosswire.jsword.passage.Key;
+ import org.jdom.Document;
  
  /**
***************
*** 46,51 ****
      }
  
!     /**
!      * @see org.crosswire.jsword.book.Book#getBookMetaData()
       */
      public final void setBookMetaData(BookMetaData bmd)
--- 52,57 ----
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.Book#setBookMetaData(org.crosswire.jsword.book.BookMetaData)
       */
      public final void setBookMetaData(BookMetaData bmd)
***************
*** 89,97 ****
  
      /* (non-Javadoc)
       * @see java.lang.Object#toString()
       */
!     public final String toString()
      {
!         return ClassUtil.getShortClassName(getClass()) + ":" + getBookMetaData().toString(); //$NON-NLS-1$
      }
  
--- 95,275 ----
  
      /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#getBook()
+      */
+     public Book getBook()
+     {
+         return this;
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#getDriver()
+      */
+     public BookDriver getDriver()
+     {
+         return bmd.getDriver();
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#getDriverName()
+      */
+     public String getDriverName()
+     {
+         return bmd.getDriverName();
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#getFullName()
+      */
+     public String getFullName()
+     {
+         return bmd.getFullName();
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#getIndexStatus()
+      */
+     public IndexStatus getIndexStatus()
+     {
+         return bmd.getIndexStatus();
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#setIndexStatus(org.crosswire.jsword.book.IndexStatus)
+      */
+     public void setIndexStatus(IndexStatus status)
+     {
+         bmd.setIndexStatus(status);
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#getInitials()
+      */
+     public String getInitials()
+     {
+         return bmd.getInitials();
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#getLanguage()
+      */
+     public String getLanguage()
+     {
+         return bmd.getLanguage();
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#getName()
+      */
+     public String getName()
+     {
+         return bmd.getName();
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#getOsisID()
+      */
+     public String getOsisID()
+     {
+         return bmd.getOsisID();
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#getProperties()
+      */
+     public Map getProperties()
+     {
+         return bmd.getProperties();
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#getType()
+      */
+     public BookType getType()
+     {
+         return bmd.getType();
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#isLeftToRight()
+      */
+     public boolean isLeftToRight()
+     {
+         return bmd.isLeftToRight();
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#removePropertyChangeListener(java.beans.PropertyChangeListener)
+      */
+     public void removePropertyChangeListener(PropertyChangeListener li)
+     {
+         bmd.removePropertyChangeListener(li);
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#addPropertyChangeListener(java.beans.PropertyChangeListener)
+      */
+     public void addPropertyChangeListener(PropertyChangeListener li)
+     {
+         bmd.addPropertyChangeListener(li);
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#toOSIS()
+      */
+     public Document toOSIS()
+     {
+         return bmd.toOSIS();
+     }
+ 
+     /* (non-Javadoc)
+      * @see java.lang.Object#equals(java.lang.Object)
+      */
+     public boolean equals(Object obj)
+     {
+         // Since this can not be null
+         if (obj == null)
+         {
+             return false;
+         }
+ 
+         // We might consider checking for equality against all Books?
+         // However currently we dont.
+ 
+         // Check that that is the same as this
+         // Don't use instanceof since that breaks inheritance
+         if (!obj.getClass().equals(this.getClass()))
+         {
+             return false;
+         }
+ 
+         // The real bit ...
+         Book that = (Book) obj;
+ 
+         return bmd.equals(that.getBookMetaData());
+     }
+ 
+     /* (non-Javadoc)
+      * @see java.lang.Object#hashCode()
+      */
+     public int hashCode()
+     {
+         return bmd.hashCode();
+     }
+ 
+     /* (non-Javadoc)
+      * @see java.lang.Comparable#compareTo(java.lang.Object)
+      */
+     public int compareTo(Object obj)
+     {
+         Book that = (Book) obj;
+         return this.bmd.compareTo(that.getBookMetaData());
+     }
+ 
+     /* (non-Javadoc)
       * @see java.lang.Object#toString()
       */
!     public String toString()
      {
!         return bmd.toString();
      }
  



More information about the jsword-svn mailing list