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

jswordcvs at crosswire.org jswordcvs at crosswire.org
Sat Oct 9 14:45:07 MST 2004


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

Modified Files:
	DefaultBookMetaData.java AbstractBook.java Verifier.java 
Added Files:
	AbstractBookMetaData.java 
Log Message:
indexing updates

--- NEW FILE: AbstractBookMetaData.java ---
package org.crosswire.jsword.book.basic;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.event.EventListenerList;

import org.crosswire.jsword.book.BookMetaData;

/**
 * An implementaion of the Propery Change methods from BookMetaData.
 * 
 * <p><table border='1' cellPadding='3' cellSpacing='0'>
 * <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
 *
 * Distribution Licence:<br />
 * 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.<br />
 * 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.<br />
 * The License is available on the internet
 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, or by writing to:
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA<br />
 * The copyright to this program is held by it's authors.
 * </font></td></tr></table>
 * @see gnu.gpl.Licence
 * @author Joe Walker [joe at eireneh dot com]
 * @version $Id: AbstractBookMetaData.java,v 1.16 2004/10/09 21:45:04 joe Exp $
 */
public abstract class AbstractBookMetaData implements BookMetaData
{
    /* (non-Javadoc)
     * @see org.crosswire.jsword.book.BookMetaData#addPropertyChangeListener(java.beans.PropertyChangeListener)
     */
    public void addPropertyChangeListener(PropertyChangeListener listener)
    {
        if (listeners == null)
        {
            listeners = new EventListenerList();
        }
        listeners.add(PropertyChangeListener.class, listener);
    }

    /* (non-Javadoc)
     * @see org.crosswire.jsword.book.BookMetaData#removePropertyChangeListener(java.beans.PropertyChangeListener)
     */
    public void removePropertyChangeListener(PropertyChangeListener listener)
    {
        if (listeners == null)
        {
            return;
        }

        listeners.remove(PropertyChangeListener.class, listener);
    }

    /**
     * Reports bound property changes.
     * If <code>oldValue</code> and <code>newValue</code> are not equal and the
     * <code>PropertyChangeEvent</code> listener list isn't empty,
     * then fire a <code>PropertyChange</code> event to each listener.
     * @param propertyName  the programmatic name of the property that was changed
     * @param oldValue the old value of the property (as an Object)
     * @param newValue the new value of the property (as an Object)
     * @see java.beans.PropertyChangeSupport
     */
    protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
    {
        if (listeners != null)
        {
            if (oldValue != null && newValue != null && oldValue.equals(newValue))
            {
                return;
            }

            if (listeners != null)
            {
                Object[] listenerList = listeners.getListenerList();
                for (int i = 0; i <= listenerList.length - 2; i += 2)
                {
                    if (listenerList[i] == PropertyChangeListener.class)
                    {
                        PropertyChangeEvent ev = new PropertyChangeEvent(this, propertyName, oldValue, newValue);
                        PropertyChangeListener li = (PropertyChangeListener) listenerList[i + 1];
                        li.propertyChange(ev);
                    }
                }
            }
        }
    }

    /**
     * The list of property change listeners
     */
    private transient EventListenerList listeners;
}

Index: DefaultBookMetaData.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/basic/DefaultBookMetaData.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** DefaultBookMetaData.java	5 Oct 2004 22:03:09 -0000	1.13
--- DefaultBookMetaData.java	9 Oct 2004 21:45:04 -0000	1.14
***************
*** 10,13 ****
--- 10,16 ----
  import org.crosswire.jsword.book.BookMetaData;
  import org.crosswire.jsword.book.BookType;
+ import org.crosswire.jsword.book.IndexStatus;
+ import org.crosswire.jsword.book.search.IndexManager;
+ import org.crosswire.jsword.book.search.IndexManagerFactory;
  
  /**
***************
*** 39,43 ****
   * @version $Id$
   */
