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
Implementation for Block operations. All blocks should extend this class. Supports the notion of generic parameters
which can be added to a block (see
getParameter(String) for more details.- Since:
- 1.5M2
- Version:
- $Id: d54488d4ae6954cb387b7104d3364ad3395f570f $
-
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
ConstructorsConstructorDescriptionEmpty constructor to construct an empty block.AbstractBlock(List<? extends Block> childrenBlocks) Constructs a block with children blocks.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
Modifier and TypeMethodDescriptionvoidHelper method to add a single child block to the end of the children list of the current block.voidaddChildren(List<? extends Block> blocksToAdd) Adds several children blocks to the end of the children list of the current block.voidSendListenerevents corresponding to the end of the block.voidSendListenerevents corresponding to the start of the block.clone()clone(BlockFilter blockFilter) Return a copy of the block with filtered children.boolean<T> Optional<T>get(Function<Block, Optional<T>> searcher, Block.Axes axes) Get the first value extracted from the blocks in the providedBlock.Axes.getAttribute(String name) An attribute is a generic key/value pair which can be used to add internal data to a block.getBlocks(BlockMatcher matcher, Block.Axes axes) Get all blocks following providedBlockMatcherandBlock.Axes.Gets all children blocks.<T extends Block>
TgetFirstBlock(BlockMatcher matcher, Block.Axes axes) Get the first matched block in the providedBlock.Axes.getParameter(String name) A Parameter is a generic key/value which can be used to add metadata to a block.Get the parent block.getRoot()Gets the top level Block.Try to find the syntax of the block in its hierarchy (itself of its ancestors).inthashCode()longFind the index of the block in the tree.voidinsertChildAfter(Block blockToInsert, Block previousBlock) Helper method to add a single child block to the current block after the provided existing child block.voidinsertChildBefore(Block blockToInsert, Block nextBlock) Helper method to add a single child block to the current block before the provided existing child block.voidremoveBlock(Block childBlockToRemove) Removes a Block.voidreplaceChild(List<Block> newBlocks, Block oldBlock) Replaces an existing children block with the passed new blocks.voidreplaceChild(Block newBlock, Block oldBlock) Replaces an existing children block with the passed new block.voidsetAttribute(String name, Object value) Set an attribute on the current block.voidsetAttributes(Map<String, Object> attributes) Set (replace) all attributes.voidsetChildren(List<? extends Block> children) Replace current children by the provided list ofBlocks.voidsetNextSiblingBlock(Block nextSiblingBlock) voidsetParameter(String name, String value) Set a parameter on the current block.voidsetParameters(Map<String, String> parameters) Set several parameters at once.voidSets the parent block.voidsetPreviousSiblingBlock(Block previousSiblingBlock) voidLet the block sendListenerevents corresponding to its content.
-
Constructor Details
-
AbstractBlock
public AbstractBlock()Empty constructor to construct an empty block. -
AbstractBlock
Construct a block with parameters.- Parameters:
parameters- the parameters to set
-
AbstractBlock
Constructs a block with a child block.- Parameters:
childBlock- the child block of this block- Since:
- 3.0M1
-
AbstractBlock
Constructs a block with children blocks.- Parameters:
childrenBlocks- the list of children blocks of the block to construct- Since:
- 3.0M1
-
AbstractBlock
Construct a block with a child block and parameters.- Parameters:
childBlock- the child block of this blockparameters- the parameters to set- Since:
- 3.0M1
-
AbstractBlock
Construct a block with children blocks and parameters.- Parameters:
childrenBlocks- the list of children blocks of the block to constructparameters- the parameters to set- Since:
- 3.0M1
-
-
Method Details
-
addChild
Description copied from interface:BlockHelper 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
Description copied from interface:BlockAdds 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:
addChildrenin interfaceBlock- Parameters:
blocksToAdd- the children blocks to add
-
setChildren
Description copied from interface:BlockReplace current children by the provided list ofBlocks.- Specified by:
setChildrenin interfaceBlock- Parameters:
children- the new children
-
setNextSiblingBlock
- Specified by:
setNextSiblingBlockin interfaceBlock- Parameters:
nextSiblingBlock- seeBlock.getNextSibling()
-
setPreviousSiblingBlock
- Specified by:
setPreviousSiblingBlockin interfaceBlock- Parameters:
previousSiblingBlock- seeBlock.getPreviousSibling()()}
-
insertChildBefore
Description copied from interface:BlockHelper 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:
insertChildBeforein interfaceBlock- Parameters:
blockToInsert- the child block to addnextBlock- the child block that will be just after the added block
-
insertChildAfter
Description copied from interface:BlockHelper 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:
insertChildAfterin interfaceBlock- Parameters:
blockToInsert- the child block to addpreviousBlock- the child block that will be just before the added block
-
replaceChild
Description copied from interface:BlockReplaces an existing children block with the passed new block. Also sets the new block's parent to be the current block.- Specified by:
replaceChildin interfaceBlock- Parameters:
newBlock- the new block to replace the old block witholdBlock- the block to replace with the new block
-
replaceChild
Description copied from interface:BlockReplaces an existing children block with the passed new blocks. Also sets the new block's parents to be the current block.- Specified by:
replaceChildin interfaceBlock- Parameters:
newBlocks- the new blocks to replace the old block witholdBlock- the block to replace with the new blocks
-
indexOf
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
Description copied from interface:BlockGets all children blocks.- Specified by:
getChildrenin interfaceBlock- Returns:
- the children blocks
- See Also:
-
getParent
Description copied from interface:BlockGet the parent block. All blocks have a parent and the top level parent is theXDOMobject. -
getParameters
- Specified by:
getParametersin interfaceBlock- Returns:
- all parameters
-
getParameter
Description copied from interface:BlockA 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:
getParameterin interfaceBlock- Parameters:
name- the name of the parameter to return- Returns:
- the parameter or null if the parameter doesn't exist
-
setParameter
Description copied from interface:BlockSet a parameter on the current block. SeeBlock.getParameter(String)for more details.- Specified by:
setParameterin interfaceBlock- Parameters:
name- the parameter's namevalue- the parameter's value
-
setParameters
Description copied from interface:BlockSet several parameters at once.- Specified by:
setParametersin interfaceBlock- Parameters:
parameters- the parameters to set- See Also:
-
getAttributes
- Specified by:
getAttributesin interfaceBlock- Returns:
- all attributes
-
getAttribute
Description copied from interface:BlockAn attribute is a generic key/value pair which can be used to add internal data to a block.These attribute shouldn't be serialized by any renderer, they are meant to be used internally, e.g., in an XDOM transformation or a macro execution to store data related to the block. When a block is cloned, attribute values will be cloned using their
clone()-implementation when the value is cloneable, if not, the value will be shared by original and clone.- Specified by:
getAttributein interfaceBlock- Parameters:
name- the name of the attribute to return- Returns:
- the attribute or null if the attribute doesn't exist
-
setAttribute
Description copied from interface:BlockSet an attribute on the current block. SeeBlock.getAttribute(String)for more details.- Specified by:
setAttributein interfaceBlock- Parameters:
name- the attribute's namevalue- the attribute's value
-
setAttributes
Description copied from interface:BlockSet (replace) all attributes.- Specified by:
setAttributesin interfaceBlock- Parameters:
attributes- the attributes to set- See Also:
-
setParent
Description copied from interface:BlockSets the parent block. -
getRoot
Description copied from interface:BlockGets the top level Block. If the current block is the top level Block, it return itself. -
getNextSibling
- Specified by:
getNextSiblingin interfaceBlock- Returns:
- the next sibling block or null if there's no next sibling
-
getPreviousSibling
- Specified by:
getPreviousSiblingin interfaceBlock- Returns:
- the previous sibling block or null if there's no previous sibling
-
removeBlock
Description copied from interface:BlockRemoves a Block.- Specified by:
removeBlockin interfaceBlock- Parameters:
childBlockToRemove- the child block to remove
-
equals
-
hashCode
public int hashCode() -
clone
-
clone
Return a copy of the block with filtered children. -
traverse
Description copied from interface:BlockLet the block sendListenerevents 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
SendListenerevents 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
SendListenerevents 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
Description copied from interface:BlockGet all blocks following providedBlockMatcherandBlock.Axes. -
getFirstBlock
Description copied from interface:BlockGet the first matched block in the providedBlock.Axes.- Specified by:
getFirstBlockin 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
-
getSyntaxMetadata
Description copied from interface:BlockTry to find the syntax of the block in its hierarchy (itself of its ancestors).- Specified by:
getSyntaxMetadatain interfaceBlock- Returns:
- the syntax of the block or null of none could be found
-
get
Description copied from interface:BlockGet the first value extracted from the blocks in the providedBlock.Axes.
-