org.crosswire.jsword.book
Class BookData

java.lang.Object
  extended by org.crosswire.jsword.book.BookData
All Implemented Interfaces:
BookProvider

public class BookData
extends Object
implements BookProvider

BookData is the assembler of the OSIS that is returned by the filters. As such it puts that into an OSIS document. When several books are supplied, it gets the data from each and puts it into a parallel or interlinear view. Note: it is critical that all the books are able to understand the same key. That does not mean that each has to have content for each key. Missing keys are represented by empty cells.

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

Nested Class Summary
(package private)  class BookData.BookVerseContent
          A temporary holder for a map that links each verse ID to its set of OSIS elements.
 
Field Summary
private  Book[] books
          The books to which the key should be applied.
private  boolean comparingBooks
          Whether the Books should be compared.
private  org.jdom2.Element fragment
          Just the element
private  Key key
          What key was used to create this data
private  org.jdom2.Element osis
          The complete OSIS container for the element
private  UnAccenter unaccenter
           
 
Constructor Summary
BookData(Book[] books, Key key, boolean compare)
          Create BookData for multiple books.
BookData(Book book, Key key)
          Create a BookData.
 
Method Summary
private  void addContentSafely(org.jdom2.Element cell, List<org.jdom2.Content> xmlContent)
          JDOM will throw an exception if we try and add the content to multiple parents.
private  boolean addHeaderAndSetShowDiffsState(org.jdom2.Element row, boolean[] showDiffs, int i, boolean ommittedVerse)
           
private  void addText(boolean doDiffs, StringBuilder newText, org.jdom2.Content content)
          Adds the text to the diff buffer
private  void addText(boolean doDiffs, StringBuilder newText, List<org.jdom2.Content> contents)
          Loops around contents and calls addText for a single element
private  org.jdom2.Element appendVersificationNotice(org.jdom2.Element parent, String notice)
          Creates a notice element.
 Book[] getBooks()
          Who created this data.
 Book getFirstBook()
          Get the first book.
 Key getKey()
          The key used to obtain data from one or more books.
 org.jdom2.Element getOsis()
          Accessor for the root OSIS element
private  org.jdom2.Element getOsisContent(boolean allowGenTitles)
           
 org.jdom2.Element getOsisFragment()
          Accessor for the requested data in OSIS format.
 org.jdom2.Element getOsisFragment(boolean allowGenTitles)
          Accessor for the root OSIS element
 SAXEventProvider getSAXEventProvider()
          Output the current data as a SAX stream.
private  Versification getVersification(int i)
           
 boolean isComparingBooks()
           
private  BookData.BookVerseContent keyIteratorContentByVerse(Versification v11n, Iterator<org.jdom2.Content> iter)
          We iterate through the content, making sure we key together those bits that belong together.
 void setUnaccenter(UnAccenter unaccenter)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

key

private Key key
What key was used to create this data


books

private Book[] books
The books to which the key should be applied.


comparingBooks

private boolean comparingBooks
Whether the Books should be compared.


osis

private org.jdom2.Element osis
The complete OSIS container for the element


fragment

private org.jdom2.Element fragment
Just the element


unaccenter

private UnAccenter unaccenter
Constructor Detail

BookData

public BookData(Book book,
                Key key)
Create a BookData.

Parameters:
book - the Book to which the data belongs
key - the Key specifying the data

BookData

public BookData(Book[] books,
                Key key,
                boolean compare)
Create BookData for multiple books.

Parameters:
books - the set of Books to which the data belongs
key - the Key specifying the data
compare - when true each pair of adjacent books is to be compared
Method Detail

getOsis

public org.jdom2.Element getOsis()
                          throws BookException
Accessor for the root OSIS element

Returns:
the root of the OSIS document representing this data
Throws:
BookException - if there is any problem with this request

getOsisFragment

public org.jdom2.Element getOsisFragment()
                                  throws BookException
Accessor for the requested data in OSIS format.

Returns:
the fragment of the OSIS document representing this data
Throws:
BookException - if there is any problem with this request

getOsisFragment

public org.jdom2.Element getOsisFragment(boolean allowGenTitles)
                                  throws BookException
Accessor for the root OSIS element

Parameters:
allowGenTitles - whether to generate titles
Returns:
the root of the document
Throws:
BookException - if there is any problem with this request

getSAXEventProvider

public SAXEventProvider getSAXEventProvider()
                                     throws BookException
Output the current data as a SAX stream.

Returns:
A way of posting SAX events
Throws:
BookException - if there is any problem with this request

getBooks

public Book[] getBooks()
Who created this data.

Specified by:
getBooks in interface BookProvider
Returns:
Returns the book.

getFirstBook

public Book getFirstBook()
Get the first book.

Specified by:
getFirstBook in interface BookProvider
Returns:
the first or only book

getKey

public Key getKey()
The key used to obtain data from one or more books.

Returns:
Returns the key.

isComparingBooks

public boolean isComparingBooks()
Returns:
whether the books should be compared.

getOsisContent

private org.jdom2.Element getOsisContent(boolean allowGenTitles)
                                  throws BookException
Throws:
BookException

addContentSafely

private void addContentSafely(org.jdom2.Element cell,
                              List<org.jdom2.Content> xmlContent)
JDOM will throw an exception if we try and add the content to multiple parents. As a result, we take the opportunity to add it safely, and add a note indicating this content appears twice.

Parameters:
cell - the element to be added
xmlContent - the collector of content

appendVersificationNotice

private org.jdom2.Element appendVersificationNotice(org.jdom2.Element parent,
                                                    String notice)
Creates a notice element.

Parameters:
parent - the parent to which the notice is added
notice - the notice fragment to be applied to the sub-type
Returns:
the new element

getVersification

private Versification getVersification(int i)
Parameters:
i - the current position in the array of books
Returns:
the versification of the book.

keyIteratorContentByVerse

private BookData.BookVerseContent keyIteratorContentByVerse(Versification v11n,
                                                            Iterator<org.jdom2.Content> iter)
                                                     throws BookException
We iterate through the content, making sure we key together those bits that belong together. And separating out each verse.

Parameters:
v11n - the versification for the content
iter - the iterator of OSIS content
Returns:
the verse content for the book
Throws:
BookException - if there is any problem with this request

addHeaderAndSetShowDiffsState

private boolean addHeaderAndSetShowDiffsState(org.jdom2.Element row,
                                              boolean[] showDiffs,
                                              int i,
                                              boolean ommittedVerse)
Parameters:
row - our current OSIS row
showDiffs - the array of states as to whether we are showing diffs for this column
i - our current place in the state
ommittedVerse - true to indicate this column will be ommiting a verse
Returns:
true if we are doing diffs

addText

private void addText(boolean doDiffs,
                     StringBuilder newText,
                     List<org.jdom2.Content> contents)
Loops around contents and calls addText for a single element

Parameters:
doDiffs - true for calculating differences
newText - the newText buffer used to compare one portion of text to another
contents - the contents to be added

addText

private void addText(boolean doDiffs,
                     StringBuilder newText,
                     org.jdom2.Content content)
Adds the text to the diff buffer

Parameters:
doDiffs - true for calculating differences
newText - the newText buffer used to compare one portion of text to another
content - the content element to be added

setUnaccenter

public void setUnaccenter(UnAccenter unaccenter)
Parameters:
unaccenter - the unaccenter to set

Copyright ยจ 2003-2015