Class TableOfContents

java.lang.Object
nl.siegmann.epublib.domain.TableOfContents
All Implemented Interfaces:
Serializable

public class TableOfContents extends Object implements 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 Details

  • Constructor Details

    • TableOfContents

      public TableOfContents()
    • TableOfContents

      public TableOfContents(List<TOCReference> tocReferences)
  • Method Details

    • getTocReferences

      public List<TOCReference> getTocReferences()
    • setTocReferences

      public void setTocReferences(List<TOCReference> tocReferences)
    • addSection

      public TOCReference addSection(Resource resource, String path)
      Calls addTOCReferenceAtLocation after splitting the path using the DEFAULT_PATH_SEPARATOR.
      Returns:
      the new TOCReference
    • addSection

      public TOCReference addSection(Resource resource, String path, 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(String title, 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, 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
    • 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
    • paddTOCReferences

      private void paddTOCReferences(List<TOCReference> currentTocReferences, int[] pathElements, int pathPos, String sectionPrefix, String sectionNumberSeparator)
    • createSectionTitle

      private String createSectionTitle(int[] pathElements, int pathPos, int lastPos, String sectionPrefix, String sectionNumberSeparator)
    • addTOCReference

      public TOCReference addTOCReference(TOCReference tocReference)
    • getAllUniqueResources

      public 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(Set<String> uniqueHrefs, List<Resource> result, 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(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(List<TOCReference> tocReferences, int currentDepth)