Package org.xwiki.rendering.block
Interface Block
- All Superinterfaces:
Cloneable
- All Known Subinterfaces:
ListBLock
- All Known Implementing Classes:
AbstractBlock,AbstractMacroBlock,BulletedListBlock,CompositeBlock,DefinitionDescriptionBlock,DefinitionListBlock,DefinitionTermBlock,EmptyLinesBlock,FigureBlock,FigureCaptionBlock,FormatBlock,GroupBlock,HeaderBlock,HorizontalLineBlock,IdBlock,ImageBlock,LinkBlock,ListItemBlock,MacroBlock,MacroMarkerBlock,MetaDataBlock,NewLineBlock,NumberedListBlock,ParagraphBlock,QuotationBlock,QuotationLineBlock,RawBlock,SectionBlock,SpaceBlock,SpecialSymbolBlock,TableBlock,TableCellBlock,TableHeadCellBlock,TableRowBlock,VerbatimBlock,WordBlock,XDOM
Represents an element of a XWiki Document's content. For example there are Blocks for Paragraphs, Bold parts,
Sections, Links, etc. A block has a parent and can have children too for Blocks which are wrapper around other blocks
(e.g. Paragraph blocks, List blocks, Bold blocks).
- Since:
- 1.5M2
- Version:
- $Id: 333192035c213679a0a035bf93c6701c09fa60d4 $
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumSearch axes used in searching methods. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TypeHelper to represent the Type for each List<Block>. -
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.clone()clone(BlockFilter blockFilter) Return a copy of the block with filtered children.default <T> Optional<T>get(Function<Block, Optional<T>> searcher, Block.Axes axes) Get the first value extracted from the blocks in the providedBlock.Axes.default ObjectgetAttribute(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).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.
-
Field Details
-
LIST_BLOCK_TYPE
Helper to represent the Type for each List<Block>.- Since:
- 10.10RC1
-
-
Method Details
-
traverse
Let 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.- Parameters:
listener- the listener to which to send the events to.
-
addChild
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 useaddChildren(java.util.List).- Parameters:
blockToAdd- the child block to add
-
addChildren
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.- Parameters:
blocksToAdd- the children blocks to add
-
setChildren
Replace current children by the provided list ofBlocks.- Parameters:
children- the new children
-
insertChildBefore
Helper method to add a single child block to the current block before the provided existing child block. For adding several blocks at once useaddChildren(java.util.List).- Parameters:
blockToInsert- the child block to addnextBlock- the child block that will be just after the added block- Since:
- 1.6M1
-
insertChildAfter
Helper method to add a single child block to the current block after the provided existing child block. For adding several blocks at once useaddChildren(java.util.List).- Parameters:
blockToInsert- the child block to addpreviousBlock- the child block that will be just before the added block- Since:
- 1.6M1
-
replaceChild
Replaces an existing children block with the passed new block. Also sets the new block's parent to be the current block.- Parameters:
newBlock- the new block to replace the old block witholdBlock- the block to replace with the new block
-
replaceChild
Replaces an existing children block with the passed new blocks. Also sets the new block's parents to be the current block.- Parameters:
newBlocks- the new blocks to replace the old block witholdBlock- the block to replace with the new blocks
-
getParent
Block getParent()Get the parent block. All blocks have a parent and the top level parent is theXDOMobject.- Returns:
- the parent block
-
setParent
Sets the parent block.- Parameters:
parentBlock- the parent block
-
getChildren
Gets all children blocks.- Returns:
- the children blocks
- See Also:
-
getRoot
Block getRoot()Gets the top level Block. If the current block is the top level Block, it return itself.- Returns:
- the top level Block
-
removeBlock
Removes a Block.- Parameters:
childBlockToRemove- the child block to remove- Since:
- 2.6RC1
-
getNextSibling
Block getNextSibling()- Returns:
- the next sibling block or null if there's no next sibling
- Since:
- 2.6RC1
-
setNextSiblingBlock
- Parameters:
nextSiblingBlock- seegetNextSibling()- Since:
- 2.6RC1
-
getPreviousSibling
Block getPreviousSibling()- Returns:
- the previous sibling block or null if there's no previous sibling
- Since:
- 2.6RC1
-
setPreviousSiblingBlock
- Parameters:
previousSiblingBlock- seegetPreviousSibling()()}- Since:
- 2.6RC1
-
clone
Return a copy of the block with filtered children.- Parameters:
blockFilter- the Block filter.- Returns:
- the filtered Block.
- Since:
- 1.8RC2
-
clone
Block clone()- Returns:
- the cloned Block
- See Also:
-
getParameters
- Returns:
- all parameters
- Since:
- 3.0M1
-
getParameter
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.- Parameters:
name- the name of the parameter to return- Returns:
- the parameter or null if the parameter doesn't exist
- Since:
- 3.0M1
-
setParameter
Set a parameter on the current block. SeegetParameter(String)for more details.- Parameters:
name- the parameter's namevalue- the parameter's value- Since:
- 3.0M1
-
setParameters
Set several parameters at once.- Parameters:
parameters- the parameters to set- Since:
- 3.0M1
- See Also:
-
getAttributes
- Returns:
- all attributes
- Since:
- 15.9RC1
-
getAttribute
An 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.- Parameters:
name- the name of the attribute to return- Returns:
- the attribute or null if the attribute doesn't exist
- Since:
- 15.9RC1
-
setAttribute
Set an attribute on the current block. SeegetAttribute(String)for more details.- Parameters:
name- the attribute's namevalue- the attribute's value- Since:
- 15.9RC1
-
setAttributes
Set (replace) all attributes.- Parameters:
attributes- the attributes to set- Since:
- 15.9RC1
- See Also:
-
getBlocks
Get all blocks following providedBlockMatcherandBlock.Axes.- Type Parameters:
T- the class of the Blocks to return- Parameters:
matcher- filter the blocks to returnaxes- indicate the search axes- Returns:
- the matched
Blocks, empty list of none was found - Since:
- 3.0M3
-
getFirstBlock
Get the first matched block in the providedBlock.Axes.- 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 - Since:
- 3.0M3
-
getSyntaxMetadata
Try to find the syntax of the block in its hierarchy (itself of its ancestors).- Returns:
- the syntax of the block or null of none could be found
- Since:
- 15.9RC1
-
get
Get the first value extracted from the blocks in the providedBlock.Axes.- Type Parameters:
T- the type of value searching in the block- Parameters:
searcher- theFunctionin charge of extracting the searched value from the blockaxes- indicate the search axes- Returns:
- the value found in the provided block axes
- Since:
- 15.9RC1
-