@Override public boolean shouldSplit(Block block, int depth) { boolean shouldSplit = false; if (block instanceof SectionBlock) { SectionBlock section = (SectionBlock) block; Block firstChild = section.getChildren().get(0); shouldSplit = (firstChild instanceof HeaderBlock) && (Arrays.binarySearch(headingLevels, depth) >= 0); } return shouldSplit; } }
/** * @return the title block of the section. */ public HeaderBlock getHeaderBlock() { HeaderBlock headerBlock = null; List<Block> children = getChildren(); if (children.size() > 0) { Block firstChild = children.get(0); if (firstChild instanceof HeaderBlock) { headerBlock = (HeaderBlock) firstChild; } } return headerBlock; } }
/** * Get the content to display (either the entire document content or the content of a specific section). * * @param document the source document * @param parameters the display parameters * @return the content as an XDOM tree */ private XDOM getContent(DocumentModelBridge document, final DocumentDisplayerParameters parameters) { XDOM content = parameters.isContentTranslated() ? getTranslatedContent(document) : document.getXDOM(); if (parameters.getSectionId() != null) { HeaderBlock headerBlock = content.getFirstBlock(new CompositeBlockMatcher(new ClassBlockMatcher(HeaderBlock.class), new BlockMatcher() { @Override public boolean match(Block block) { return ((HeaderBlock) block).getId().equals(parameters.getSectionId()); } }), Block.Axes.DESCENDANT); if (headerBlock == null) { throw new RuntimeException("Cannot find section [" + parameters.getSectionId() + "] in document [" + this.defaultEntityReferenceSerializer.serialize(document.getDocumentReference()) + "]"); } else { content = new XDOM(headerBlock.getSection().getChildren(), content.getMetaData()); } } return content; }