/** Add Table of content */ private Document toc() { // anything to do? if (toc.isEmpty()) return this; Element old = cursor; // pop back to flow pop("flow", "can't create TOC without enclosing flow"); // add block for toc AS FIRST child push("block", "", cursor.getFirstChild()); // <block> // Table of Contents // <block> // Title 1<leader/><page-number-citation/> // </block> // ... // </block> // add toc header push("block", formatSectionLarger); text(RESOURCES.getString("toc"), ""); pop(); // add toc entries for (Iterator it = toc.iterator(); it.hasNext(); ) { push( "block", "start-indent=1cm,end-indent=1cm,text-indent=0cm,text-align-last=justify,text-align=justify"); TOCEntry entry = (TOCEntry) it.next(); addLink(entry.text, entry.id); push("leader", "leader-pattern=dots").pop(); push("page-number-citation", "ref-id=" + entry.id).pop(); pop(); } // done cursor = old; return this; }
/** Add a link */ public Document addLink(String text, Entity entity) { addLink(text, entity.getTag() + "_" + entity.getId()); return this; }