Package org.docx4j.toc
Class TocFinder
java.lang.Object
org.docx4j.TraversalUtil.CallbackImpl
org.docx4j.toc.TocFinder
- All Implemented Interfaces:
TraversalUtil.Callback
Don't attempt to reuse this; create a new TocFinder object each time you invoke it.
Word (current version 2025 07) adds a table of contents in a content control.
<w:sdt>
<w:sdtPr>
<w:docPartObj>
<w:docPartGallery w:val="Table of Contents"/>
One which represents a table of figures though, is added without the content control.
<w:p>
<w:fldSimple w:instr=" TOC \h \z \c "Figure" ">
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionVisits a node in pre order (before its children have been visited).private CTSdtDocPartgetDocPartObj(SdtPr sdtPr) private booleanisDocPartToC(SdtBlock currentSDT) private voidWhen we add the heading paragraphs, the last one added will be a false positive (it contains the TOC field instruction), so remove it.booleanDecide whether this node's children should be traversed.voidwalkJAXBElements(Object parent)
-
Field Details
-
Constructor Details
-
TocFinder
public TocFinder()
-
-
Method Details
-
getTocSDT
- Returns:
- Since:
- 3.3.1
-
apply
Description copied from class:TraversalUtil.CallbackImplVisits a node in pre order (before its children have been visited). A node is visited only if all its parents have been traversed (TraversalUtil.CallbackImpl.shouldTraverse(Object)).Implementations can have side effects.
- Specified by:
applyin interfaceTraversalUtil.Callback- Specified by:
applyin classTraversalUtil.CallbackImpl
-
removeLastHeadingP
private void removeLastHeadingP()When we add the heading paragraphs, the last one added will be a false positive (it contains the TOC field instruction), so remove it. -
isDocPartToC
-
getDocPartObj
-
walkJAXBElements
- Specified by:
walkJAXBElementsin interfaceTraversalUtil.Callback- Overrides:
walkJAXBElementsin classTraversalUtil.CallbackImpl
-
getChildren
- Specified by:
getChildrenin interfaceTraversalUtil.Callback- Overrides:
getChildrenin classTraversalUtil.CallbackImpl
-
shouldTraverse
Decide whether this node's children should be traversed.- Specified by:
shouldTraversein interfaceTraversalUtil.Callback- Overrides:
shouldTraversein classTraversalUtil.CallbackImpl- Returns:
- whether the children of this node should be visited
-