[jsword-devel] Jsword web

Yiguang Hu yighu at yahoo.com
Fri Mar 21 20:00:37 MST 2008


DM,

I am trying to revitalize an effort to build a web
front based on jsword. I got a simple page doing bible
search working on my local desktop since I have
installed Bibles with the Bible desktop. But when I
deployed the war to a tomcat on linux, the search
FAILED since I didn't install  any Bible. I wrote a
simple code based on the sample code on the UI but got
nullpointerexception on the following line when I try
to use it to install bible.

             installer.reloadBookList();
What am I missing?
Thanks
Yiguang
 
public Testcode {
.....
public void installBook(String booktoinstall){
 
         // An installer knows how to install books
         Installer installer = null;
         
         InstallManager imanager = new
InstallManager();
 
        // Ask the Install Manager for a map of all
known module sites
         Map installers = imanager.getInstallers();
 
         // Get all the installers one after the other
         Iterator iter =
installers.keySet().iterator();
         while (iter.hasNext())
         {
             String name = (String) iter.next();
             installer = (Installer)
installers.get(name);
             
         }
 
         // If we know the name of the installer we
can get it directly
         installer =
imanager.getInstaller("CrossWire"); //$NON-NLS-1$
 
         // Now we can get the list of books
         try
         {
             installer.reloadBookList();
         }
         catch (InstallException e)
         {
             e.printStackTrace();
         }
 
         // Get a list of all the available books
         List availableBooks = installer.getBooks();
 
         // get some available books. In this case,
just one book.
         availableBooks = installer.getBooks(new
MyBookFilter(booktoinstall)); //$NON-NLS-1$
 
         Book book = (Book) availableBooks.get(0);
 
         if (book != null)
         {
             System.out.println("Book " +
book.getInitials() + " is available"); //$NON-NLS-1$
//$NON-NLS-2$
 
             // Delete the book, if present
             // At the moment, JSword will not
re-install. Later it will, if the remote version is
greater.
             try
             {
                 if
(Books.installed().getBook(booktoinstall) != null)
//$NON-NLS-1$
                 {
                     // Make the book unavailable.
                     // This is normally done via
listeners.
                    
Books.installed().removeBook(book);
 
                     // Actually do the delete
                     // This should be a call on
installer.
                     book.getDriver().delete(book);
                 }
             }
             catch (BookException e1)
             {
                 e1.printStackTrace();
             }
 
             try
             {
                 // Now install it. Note this is a
background task.
                 installer.install(book);
             }
             catch (InstallException e)
             {
                 e.printStackTrace();
             }
         }
     }

static class MyBookFilter implements BookFilter
     {
         public MyBookFilter(String bookName)
         {
             name = bookName;
         }
 
         public boolean test(Book bk)
         {
             return bk.getInitials().equals(name);
         }
 
         private String name;
     }
 
     /**
      * A simple BooksListener that actually does
nothing.
      */
     static class MyBooksListener implements
BooksListener
     {
         /* (non-Javadoc)
          * @see
org.crosswire.jsword.book.BooksListener#bookAdded(org.crosswire.jsword.book.BooksEvent)
          */
         public void bookAdded(BooksEvent ev)
         {
         }
 
         /* (non-Javadoc)
          * @see
org.crosswire.jsword.book.BooksListener#bookRemoved(org.crosswire.jsword.book.BooksEvent)
          */
         public void bookRemoved(BooksEvent ev)
         {
         }
     }
     public static void main(String[] args){
         Testcode sc=new Testcode();
         sc.installBook(args[0]);
     }
}


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs




More information about the jsword-devel mailing list