public List<TocEntry> getTableOfContents() { if (this.book == null) { return null; } List<TocEntry> result = new ArrayList<BookView.TocEntry>(); flatten(book.getTableOfContents().getTocReferences(), result, 0); return result; }
private void flatten(List<TOCReference> refs, List<TocEntry> entries, int level) { if (refs == null || refs.isEmpty()) { return; } for (TOCReference ref : refs) { String title = ""; for (int i = 0; i < level; i++) { title += "-"; } title += ref.getTitle(); if (ref.getResource() != null) { entries.add(new TocEntry(title, spine.resolveTocHref(ref.getCompleteHref()))); } flatten(ref.getChildren(), entries, level + 1); } }