}
public void generateTOCFromHeadings(Stack headings, int depth) {
if (elementName.startsWith("h") && elementName.length() == 2 && Character.isDigit(elementName.charAt(1))) {
int headingLevel = elementName.charAt(1) - '0';
TOCLevel level;
while (true) {
level = (TOCLevel) headings.pop();
if (headings.isEmpty() || level.getHeadingLevel() < headingLevel) {
headings.push(level);
break;
}
}
if (headings.size() < depth + 1) {
String title = getText();
TOCEntry entry = new TOCEntry(title, getSelfRef());
level.getTOCEntry().add(entry);
TOCLevel myLevel = new TOCLevel(headingLevel, entry);
headings.push(myLevel);
}
}
super.generateTOCFromHeadings(headings, depth);
}