[jsword-devel] Module API

Joe Walker jsword-devel@crosswire.org
Sun, 16 Feb 2003 09:05:57 +0000


The short version:
    Project.init();
    Bible b = Defaults.getBibleMetaData().getBible();
    Passage p = PassageFactory.createPassage("Eph 1:18");
    BibleData bd = b.getData(p);
    String s = OsisUtil.getPlainText(bd);
Now this is over simplfied in 2 ways. Firstly it assumes you always only 
want the default Bible, and secondly it only gets you plain text - since 
we are using OSIS you would probably want something better.

How do I select a Bible other than the default?
Books is the interface to all Bibles/Dictionaries/Commentaries, and you 
need some way to tell it what you want. The sledgehammer approach is.
    List everything = Books.getBooks();
Or you can get just the Bibles:
    List bibles = Books.getBooks(BookFilters.getBibles());
BookFilters has a selection of commonly used filters, or you can write 
your own filter (see BookFilter)
Now all of the above get you a (list of) BibleMetaData objects from 
which you get the real Bible. A BibleMetaData object will tell you 
everything about the Bible but it will not read any data, to get the 
real data you need to call getBible().

How do I get something better than plain text?
The short version would be something like:
    SAXEventProvider provider = OsisUtil.getSAXEventProvider(bd);
    Style style = new Style("swing");
    String html = style.applyStyleToString(provider, "simple.xsl");
If you have a look in the resource directory you should see where the 
stylesheets are, so you're not limited to HTML.

How do I get the Commentary for a verse?
There is an inheritance hierachy; Book is at the top, and from this, 
Bible, Dictionary and Commentary are derived. The Books class will get 
you any of the above - you just need to give it a different BookFilter. 
 From then on just continue as you would for a Bible.
Dictionaries work in a similar way.

Caveat - The current CVS has full support for Sword modules except that 
Commentary and Dictionary support is being finished as we speak, so 
don't expect wonders just yet.
2nd Caveat - I don't expect the API above to change much, but we've not 
got to 1.0 yet so I'm not making any promises.

Joe.


Patrick Lacson wrote:

>Hello Everyone!
>
>Where in the JSword API does the actual reading of the
>modules?  Can somebody provide sample code of reading
>say Eph 1:18 and the Commentary on that verse?
>
>Thanks!
>
>Patrick
>_______________________________________________
>jsword-devel mailing list
>jsword-devel@crosswire.org
>http://www.crosswire.org/mailman/listinfo/jsword-devel
>  
>