[jsword-devel] Valid module keys
DM Smith
dmsmith at crosswire.org
Sat Jan 11 20:30:38 MST 2014
On Jan 11, 2014, at 9:48 PM, Greg Hellings <greg.hellings at gmail.com> wrote:
> for (Key key : book.getKey(requestedReference)) {
> BookData data = new BookData(book, key);
>
> System.out.println(OSISUtil.getCanonicalText(data.getOSISFragment()));
> }
>
> This works fine for Bibles. I can iterate a single chapter, verse range, book, etc in a Bible. I can get out any entry in a Dictionary. I can even get the contents of a Gen Book if that sub-tree is only one level deep. E.g. I can get out Pilgrim's Progress 'SOURCE' section or 'TITLE' section. But I can't get out 'THE_AUTHOR'S_APOLOGY_FOR_HIS_BOOK' or 'PART_I'. Both of them throw a NoSuchKeyException, although getGlobalKeyList() returned a key whose OSIS ID claims to be equal to that string. Am I doing something wrong here, or breaking some sort of assumption about module types?
From memory:
The basic idea is that *a* key is either a leaf node or it can have (i.e. has) children.
So given a top level key. You'll need to ask it if it has children. If it does then you need to get them with that key's iterator.
This is true of every key: it implements hasChildren() which is a test that is needed before getting the children. And there are a variety of ways to get the children.
1) By iterator (it has multiple semantic depending on whether a Key is a single item, a list or a node in a tree)
2) by number (with key.getChildCount(), key.get(n)) (You can also reverse the call of get(n) with key.indexOf(c))
You'll either need recursion or a stack to do a depth first processing of the tree. I don't think we've had a use case for having that in JSword. So far getting the children has been by user demand.
The string that is used for a key in a gen book is a path from the root. I forget the representation of the path. I don't remember if there is a lookup given a path.
Given the above it is pretty easy. Split the path into a list. Match at the top level, iterate over the children until a match of the next level and repeat until last level is processed.
Hope this helps.
And welcome to the JSword world.
BTW, you may want to look at o.c.j.bridge and o.c.j.examples. For the most part I try to keep these up as a simple tutorial. Bridge is meant to be a collection of useful programs in their own right.
In Him,
DM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.crosswire.org/pipermail/jsword-devel/attachments/20140111/ec294619/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4145 bytes
Desc: not available
URL: <http://www.crosswire.org/pipermail/jsword-devel/attachments/20140111/ec294619/attachment-0001.p7s>
More information about the jsword-devel
mailing list