use of org.xwiki.rendering.listener.reference.DocumentResourceReference in project xwiki-platform by xwiki.
the class DefaultDocumentSplitter method createLink.
/**
* Creates a {@link LinkBlock} suitable to be placed in the parent document.
*
* @param block the {@link Block} that has just been split into a separate document.
* @param target name of the target wiki document.
* @return a {@link LinkBlock} representing the link from the parent document to new document.
*/
private LinkBlock createLink(Block block, String target) {
Block firstBlock = block.getChildren().get(0);
if (firstBlock instanceof HeaderBlock) {
DocumentResourceReference reference = new DocumentResourceReference(target);
// Clone the header block and remove any unwanted stuff
Block clonedHeaderBlock = firstBlock.clone(new BlockFilter() {
@Override
public List<Block> filter(Block block) {
List<Block> blocks = new ArrayList<Block>();
if (block instanceof WordBlock || block instanceof SpaceBlock || block instanceof SpecialSymbolBlock) {
blocks.add(block);
}
return blocks;
}
});
return new LinkBlock(clonedHeaderBlock.getChildren(), reference, false);
} else if (firstBlock instanceof SectionBlock) {
return createLink(firstBlock, target);
} else {
throw new IllegalArgumentException("A SectionBlock should either begin with a HeaderBlock or another SectionBlock.");
}
}
Aggregations