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:
Backend<GenBookBackendState>, StatefulFileBackedBackend<GenBookBackendState>

public class GenBookBackend
extends AbstractBackend<GenBookBackendState>

Backend for General Books.

Author:
DM Smith
See Also:
The GNU Lesser General Public License for details.

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.
 int getRawTextLength(Key key)
          Determine the size of the raw data for the key in question.
 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, getRawText, isSupported, isWritable, readToOsis, setAliasKey
 
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

Parameters:
sbmd -
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 interface: Backend
Determine whether this Book contains the key in question

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

getRawTextLength

public int getRawTextLength(Key key)
Description copied from interface: Backend
Determine the size of the raw data for the key in question. This method may not be faster than getting the raw text and getting its size.

Specified by:
getRawTextLength in interface Backend<GenBookBackendState>
Overrides:
getRawTextLength in class AbstractBackend<GenBookBackendState>
Parameters:
key - The key whose raw data length is desired.
Returns:
The length of the raw data, 0 if not a valid 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 interface: Backend
Initialize a AbstractBackend before use. This method needs to call addKey() a number of times on GenBookBackend

Specified by:
readIndex in interface Backend<GenBookBackendState>
Overrides:
readIndex in class AbstractBackend<GenBookBackendState>
Returns:
the list of all keys for the book

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

Parameters:
state - the open file state
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-2015