public abstract class AbstractBlock extends Object implements Block
getParameter(String)
for more details.Block.Axes
LIST_BLOCK_TYPE
Constructor and Description |
---|
AbstractBlock()
Empty constructor to construct an empty block.
|
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.
|
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.
|
Modifier and Type | Method and 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)
Send
Listener events corresponding to the end of the block. |
void |
before(Listener listener)
Send
Listener 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> |
getBlocks(BlockMatcher matcher,
Block.Axes axes)
Get all blocks following provided
BlockMatcher and Block.Axes . |
List<Block> |
getChildren()
Gets all children blocks.
|
<T extends Block> |
getFirstBlock(BlockMatcher matcher,
Block.Axes axes)
Get the first matched block in the provided
Block.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(Block newBlock,
Block oldBlock)
Replaces an existing children block with the passed new block.
|
void |
replaceChild(List<Block> newBlocks,
Block oldBlock)
Replaces an existing children block with the passed new blocks.
|
void |
setChildren(List<? extends Block> children)
Replace current children by the provided list of
Block 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 send
Listener events corresponding to its content. |
public AbstractBlock()
public AbstractBlock(Map<String,String> parameters)
parameters
- the parameters to setpublic AbstractBlock(Block childBlock)
childBlock
- the child block of this blockpublic AbstractBlock(List<? extends Block> childrenBlocks)
childrenBlocks
- the list of children blocks of the block to constructpublic AbstractBlock(Block childBlock, Map<String,String> parameters)
childBlock
- the child block of this blockparameters
- the parameters to setpublic void addChild(Block blockToAdd)
Block
Block.addChildren(java.util.List)
.public void addChildren(List<? extends Block> blocksToAdd)
Block
addChildren
in interface Block
blocksToAdd
- the children blocks to addpublic void setChildren(List<? extends Block> children)
Block
Block
s.setChildren
in interface Block
children
- the new childrenpublic void setNextSiblingBlock(Block nextSiblingBlock)
setNextSiblingBlock
in interface Block
nextSiblingBlock
- see Block.getNextSibling()
public void setPreviousSiblingBlock(Block previousSiblingBlock)
setPreviousSiblingBlock
in interface Block
previousSiblingBlock
- see Block.getPreviousSibling()
()}public void insertChildBefore(Block blockToInsert, Block nextBlock)
Block
Block.addChildren(java.util.List)
.insertChildBefore
in interface Block
blockToInsert
- the child block to addnextBlock
- the child block that will be just after the added blockpublic void insertChildAfter(Block blockToInsert, Block previousBlock)
Block
Block.addChildren(java.util.List)
.insertChildAfter
in interface Block
blockToInsert
- the child block to addpreviousBlock
- the child block that will be just before the added blockpublic void replaceChild(Block newBlock, Block oldBlock)
Block
replaceChild
in interface Block
newBlock
- the new block to replace the old block witholdBlock
- the block to replace with the new blockpublic void replaceChild(List<Block> newBlocks, Block oldBlock)
Block
replaceChild
in interface Block
newBlocks
- the new blocks to replace the old block witholdBlock
- the block to replace with the new blockspublic long indexOf(Block child)
child
- the block for which to find the indexpublic List<Block> getChildren()
Block
getChildren
in interface Block
Block.addChildren(java.util.List)
public Block getParent()
Block
XDOM
object.public Map<String,String> getParameters()
getParameters
in interface Block
public String getParameter(String name)
Block
getParameter
in interface Block
name
- the name of the parameter to returnpublic void setParameter(String name, String value)
Block
Block.getParameter(String)
for more details.setParameter
in interface Block
name
- the parameter's namevalue
- the parameter's valuepublic void setParameters(Map<String,String> parameters)
Block
setParameters
in interface Block
parameters
- the parameters to setBlock.getParameter(String)
public void setParent(Block parentBlock)
Block
public Block getRoot()
Block
public Block getNextSibling()
getNextSibling
in interface Block
public Block getPreviousSibling()
getPreviousSibling
in interface Block
public void removeBlock(Block childBlockToRemove)
Block
removeBlock
in interface Block
childBlockToRemove
- the child block to removepublic Block clone()
clone
in interface Block
clone
in class Object
Object.clone()
public Block clone(BlockFilter blockFilter)
public void traverse(Listener listener)
Block
Listener
events corresponding to its content. For example a Paragraph block will send
the Listener.beginParagraph(java.util.Map<java.lang.String, java.lang.String>)
and
Listener.endParagraph(java.util.Map<java.lang.String, java.lang.String>)
events when this method is called.public void before(Listener listener)
Listener
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>
.listener
- the listener that will receive the events sent by this block before its children blocks have
emitted their own events.public void after(Listener listener)
Listener
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>
.listener
- the listener that will receive the events sent by this block before its children blocks have
emitted their own events.public <T extends Block> List<T> getBlocks(BlockMatcher matcher, Block.Axes axes)
Block
BlockMatcher
and Block.Axes
.public <T extends Block> T getFirstBlock(BlockMatcher matcher, Block.Axes axes)
Block
Block.Axes
.getFirstBlock
in interface Block
T
- the class of the Block to returnmatcher
- indicate which block to stop toaxes
- indicate the search axesBlock
, null if none was foundCopyright © 2004–2021 XWiki. All rights reserved.