Class TableOfContents
java.lang.Object
nl.siegmann.epublib.domain.TableOfContents
- All Implemented Interfaces:
Serializable
The 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprivate static final longprivate List<TOCReference> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddSection(Resource resource, int[] pathElements, String sectionTitlePrefix, String sectionNumberSeparator) Adds the given Resources to the TableOfContents at the location specified by the pathElements.addSection(Resource resource, String path) Calls addTOCReferenceAtLocation after splitting the path using the DEFAULT_PATH_SEPARATOR.addSection(Resource resource, String[] pathElements) Adds the given Resources to the TableOfContents at the location specified by the pathElements.addSection(Resource resource, String path, String pathSeparator) Calls addTOCReferenceAtLocation after splitting the path using the given pathSeparator.addTOCReference(TOCReference tocReference) intThe maximum depth of the reference treeprivate intcalculateDepth(List<TOCReference> tocReferences, int currentDepth) private StringcreateSectionTitle(int[] pathElements, int pathPos, int lastPos, String sectionPrefix, String sectionNumberSeparator) private static TOCReferencefindTocReferenceByTitle(String title, List<TOCReference> tocReferences) Finds the first TOCReference in the given list that has the same title as the given Title.All unique references (unique by href) in the order in which they are referenced to in the table of contents.private static voidgetAllUniqueResources(Set<String> uniqueHrefs, List<Resource> result, List<TOCReference> tocReferences) private static intgetTotalSize(Collection<TOCReference> tocReferences) private voidpaddTOCReferences(List<TOCReference> currentTocReferences, int[] pathElements, int pathPos, String sectionPrefix, String sectionNumberSeparator) voidsetTocReferences(List<TOCReference> tocReferences) intsize()The total number of references in this table of contents.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
DEFAULT_PATH_SEPARATOR
- See Also:
-
tocReferences
-
-
Constructor Details
-
TableOfContents
public TableOfContents() -
TableOfContents
-
-
Method Details
-
getTocReferences
-
setTocReferences
-
addSection
Calls addTOCReferenceAtLocation after splitting the path using the DEFAULT_PATH_SEPARATOR.- Returns:
- the new TOCReference
-
addSection
Calls addTOCReferenceAtLocation after splitting the path using the given pathSeparator.- Parameters:
resource-path-pathSeparator-- Returns:
- the new TOCReference
-
findTocReferenceByTitle
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
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, String sectionTitlePrefix, 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(List<TOCReference> currentTocReferences, int[] pathElements, int pathPos, String sectionPrefix, String sectionNumberSeparator) -
createSectionTitle
-
addTOCReference
-
getAllUniqueResources
-
getAllUniqueResources
-
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
-
calculateDepth
public int calculateDepth()The maximum depth of the reference tree- Returns:
- The maximum depth of the reference tree
-
calculateDepth
-