in freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/Transform.java [1841:1915]
private void preprocessDOM_buildTOC_checkTOCTopology(TOCNode tocNode) {
// Check parent-child relation:
TOCNode parent = tocNode.getParent();
if (parent != null && !parent.getElement().isSameNode(
tocNode.getElement().getParentNode())) {
throw new DocgenException(
"Bad ToC-element topology: In the ToC "
+ parent.theSomethingElement()
+ " is the parent of "
+ tocNode.theSomethingElement()
+ ", yet they are not in parent-child relation in the XML "
+ "document (but maybe in grandparent-nephew relation or "
+ "like)."
+ COMMON_TOC_TOPOLOGY_ERROR_HINT);
}
// Check following-sibling relation:
TOCNode next = tocNode.getNext();
Element relevantSibling = preprocessDOM_buildTOC_getSectionLikeSibling(
tocNode.getElement(), true);
if (next != null) {
if (relevantSibling == null) {
throw new DocgenException(
"Bad ToC-element topology: In the ToC "
+ next.theSomethingElement()
+ " is the following sibling of "
+ tocNode.theSomethingElement()
+ ", yet they are not siblings in the XML document."
+ COMMON_TOC_TOPOLOGY_ERROR_HINT);
}
if (!relevantSibling.isSameNode(next.getElement())) {
throw new DocgenException(
"Bad ToC-element topology: In the ToC "
+ next.theSomethingElement()
+ " is the immediate following sibling of "
+ tocNode.theSomethingElement()
+ ", but in the XML document there is a \""
+ relevantSibling.getLocalName()
+ "\" element between them, or they aren't siblings "
+ "at all."
+ COMMON_TOC_TOPOLOGY_ERROR_HINT);
}
} else {
// next == null
if (relevantSibling != null) {
throw new DocgenException(
"Bad ToC-element topology: In the ToC hierarchy "
+ tocNode.theSomethingElement()
+ "\" is a last-child, but in the XML document it has "
+ "a \"" + relevantSibling.getLocalName() + "\" "
+ "element as its following sibling."
+ COMMON_TOC_TOPOLOGY_ERROR_HINT);
}
}
// Check preceding-sibling relation:
TOCNode prev = tocNode.getPrevious();
relevantSibling = preprocessDOM_buildTOC_getSectionLikeSibling(
tocNode.getElement(), false);
if (prev == null && relevantSibling != null) {
throw new DocgenException(
"Bad ToC-element topology: In the ToC hierarchy "
+ tocNode.theSomethingElement() + " is a first-child, "
+ "but in the XML document it has a "
+ "\"" + relevantSibling.getLocalName() + "\" "
+ "element as its preceding sibling."
+ COMMON_TOC_TOPOLOGY_ERROR_HINT);
}
TOCNode child = tocNode.getFirstChild();
while (child != null) {
preprocessDOM_buildTOC_checkTOCTopology(child);
child = child.getNext();
}
}