[jsword-devel] API Example

DM Smith dmsmith at crosswire.org
Fri Sep 10 12:04:41 MST 2010


  You are very close, though I don't know why you are having a timeout 
issue.

It looks like there are a couple of things going on. I suggest trying to 
separate them.
What platform are you developing for? Unix/Linux, Windows, Mac or 
something else? If something else, that might be a problem to solve. 
This helps find the default location for mods.d and modules folder. (The 
example code does not allow for anything but default preferences.)

It should be located at:
      OSType.getOSType().getUserAreaFolder(".sword", "Sword").
Make sure that directory exists and that the conf and the module's files 
are appropriately under there in mods.d and modules respectively.


Try to separate the installer from doing a lookup. That way you isolate 
whether the problem is installing or if it is in doing a lookup.

Without the installer you can do the following to find a book:
     Book book = Books.installed().getBook("KJV"); // or what ever 
"initials" you want to use.

To do a lookup in that book (just as you have done):
         Key key = book.getKey("Gen 1:1");
         BookData data = new BookData(book, key);
         String text = OSISUtil.getCanonicalText(data.getOsisFragment());

Regarding deleting:
The call to Books.installed().remove(book); is unnecessary. The comment 
is correct: doing that will make the book not be visible during the 
current process. Run it again and it will be visible.

The second call, book.getDriver().delete(book), should delete the conf 
and all the files in the module. It won't delete the index.

To delete the index, if present, you'll need to do:
     IndexManager imanager = IndexManagerFactory.getIndexManager();
     if (imanager.isIndexed(book)) {
         imanager.deleteIndex(book);
     }

Let me know if this works.

In Him,
     DM

On 09/10/2010 01:49 PM, Matthias Wegner wrote:
>
> Hi All,
>
> my Name is Matthias Wegner from Germany, Freiburg. I develop since 13 
> years java and want to use the jsword api for an own application. For 
> that I need some bibles and a search for the bible text in dependency 
> of the "key". I try since three days to get the given API Example 
> working. I think I understood in a raw concept what the different 
> Installer-Classes and the WebRessource-Class are doing, but I don't 
> get it what is going wrong.
>
> i tried to get a working APIExample. I use the newest Eclipse, load 
> all Librarys from Maven and have a working set. My problem is, that I 
> always get a timeout (I moved, so I only have UMTS at the moment). 
> When I put the timeout in WebResource-Class to 5000ms the Application 
> below starts, but I always get in the Console
>
> *ESV***
>
> *Book contains key: false***
>
> *Text is ''*
>
> * *
>
> I don't get what i am doing wrong. Is the problem a connection 
> problem? When I put manually the esv.conf in the mods.d-directory, 
> then the book is removed and deleted (that means only the 
> config-file). Is that the way it goes? I downloaded the esv and put it 
> relative to mods.d to "../modules". In the full desktop application 
> this works fine, so I don't understood whats wrong.
>
> I really appreciate some help or hints. Can you give me some tryouts, 
> so I can find the "real" problem?
>
> Warm Regards,
>
> Matthias
>
> Example Code:
>
> *    public* *static* *void* main(String[] args) {
>
>         InstallManager imanager = *new* InstallManager();
>
>         Installer installer = imanager.getInstaller("CrossWire");
>
> *try* {
>
>             installer.reloadBookList();
>
>         }
>
> *catch* (InstallException e) {
>
>             e.printStackTrace();
>
>         }
>
> _List_ availableBooks = installer.getBooks(*new* MyBookFilter("ESV"));
>
>         Book book = (Book) availableBooks.get(0);
>
> *if* (book != *null*) {
>
> *try* {
>
> *if* (Books./installed/().getBook("ESV") != *null*) {
>
>                   System./out/.println("Book " + book.getInitials() + 
> " is removed");
>
>                     Books./installed/().removeBook(book);
>
>                     System./out/.println("Book " + book.getInitials() 
> + " is deleted");
>
>                     book.getDriver().delete(book);
>
>                 }
>
>             }
>
> *catch* (BookException e1)
>
>             {
>
>                 e1.printStackTrace();
>
>             }
>
>         }
>
>         System./out/.println(book.getInitials());
>
> *try* {
>
>             installer.install(book);
>
> *if* (Books./installed/().getBook("ESV") != *null*) {
>
>                   System./out/.println("Book is NOT empty");
>
>             }
>
>         }
>
> *catch* (InstallException e) {
>
>             e.printStackTrace();
>
>         }
>
> *try* {
>
>                   Key key = book.getKey("Gen 1:1");
>
>                   System./out/.println("Book contains key: "+ 
> book.contains(key));
>
>                   BookData data = *new* BookData(book, key);
>
>               String text = 
> OSISUtil./getCanonicalText/(data.getOsisFragment());
>
>               System./out/.println("Text is '" + text+"'");
>
>             } *catch* (NoSuchKeyException e) {
>
>                   e.printStackTrace();
>
>             } *catch* (BookException e) {
>
>                   e.printStackTrace();
>
>             }
>
>         System./exit/(1);
>
>       }
>
> *static* *class* MyBookFilter *implements* BookFilter
>
>     {
>
> *public* MyBookFilter(String bookName)
>
>         {
>
> name = bookName;
>
>         }
>
> *public* *boolean* test(Book bk)
>
>         {
>
> *return* bk.getInitials().equals(name);
>
> }
>
> *private* String name;
>
>     }
>
>
> _______________________________________________
> jsword-devel mailing list
> jsword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/jsword-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.crosswire.org/pipermail/jsword-devel/attachments/20100910/b6a075dd/attachment-0001.html>


More information about the jsword-devel mailing list