Package org.xwiki.rendering.block
Class AbstractBlock
- java.lang.Object
-
- org.xwiki.rendering.block.AbstractBlock
-
- Direct Known Subclasses:
AbstractMacroBlock
,BulletedListBlock
,CompositeBlock
,DefinitionDescriptionBlock
,DefinitionListBlock
,DefinitionTermBlock
,EmptyLinesBlock
,FigureBlock
,FigureCaptionBlock
,FormatBlock
,GroupBlock
,HeaderBlock
,HorizontalLineBlock
,IdBlock
,ImageBlock
,LinkBlock
,ListItemBlock
,MetaDataBlock
,NewLineBlock
,NumberedListBlock
,ParagraphBlock
,QuotationBlock
,QuotationLineBlock
,RawBlock
,SectionBlock
,SpaceBlock
,SpecialSymbolBlock
,TableBlock
,TableCellBlock
,TableRowBlock
,VerbatimBlock
,WordBlock
public abstract class AbstractBlock extends Object implements Block
Implementation for Block operations. All blocks should extend this class. Supports the notion of generic parameters which can be added to a block (seegetParameter(String)
for more details.- Since:
- 1.5M2
- Version:
- $Id: 0b3886c2e5bb03085740c7116d96bc2674b63eef $
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.xwiki.rendering.block.Block
Block.Axes
-
-
Field Summary
-
Fields inherited from interface org.xwiki.rendering.block.Block
LIST_BLOCK_TYPE
-
-
Constructor Summary
Constructors Constructor Description AbstractBlock()
Empty constructor to construct an empty block.AbstractBlock(List<? extends Block> childrenBlocks)
Constructs a block with children blocks.AbstractBlock(List<? extends Block> childrenBlocks, Map<String,String> parameters)
Construct a block with children blocks and parameters.AbstractBlock(Map<String,String> parameters)
Construct a block with parameters.AbstractBlock(Block childBlock)
Constructs a block with a child block.AbstractBlock(Block childBlock, Map<String,String> parameters)
Construct a block with a child block and parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChild(Block blockToAdd)
Helper method to add a single child block to the end of the children list of the current block.void
addChildren(List<? extends Block> blocksToAdd)
Adds several children blocks to the end of the children list of the current block.void
after(Listener listener)
SendListener
events corresponding to the end of the block.void
before(Listener listener)
SendListener
events corresponding to the start of the block.Block
clone()
Block
clone(BlockFilter blockFilter)
Return a copy of the block with filtered children.boolean
equals(Object obj)
<T extends Block>
List<T>getBlocks(BlockMatcher matcher, Block.Axes axes)
Get all blocks following providedBlockMatcher
andBlock.Axes
.List<Block>
getChildren()
Gets all children blocks.<T extends Block>
TgetFirstBlock(BlockMatcher matcher, Block.Axes axes)
Get the first matched block in the providedBlock.Axes
.Block
getNextSibling()
String
getParameter(String name)
A Parameter is a generic key/value which can be used to add metadata to a block.Map<String,String>
getParameters()
Block
getParent()
Get the parent block.Block
getPreviousSibling()
Block
getRoot()
Gets the top level Block.int
hashCode()
long
indexOf(Block child)
Find the index of the block in the tree.void
insertChildAfter(Block blockToInsert, Block previousBlock)
Helper method to add a single child block to the current block after the provided existing child block.void
insertChildBefore(Block blockToInsert, Block nextBlock)
Helper method to add a single child block to the current block before the provided existing child block.void
removeBlock(Block childBlockToRemove)
Removes a Block.void
replaceChild(List<Block> newBlocks, Block oldBlock)
Replaces an existing children block with the passed new blocks.void
replaceChild(Block newBlock, Block oldBlock)
Replaces an existing children block with the passed new block.void
setChildren(List<? extends Block> children)
Replace current children by the provided list ofBlock
s.void
setNextSiblingBlock(Block nextSiblingBlock)
void
setParameter(String name, String value)
Set a parameter on the current block.void
setParameters(Map<String,String> parameters)
Set several parameters at once.void
setParent(Block parentBlock)
Sets the parent block.void
setPreviousSiblingBlock(Block previousSiblingBlock)
void
traverse(Listener listener)
Let the block sendListener
events corresponding to its content.
-
-
-
Constructor Detail
-
AbstractBlock
public AbstractBlock()
Empty constructor to construct an empty block.
-
AbstractBlock
public AbstractBlock(Map<String,String> parameters)
Construct a block with parameters.- Parameters:
parameters
- the parameters to set
-
AbstractBlock
public AbstractBlock(Block childBlock)
Constructs a block with a child block.- Parameters:
childBlock
- the child block of this block- Since:
- 3.0M1
-
AbstractBlock
public AbstractBlock(List<? extends Block> childrenBlocks)
Constructs a block with children blocks.- Parameters:
childrenBlocks
- the list of children blocks of the block to construct- Since:
- 3.0M1
-
AbstractBlock
public AbstractBlock(Block childBlock, Map<String,String> parameters)
Construct a block with a child block and parameters.- Parameters:
childBlock
- the child block of this blockparameters
- the parameters to set- Since:
- 3.0M1
-
-
Method Detail
-
addChild
public void addChild(Block blockToAdd)
Description copied from interface:Block
Helper method to add a single child block to the end of the children list of the current block. For adding several blocks at once useBlock.addChildren(java.util.List)
.
-
addChildren
public void addChildren(List<? extends Block> blocksToAdd)
Description copied from interface:Block
Adds several children blocks to the end of the children list of the current block. For example a bold sentence is made up of a Bold block to which the different words making up the text have been added to.- Specified by:
addChildren
in interfaceBlock
- Parameters:
blocksToAdd
- the children blocks to add
-
setChildren
public void setChildren(List<? extends Block> children)
Description copied from interface:Block
Replace current children by the provided list ofBlock
s.- Specified by:
setChildren
in interfaceBlock
- Parameters:
children
- the new children
-
setNextSiblingBlock
public void setNextSiblingBlock(Block nextSiblingBlock)
- Specified by:
setNextSiblingBlock
in interfaceBlock
- Parameters:
nextSiblingBlock
- seeBlock.getNextSibling()
-
setPreviousSiblingBlock
public void setPreviousSiblingBlock(Block previousSiblingBlock)
- Specified by:
setPreviousSiblingBlock
in interfaceBlock
- Parameters:
previousSiblingBlock
- seeBlock.getPreviousSibling()
()}
-
insertChildBefore
public void insertChildBefore(Block blockToInsert, Block nextBlock)
Description copied from interface:Block
Helper method to add a single child block to the current block before the provided existing child block. For adding several blocks at once useBlock.addChildren(java.util.List)
.- Specified by:
insertChildBefore
in interfaceBlock
- Parameters:
blockToInsert
- the child block to addnextBlock
- the child block that will be just after the added block
-
insertChildAfter
public void insertChildAfter(Block blockToInsert, Block previousBlock)
Description copied from interface:Block
Helper method to add a single child block to the current block after the provided existing child block. For adding several blocks at once useBlock.addChildren(java.util.List)
.- Specified by:
insertChildAfter
in interfaceBlock
- Parameters:
blockToInsert
- the child block to addpreviousBlock
- the child block that will be just before the added block
-
replaceChild
public void replaceChild(Block newBlock, Block oldBlock)
Description copied from interface:Block
Replaces an existing children block with the passed new block. Also sets the new block's parent to be the current block.- Specified by:
replaceChild
in interfaceBlock
- Parameters:
newBlock
- the new block to replace the old block witholdBlock
- the block to replace with the new block
-
replaceChild
public void replaceChild(List<Block> newBlocks, Block oldBlock)
Description copied from interface:Block
Replaces an existing children block with the passed new blocks. Also sets the new block's parents to be the current block.- Specified by:
replaceChild
in interfaceBlock
- Parameters:
newBlocks
- the new blocks to replace the old block witholdBlock
- the block to replace with the new blocks
-
indexOf
public long indexOf(Block child)
Find the index of the block in the tree.- Parameters:
child
- the block for which to find the index- Returns:
- the index of the passed block in the tree, 0 is the current block and -1 means that it was not found
- Since:
- 10.10RC1
-
getChildren
public List<Block> getChildren()
Description copied from interface:Block
Gets all children blocks.- Specified by:
getChildren
in interfaceBlock
- Returns:
- the children blocks
- See Also:
Block.addChildren(java.util.List)
-
getParent
public Block getParent()
Description copied from interface:Block
Get the parent block. All blocks have a parent and the top level parent is theXDOM
object.
-
getParameters
public Map<String,String> getParameters()
- Specified by:
getParameters
in interfaceBlock
- Returns:
- all parameters
-
getParameter
public String getParameter(String name)
Description copied from interface:Block
A Parameter is a generic key/value which can be used to add metadata to a block. What is done with the metadata depends on the Renderer's implementations. For example the XHTML Renderer adds them as Element attributes.- Specified by:
getParameter
in interfaceBlock
- Parameters:
name
- the name of the parameter to return- Returns:
- the parameter or null if the parameter doesn't exist
-
setParameter
public void setParameter(String name, String value)
Description copied from interface:Block
Set a parameter on the current block. SeeBlock.getParameter(String)
for more details.- Specified by:
setParameter
in interfaceBlock
- Parameters:
name
- the parameter's namevalue
- the parameter's value
-
setParameters
public void setParameters(Map<String,String> parameters)
Description copied from interface:Block
Set several parameters at once.- Specified by:
setParameters
in interfaceBlock
- Parameters:
parameters
- the parameters to set- See Also:
Block.getParameter(String)
-
setParent
public void setParent(Block parentBlock)
Description copied from interface:Block
Sets the parent block.
-
getRoot
public Block getRoot()
Description copied from interface:Block
Gets the top level Block. If the current block is the top level Block, it return itself.
-
getNextSibling
public Block getNextSibling()
- Specified by:
getNextSibling
in interfaceBlock
- Returns:
- the next sibling block or null if there's no next sibling
-
getPreviousSibling
public Block getPreviousSibling()
- Specified by:
getPreviousSibling
in interfaceBlock
- Returns:
- the previous sibling block or null if there's no previous sibling
-
removeBlock
public void removeBlock(Block childBlockToRemove)
Description copied from interface:Block
Removes a Block.- Specified by:
removeBlock
in interfaceBlock
- Parameters:
childBlockToRemove
- the child block to remove
-
clone
public Block clone()
- Specified by:
clone
in interfaceBlock
- Overrides:
clone
in classObject
- Returns:
- the cloned Block
- See Also:
Object.clone()
-
clone
public Block clone(BlockFilter blockFilter)
Return a copy of the block with filtered children.
-
traverse
public void traverse(Listener listener)
Description copied from interface:Block
Let the block sendListener
events corresponding to its content. For example a Paragraph block will send theListener.beginParagraph(java.util.Map<java.lang.String, java.lang.String>)
andListener.endParagraph(java.util.Map<java.lang.String, java.lang.String>)
events when this method is called.
-
before
public void before(Listener listener)
SendListener
events corresponding to the start of the block. For example for a Bold block, this allows an XHTML Listener (aka a Renderer) to output<b>
.- Parameters:
listener
- the listener that will receive the events sent by this block before its children blocks have emitted their own events.
-
after
public void after(Listener listener)
SendListener
events corresponding to the end of the block. For example for a Bold block, this allows an XHTML Listener (aka a Renderer) to output</b>
.- Parameters:
listener
- the listener that will receive the events sent by this block before its children blocks have emitted their own events.
-
getBlocks
public <T extends Block> List<T> getBlocks(BlockMatcher matcher, Block.Axes axes)
Description copied from interface:Block
Get all blocks following providedBlockMatcher
andBlock.Axes
.
-
getFirstBlock
public <T extends Block> T getFirstBlock(BlockMatcher matcher, Block.Axes axes)
Description copied from interface:Block
Get the first matched block in the providedBlock.Axes
.- Specified by:
getFirstBlock
in interfaceBlock
- Type Parameters:
T
- the class of the Block to return- Parameters:
matcher
- indicate which block to stop toaxes
- indicate the search axes- Returns:
- the matched
Block
, null if none was found
-
-