in freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/Transform.java [1706:1751]
private void preprocessDOM_addRanks_underBookRank(Element root) {
// Find the common rank:
DocumentStructureRank commonRank = null;
for (Element child : XMLUtil.childrenElementsOf(root)) {
String name = child.getLocalName();
if (name.equals(E_PART)) {
if (commonRank != null
&& !commonRank.equals(DocumentStructureRank.PART)) {
throw new DocgenException("Bad document structure: "
+ XMLUtil.theSomethingElement(child) + " is on the "
+ "same ToC level with a \"" + E_CHAPTER
+ "\" element.");
}
commonRank = DocumentStructureRank.PART;
} else if (name.equals(E_CHAPTER)) {
if (commonRank != null
&& !commonRank.equals(DocumentStructureRank.CHAPTER)) {
throw new DocgenException("Bad document structure: "
+ XMLUtil.theSomethingElement(child) + " is on the "
+ "same ToC level with a \"" + E_PART
+ "\" element.");
}
commonRank = DocumentStructureRank.CHAPTER;
}
}
if (commonRank == null) {
commonRank = DocumentStructureRank.CHAPTER;
}
// Apply the common rank plus go deeper:
for (Element child : XMLUtil.childrenElementsOf(root)) {
if (DOCUMENT_STRUCTURE_ELEMENTS.contains(child.getLocalName())) {
child.setAttribute(
A_DOCGEN_RANK, commonRank.toString());
// Even if this node received part rank, its children will not
// "feel like" being the children of a true part, unless its
// indeed a part:
if (child.getLocalName().equals(E_PART)) {
preprocessDOM_addRanks_underTruePart(child);
} else {
preprocessDOM_addRanks_underChapterRankOrDeeper(
child, 0);
}
}
}
}