org.activemath.content
Class Book

java.lang.Object
  extended by org.activemath.content.Book
All Implemented Interfaces:
Comparable
Direct Known Subclasses:
RecBook, UserBook

public class Book
extends Object
implements Comparable

Describe me!


Field Summary
protected  ArrayList<String> allInstanciatedItems
           
protected  String creator
           
protected  OJDocument document
           
protected  String id
           
protected  String internalId
           
protected  Map<String,List<Page>> item2pages
           
protected static Logger log
           
protected  Metadata metadata
           
protected  ArrayList<Page> pages
           
protected  String title
           
protected  Map<String,String> titles
           
protected  Toc toc
           
protected static org.jdom.output.XMLOutputter xml
           
protected  Page zeroPage
           
 
Constructor Summary
protected Book()
          No constructor, use @see createBook() instead
 
Method Summary
protected  void buildPages()
          Initialize the page and toc objects for this book.
protected  void buildPages0(OJElement elem)
          Recursive page builder Will create a new @link Page when there is at least one "ref" child or "dynamic" child.
protected  Page buildZeroPage()
           
protected  Page buildZeroPage(String userId)
          Construct the zero page and instanciate all dynamic items on the way.
 int compareTo(Object o)
           
 boolean containsDynamicItem()
          Check if the book contains dynamicItems after it was instanciated once.
static RecBook createBook(String recBookKey, OJDocument document)
          Create a RecBook from an OMDoc document.
static UserBook createBook(String userId, String bookId, org.jdom.Document document, String title, String desc, String scenario, String[] goals)
          Create a User Book from an OMDoc document.
static UserBook createBook(String userId, String bookId, OJDocument document, OJDocument skeleton)
          Create a User Book from an OMDoc document and skeleton.
static GapDetectionBook createGapDetectionBook(boolean store, UserBook userBook)
          Create a GapDetectionBook from a UserBook This is due to hibernate
static org.activemath.content.TutorBook createTutorBook(String newId, UserBook userBook)
          Create a TutorBook from a UserBook
 boolean equals(Object o)
           
 List<String> getAllInstanciatedItems()
           
 List<String> getAllMBaseIDs()
          Return a list of all Sting Ids of MbaseRefs in the UserBook.
 String getCollectionId()
           
static Comparator<Book> getComparator(String lang)
          Return a Comparator for book titles in a language.
 String getCreator()
           
 String getDescription(String lang)
           
 Map<String,String> getDescriptions()
           
 OJDocument getDocument()
          Get the XML document defining this book.
 String getDocumentString()
          Needed by Hibernate persistance
 String getId()
           
 String getInternalId()
           
 Metadata getMetadata()
           
 int getNumExercises()
           
 int getNumItems()
           
 String getOwner()
          Needed here so Velocity can work it out
 String getOwnerBookId()
           
 Page getPage(int pageNum)
           
 Page getPage(String pageId)
           
 List<Page> getPages()
           
 List<Page> getPagesContaining(String itemId)
           
 String getTitle()
           
 String getTitle(List languages)
          Goes along the languages list and returns the first non-empty title, or any title.
 String getTitle(List languages, boolean atLeastSomething)
          Goes along the languages list and returns the first non-empty title.
 String getTitle(String lang)
          Get localized Book title, without fallback to default language
 String getTitle(String lang, String defaultLang)
          Get localized Book title, with fallback to default language
 Map<String,String> getTitleMap()
           
 TocEntry getToc()
           
 TocEntry getTocEntry(String id)
           
 TocEntry getTocEntryByPage(String pageId)
           
 int hashCode()
           
 boolean isTutorBook()
           
 boolean isUserBook()
           
protected  void setCreator(String creator)
           
 void setDescription(String lang, String desc)
           
 void setDescriptions(Map map)
           
 void setDocument(OJDocument document)
          Set the XML document defining this book.
 void setDocumentString(String docString)
          Needed by Hibernate persistance
 void setInternalId(String string)
           
 void setNumExercises(int numExercises)
           
 void setTitle(String string)
           
 void setTitle(String lang, String title)
          Set book title for specific language.
protected  void setTitleMap(Map<String,String> titles)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static Logger log

id

protected String id

internalId

protected String internalId

title

protected String title

titles

protected Map<String,String> titles

creator

protected String creator

metadata

protected Metadata metadata

document

protected OJDocument document

zeroPage

protected Page zeroPage

pages

protected ArrayList<Page> pages

toc

protected Toc toc

item2pages

protected Map<String,List<Page>> item2pages

allInstanciatedItems

protected ArrayList<String> allInstanciatedItems

xml

protected static org.jdom.output.XMLOutputter xml
Constructor Detail

Book

protected Book()
No constructor, use @see createBook() instead

Method Detail

isUserBook

public boolean isUserBook()

isTutorBook

public boolean isTutorBook()

getOwner

public String getOwner()
Needed here so Velocity can work it out


getOwnerBookId

public String getOwnerBookId()

createBook

public static RecBook createBook(String recBookKey,
                                 OJDocument document)
Create a RecBook from an OMDoc document.

Throws:
NullPointerException - when parameters are null, or initializing document is garbage

createBook

public static UserBook createBook(String userId,
                                  String bookId,
                                  org.jdom.Document document,
                                  String title,
                                  String desc,
                                  String scenario,
                                  String[] goals)
Create a User Book from an OMDoc document. The document is stored until pages are retrieved.

Throws:
NullPointerException - when parameters are null, or initializing document is garbage

createBook

