/** * Get the position of the provided block in the list of children. * <p> * Can't use {@link List#indexOf(Object)} since it's using {@link Object#equals(Object)} internally which is not * what we want since two WordBlock with the same text or two spaces are equals for example but we want to be able * to target one specific Block. * * @param block the block * @return the position of the block, -1 if the block can't be found */ private int indexOfChild(Block block) { return indexOfBlock(block, getChildren()); }
/** * {@inheritDoc} * * @see org.xwiki.rendering.block.Block#getChildrenByType(java.lang.Class, boolean) */ public <T extends Block> List<T> getChildrenByType(Class<T> blockClass, boolean recurse) { List<T> typedBlocks = new ArrayList<T>(); for (Block block : getChildren()) { if (blockClass.isAssignableFrom(block.getClass())) { typedBlocks.add(blockClass.cast(block)); } if (recurse && !block.getChildren().isEmpty()) { typedBlocks.addAll(block.getChildrenByType(blockClass, true)); } } return typedBlocks; }
/** * {@inheritDoc} * * @see org.xwiki.rendering.block.Block#removeBlock(Block) * @since 2.6RC1 */ public void removeBlock(Block childBlockToRemove) { getChildren().remove(childBlockToRemove); if (childBlockToRemove != null) { Block previousBlock = childBlockToRemove.getPreviousSibling(); if (previousBlock != null) { previousBlock.setNextSiblingBlock(childBlockToRemove.getNextSibling()); } Block nextBlock = childBlockToRemove.getNextSibling(); if (nextBlock != null) { nextBlock.setPreviousSiblingBlock(previousBlock); } childBlockToRemove.setNextSiblingBlock(null); childBlockToRemove.setPreviousSiblingBlock(null); } }
List<Block> blocks = getChildren();