Package nl.siegmann.epublib.domain
Class TableOfContents
- java.lang.Object
-
- nl.siegmann.epublib.domain.TableOfContents
-
- All Implemented Interfaces:
java.io.Serializable
public class TableOfContents extends java.lang.Object implements java.io.SerializableThe table of contents of the book. The TableOfContents is a tree structure at the root it is a list of TOCReferences, each if which may have as children another list of TOCReferences. The table of contents is used by epub as a quick index to chapters and sections within chapters. It may contain duplicate entries, may decide to point not to certain chapters, etc. See the spine for the complete list of sections in the order in which they should be read.- See Also:
Spine, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_PATH_SEPARATORprivate static longserialVersionUIDprivate java.util.List<TOCReference>tocReferences
-
Constructor Summary
Constructors Constructor Description TableOfContents()TableOfContents(java.util.List<TOCReference> tocReferences)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TOCReferenceaddSection(Resource resource, int[] pathElements, java.lang.String sectionTitlePrefix, java.lang.String sectionNumberSeparator)Adds the given Resources to the TableOfContents at the location specified by the pathElements.TOCReferenceaddSection(Resource resource, java.lang.String path)Calls addTOCReferenceAtLocation after splitting the path using the DEFAULT_PATH_SEPARATOR.TOCReferenceaddSection(Resource resource, java.lang.String[] pathElements)Adds the given Resources to the TableOfContents at the location specified by the pathElements.TOCReferenceaddSection(Resource resource, java.lang.String path, java.lang.String pathSeparator)Calls addTOCReferenceAtLocation after splitting the path using the given pathSeparator.TOCReferenceaddTOCReference(TOCReference tocReference)intcalculateDepth()The maximum depth of the reference treeprivate intcalculateDepth(java.util.List<TOCReference> tocReferences, int currentDepth)private java.lang.StringcreateSectionTitle(int[] pathElements, int pathPos, int lastPos, java.lang.String sectionPrefix, java.lang.String sectionNumberSeparator)private static TOCReferencefindTocReferenceByTitle(java.lang.String title, java.util.List<TOCReference> tocReferences)Finds the first TOCReference in the given list that has the same title as the given Title.java.util.List<Resource>getAllUniqueResources()All unique references (unique by href) in the order in which they are referenced to in the table of contents.private static voidgetAllUniqueResources(java.util.Set<java.lang.String> uniqueHrefs, java.util.List<Resource> result, java.util.List<TOCReference> tocReferences)java.util.List<TOCReference>getTocReferences()private static intgetTotalSize(java.util.Collection<TOCReference> tocReferences)private voidpaddTOCReferences(java.util.List<TOCReference> currentTocReferences, int[] pathElements, int pathPos, java.lang.String sectionPrefix, java.lang.String sectionNumberSeparator)voidsetTocReferences(java.util.List<TOCReference> tocReferences)intsize()The total number of references in this table of contents.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
DEFAULT_PATH_SEPARATOR
public static final java.lang.String DEFAULT_PATH_SEPARATOR
- See Also:
- Constant Field Values
-
tocReferences
private java.util.List<TOCReference> tocReferences
-
-
Constructor Detail
-
TableOfContents
public TableOfContents()
-
TableOfContents
public TableOfContents(java.util.List<TOCReference> tocReferences)
-
-
Method Detail
-
getTocReferences
public java.util.List<TOCReference> getTocReferences()
-
setTocReferences
public void setTocReferences(java.util.List<TOCReference> tocReferences)
-
addSection
public TOCReference addSection(Resource resource, java.lang.String path)
Calls addTOCReferenceAtLocation after splitting the path using the DEFAULT_PATH_SEPARATOR.- Returns:
- the new TOCReference
-
addSection
public TOCReference addSection(Resource resource, java.lang.String path, java.lang.String pathSeparator)
Calls addTOCReferenceAtLocation after splitting the path using the given pathSeparator.- Parameters:
resource-path-pathSeparator-- Returns:
- the new TOCReference
-
findTocReferenceByTitle
private static TOCReference findTocReferenceByTitle(java.lang.String title, java.util.List<TOCReference> tocReferences)
Finds the first TOCReference in the given list that has the same title as the given Title.- Parameters:
title-tocReferences-- Returns:
- null if not found.
-
addSection
public TOCReference addSection(Resource resource, java.lang.String[] pathElements)
Adds the given Resources to the TableOfContents at the location specified by the pathElements. Example: Calling this method with a Resource and new String[] {"chapter1", "paragraph1"} will result in the following:- a TOCReference with the title "chapter1" at the root level.
If this TOCReference did not yet exist it will have been created and does not point to any resource - A TOCReference that has the title "paragraph1". This TOCReference will be the child of TOCReference "chapter1" and will point to the given Resource
- Parameters:
resource-pathElements-- Returns:
- the new TOCReference
- a TOCReference with the title "chapter1" at the root level.
-
addSection
public TOCReference addSection(Resource resource, int[] pathElements, java.lang.String sectionTitlePrefix, java.lang.String sectionNumberSeparator)
Adds the given Resources to the TableOfContents at the location specified by the pathElements. Example: Calling this method with a Resource and new int[] {0, 0} will result in the following:- a TOCReference at the root level.
If this TOCReference did not yet exist it will have been created with a title of "" and does not point to any resource - A TOCReference that points to the given resource and is a child of the previously created TOCReference.
If this TOCReference didn't exist yet it will be created and have a title of ""
- Parameters:
resource-pathElements-- Returns:
- the new TOCReference
- a TOCReference at the root level.
-
paddTOCReferences
private void paddTOCReferences(java.util.List<TOCReference> currentTocReferences, int[] pathElements, int pathPos, java.lang.String sectionPrefix, java.lang.String sectionNumberSeparator)
-
createSectionTitle
private java.lang.String createSectionTitle(int[] pathElements, int pathPos, int lastPos, java.lang.String sectionPrefix, java.lang.String sectionNumberSeparator)
-
addTOCReference
public TOCReference addTOCReference(TOCReference tocReference)
-
getAllUniqueResources
public java.util.List<Resource> getAllUniqueResources()
All unique references (unique by href) in the order in which they are referenced to in the table of contents.- Returns:
- All unique references (unique by href) in the order in which they are referenced to in the table of contents.
-
getAllUniqueResources
private static void getAllUniqueResources(java.util.Set<java.lang.String> uniqueHrefs, java.util.List<Resource> result, java.util.List<TOCReference> tocReferences)
-
size
public int size()
The total number of references in this table of contents.- Returns:
- The total number of references in this table of contents.
-
getTotalSize
private static int getTotalSize(java.util.Collection<TOCReference> tocReferences)
-
calculateDepth
public int calculateDepth()
The maximum depth of the reference tree- Returns:
- The maximum depth of the reference tree
-
calculateDepth
private int calculateDepth(java.util.List<TOCReference> tocReferences, int currentDepth)
-
-