public static UserBook createBook(String userId,
                                  String bookId,
                                  OJDocument document,
                                  OJDocument skeleton)
Create a User Book from an OMDoc document and skeleton. The document is stored until pages are retrieved.

Throws:
NullPointerException - when parameters are null, or initializing document is garbage

createTutorBook

public static org.activemath.content.TutorBook createTutorBook(String newId,
                                                               UserBook userBook)
Create a TutorBook from a UserBook


createGapDetectionBook

public static GapDetectionBook createGapDetectionBook(boolean store,
                                                      UserBook userBook)
Create a GapDetectionBook from a UserBook This is due to hibernate


buildPages

protected void buildPages()
Initialize the page and toc objects for this book. This is done lazily since it will access MBase.


buildZeroPage

protected Page buildZeroPage(String userId)
Construct the zero page and instanciate all dynamic items on the way.


buildZeroPage

protected Page buildZeroPage()

buildPages0

protected void buildPages0(OJElement elem)
Recursive page builder Will create a new @link Page when there is at least one "ref" child or "dynamic" child. Else will recurse into omgroup elements.


getId

public String getId()

getCollectionId

public String getCollectionId()
Returns:
id of collection this book belongs to

getInternalId

public String getInternalId()
Returns:
internal Id (for MBase)

setInternalId

public void setInternalId(String string)

setTitle

public void setTitle(String string)

getTitle

public String getTitle()

getTitleMap

public Map<String,String> getTitleMap()

setTitleMap

protected void setTitleMap(Map<String,String> titles)

setTitle

public void setTitle(String lang,
                     String title)
Set book title for specific language.


getTitle

public String getTitle(String lang)
Get localized Book title, without fallback to default language


getTitle

public String getTitle(String lang,
                       String defaultLang)
Get localized Book title, with fallback to default language

Parameters:
lang -
defaultLang -
Returns:
Return localized title for this Book, either in
  • requested language
  • requested default language
  • this.title, which is any title we get from mbase.getCommonName()

    getTitle

    public String getTitle(List languages,
                           boolean atLeastSomething)
    Goes along the languages list and returns the first non-empty title.

    Parameters:
    languages - the list of language
    atLeastSomething - fallback to use getTitle() which will return any title
    Returns:
    the found title or, at worst, null

    getTitle

    public String getTitle(List languages)
    Goes along the languages list and returns the first non-empty title, or any title.

    Parameters:
    languages - the list of language
    Returns:
    the found title or, at worst, null

    getDocument

    public OJDocument getDocument()
    Get the XML document defining this book.

    Do not add elements to it that are not of type OJElement.

    Returns:
    the XML document defining this book

    setDocument

    public void setDocument(OJDocument document)
    Set the XML document defining this book. This will clear all pages and init the book anew.


    getDocumentString

    public String getDocumentString()
    Needed by Hibernate persistance


    setDocumentString

    public void setDocumentString(String docString)
    Needed by Hibernate persistance


    getMetadata

    public Metadata getMetadata()
    Returns:
    metadata object for this item

    getDescriptions

    public Map<String,String> getDescriptions()
    Returns:
    Map: "lang" -> "descr"

    getDescription

    public String getDescription(String lang)
    Parameters:
    lang -
    Returns:
    book description in language lang, or null.

    setDescription

    public void setDescription(String lang,
                               String desc)

    setDescriptions

    public void setDescriptions(Map map)

    getToc

    public TocEntry getToc()
    Returns:
    List of TocEntry objects

    getPages

    public List<Page> getPages()
    Returns:
    List of Page objects

    getPagesContaining

    public List<Page> getPagesContaining(String itemId)
    Returns:
    List of Page objects where item appears, or empty list.

    getPage

    public Page getPage(int pageNum)

    getPage

    public Page getPage(String pageId)
    Parameters:
    pageId - a numeric string
    Returns:
    the page

    getAllInstanciatedItems

    public List<String> getAllInstanciatedItems()
    Returns:
    a List of all currently instanciated items (content ids as String)

    getNumItems

    public int getNumItems()
    Returns:
    number of Items contained in the book

    getNumExercises

    public int getNumExercises()
    Returns:
    number of Exercises contained in the book

    setNumExercises

    public void setNumExercises(int numExercises)

    getTocEntry

    public TocEntry getTocEntry(String id)
    Returns:
    Returns tocEntry with given id, or null.

    getTocEntryByPage

    public TocEntry getTocEntryByPage(String pageId)
    Returns:
    Returns tocEntry with given id, or null.

    setCreator

    protected void setCreator(String creator)

    getCreator

    public String getCreator()

    compareTo

    public int compareTo(Object o)
    Specified by:
    compareTo in interface Comparable
    See Also:
    Comparable.compareTo(java.lang.Object)

    equals

    public boolean equals(Object o)
    Overrides:
    equals in class Object
    See Also:
    Object.equals(java.lang.Object)

    hashCode

    public int hashCode()
    Overrides:
    hashCode in class Object
    See Also:
    Object.hashCode()

    getComparator

    public static Comparator<Book> getComparator(String lang)
    Return a Comparator for book titles in a language. eg: Collections.sort(recBooks, Book.getComparator(lang));


    containsDynamicItem

    public boolean containsDynamicItem()
    Check if the book contains dynamicItems after it was instanciated once.

    Returns:
    whether it does

    getAllMBaseIDs

    public List<String> getAllMBaseIDs()
    Return a list of all Sting Ids of MbaseRefs in the UserBook. Als precondition of this method is that the Pages of the UserBook is already initialised.

    Returns:
    List of Strings