! public class DefaultBookMetaData implements BookMetaData
  {
      /**
--- 42,46 ----
   * @version $Id$
   */
! public class DefaultBookMetaData extends AbstractBookMetaData
  {
      /**
***************
*** 54,59 ****
          setName(prop.getProperty(BookMetaData.KEY_NAME));
          setType(prop.getProperty(BookMetaData.KEY_TYPE));
- 
          setLanguage(prop.getProperty(BookMetaData.KEY_LANGUAGE));
      }
  
--- 57,71 ----
          setName(prop.getProperty(BookMetaData.KEY_NAME));
          setType(prop.getProperty(BookMetaData.KEY_TYPE));
          setLanguage(prop.getProperty(BookMetaData.KEY_LANGUAGE));
+ 
+         IndexManager imanager = IndexManagerFactory.getIndexManager();
+         if (imanager.isIndexed(book))
+         {
+             setIndexStatus(IndexStatus.DONE);
+         }
+         else
+         {
+             setIndexStatus(IndexStatus.UNDONE);
+         }
      }
  
***************
*** 167,170 ****
--- 179,201 ----
      }
  
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#getIndexStatus()
+      */
+     public IndexStatus getIndexStatus()
+     {
+         return indexStatus;
+     }
+ 
+     /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.BookMetaData#setIndexStatus(java.lang.String)
+      */
+     public void setIndexStatus(IndexStatus newValue)
+     {
+         IndexStatus oldValue = this.indexStatus;
+         this.indexStatus = newValue;
+         map.put(KEY_INDEXSTATUS, newValue);
+         firePropertyChange(KEY_INDEXSTATUS, oldValue, newValue);
+     }
+ 
      /**
       * @param book The book to set.
***************
*** 333,335 ****
--- 364,367 ----
      private String language = ""; //$NON-NLS-1$
      private String initials = ""; //$NON-NLS-1$
+     private IndexStatus indexStatus = IndexStatus.UNDONE;
  }

Index: AbstractBook.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/basic/AbstractBook.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** AbstractBook.java	29 Sep 2004 22:21:24 -0000	1.10
--- AbstractBook.java	9 Oct 2004 21:45:04 -0000	1.11
***************
*** 6,18 ****
  import org.crosswire.jsword.book.BookException;
  import org.crosswire.jsword.book.BookMetaData;
- import org.crosswire.jsword.book.Search;
- import org.crosswire.jsword.book.search.Index;
- import org.crosswire.jsword.book.search.IndexFactory;
- import org.crosswire.jsword.book.search.Matcher;
- import org.crosswire.jsword.book.search.MatcherFactory;
  import org.crosswire.jsword.book.search.Searcher;
  import org.crosswire.jsword.book.search.SearcherFactory;
- import org.crosswire.jsword.book.search.Thesaurus;
- import org.crosswire.jsword.book.search.ThesaurusFactory;
  import org.crosswire.jsword.passage.Key;
  
--- 6,11 ----
***************
*** 76,118 ****
  
      /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.search.Searcher#search(org.crosswire.jsword.book.Search)
       */
!     public Key find(Search search) throws BookException
      {
!         try
          {
!             if (index == null)
!             {
!                 index = IndexFactory.getIndexForBook(this);
!             }
! 
!             if (thesaurus == null)
!             {
!                 thesaurus = ThesaurusFactory.createThesaurus();
!             }
! 
!             if (search.isBestMatch())
              {
!                 if (matcher == null)
!                 {
!                     matcher = MatcherFactory.createMatcher(index, thesaurus);
!                 }
! 
!                 return matcher.bestMatch(search.getMatch(), search.getRestriction());
              }
!             else
              {
!                 if (searcher == null)
!                 {
!                     searcher = SearcherFactory.createSearcher(index);
!                 }
! 
!                 return searcher.search(search.getMatch(), search.getRestriction());
              }
          }
!         catch (InstantiationException ex)
!         {
!             throw new BookException(Msg.INDEX_FAIL);
!         }
      }
  
--- 69,89 ----
  
      /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.Book#find(java.lang.String)
       */
!     public Key find(String search) throws BookException
      {
!         if (searcher == null)
          {
!             try
              {
!                 searcher = SearcherFactory.createSearcher(this);
              }
!             catch (InstantiationException ex)
              {
!                 throw new BookException(Msg.INDEX_FAIL);
              }
          }
! 
!         return searcher.search(search);
      }
  
***************
*** 126,144 ****
  
      /**
-      * The global thesaurus
-      */
-     private Thesaurus thesaurus;
- 
-     /**
-      * The search index for this book
-      */
-     private Index index;
- 
-     /**
-      * How do we perform best matches
-      */
-     private Matcher matcher;
- 
-     /**
       * How do we perform searches
       */
--- 97,100 ----

Index: Verifier.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/basic/Verifier.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** Verifier.java	29 Sep 2004 22:21:24 -0000	1.27
--- Verifier.java	9 Oct 2004 21:45:04 -0000	1.28
***************
*** 10,14 ****
  import org.crosswire.jsword.book.BookData;
  import org.crosswire.jsword.book.BookException;
- import org.crosswire.jsword.book.Search;
  import org.crosswire.jsword.passage.BibleInfo;
  import org.crosswire.jsword.passage.Key;
--- 10,13 ----
***************
*** 198,203 ****
      private void checkSinglePassage(String word, PrintWriter out) throws BookException
      {
!         Key ref1 = book1.find(new Search(word, false));
!         Key ref2 = book2.find(new Search(word, false));
  
          // Check
--- 197,202 ----
      private void checkSinglePassage(String word, PrintWriter out) throws BookException
      {
!         Key ref1 = book1.find(word);
!         Key ref2 = book2.find(word);
  
          // Check



More information about the jsword-svn mailing list