org.crosswire.jsword.book.sword
Class GenBookBackend

java.lang.Object
  extended by org.crosswire.jsword.book.sword.AbstractBackend<GenBookBackendState>
      extended by org.crosswire.jsword.book.sword.GenBookBackend
All Implemented Interfaces:
StatefulFileBackedBackend<GenBookBackendState>

public class GenBookBackend
extends AbstractBackend<GenBookBackendState>

Backend for General Books.

Author:
DM Smith
See Also:
for license details.
The copyright to this program is held by it's authors.

Field Summary
private  TreeKeyIndex index
          The raw index file
private static org.slf4j.Logger log
          The log stream
 
Constructor Summary
GenBookBackend(SwordBookMetaData sbmd)
          Simple ctor
 
Method Summary
 boolean contains(Key key)
          Determine whether this Book contains the key in question
private  void doReadIndex(TreeNode parentNode, Key parentKey)
          A helper function to recursively read the entire tree.
private  TreeNode find(Key key)
          Given a Key, find the TreeNode for it.
 GenBookBackendState initState()
          Initialises the state required to read from files, specific to each different backend
 Key readIndex()
          Initialize a AbstractBackend before use.
 String readRawContent(GenBookBackendState state, Key key)
           
 void setAliasKey(GenBookBackendState state, Key alias, Key source)
          Sets alias for a comment on a verse range I.e.
 void setRawText(GenBookBackendState rafBook, Key key, String text)
          Set the text allotted for the given verse
 
Methods inherited from class org.crosswire.jsword.book.sword.AbstractBackend
create, decipher, encipher, getBookMetaData, getGlobalKeyList, getVersification, isSupported, isWritable, readToOsis
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

index

private final TreeKeyIndex index
The raw index file


log

private static final org.slf4j.Logger log
The log stream

Constructor Detail

GenBookBackend

public GenBookBackend(SwordBookMetaData sbmd)
Simple ctor

Method Detail

initState

public GenBookBackendState initState()
                              throws BookException
Description copied from interface: StatefulFileBackedBackend
Initialises the state required to read from files, specific to each different backend

Returns:
the state that has been initialised
Throws:
BookException

contains

public boolean contains(Key key)
Description copied from class: AbstractBackend
Determine whether this Book contains the key in question

Specified by:
contains in class AbstractBackend<GenBookBackendState>
Parameters:
key - The key whose presence is desired.
Returns:
true if the Book contains the key

readRawContent

public String readRawContent(GenBookBackendState state,
                             Key key)
                      throws IOException,
                             BookException
Parameters:
state - the state object containing all the open random access files
key - the verse that is sought
Returns:
the raw text
Throws:
IOException - something went wrong when reading the verse
BookException

find

private TreeNode find(Key key)
               throws IOException
Given a Key, find the TreeNode for it.

Parameters:
key - The key to use for searching
Returns:
the found node, null otherwise
Throws:
IOException

readIndex

public Key readIndex()
Description copied from class: AbstractBackend
Initialize a AbstractBackend before use. This method needs to call addKey() a number of times on GenBookBackend

Overrides:
readIndex in class AbstractBackend<GenBookBackendState>

setAliasKey

public void setAliasKey(GenBookBackendState state,
                        Key alias,
                        Key source)
                 throws IOException
Description copied from interface: StatefulFileBackedBackend
Sets alias for a comment on a verse range I.e. setRawText() was for verse range Gen.1.1-3 then setAliasKey should be called for Gen.1.1.2 and Gen.1.1.3

alias - Alias Key
source - Source Key
Throws:
IOException - Exception when anything goes wrong on writing the alias

setRawText

public void setRawText(GenBookBackendState rafBook,
                       Key key,
                       String text)
                throws BookException,
                       IOException
Description copied from interface: StatefulFileBackedBackend
Set the text allotted for the given verse

Parameters:
rafBook - TODO
key - The key to set text to
text - The text to be set for key
Throws:
BookException - If the data can not be set.
IOException - If the module data path could not be created.

doReadIndex

private void doReadIndex(TreeNode parentNode,
                         Key parentKey)
                  throws IOException
A helper function to recursively read the entire tree.

Parameters:
parentNode - the current node whose children are being sought
parentKey -
Throws:
IOException

Copyright ? 2003-2011