org.xwiki.rendering.block
Class AbstractBlock

java.lang.Object
  extended by org.xwiki.rendering.block.AbstractBlock
All Implemented Interfaces:
Cloneable, Block
Direct Known Subclasses:
BulletedListBlock, DefinitionDescriptionBlock, DefinitionListBlock, DefinitionTermBlock, EmptyLinesBlock, FormatBlock, GroupBlock, HeaderBlock, HorizontalLineBlock, IdBlock, ImageBlock, LinkBlock, ListItemBlock, MacroBlock, MacroMarkerBlock, 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 (see getParameter(String) for more details.

Since:
1.5M2
Version:
$Id$

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.xwiki.rendering.block.Block
Block.Axes
 
Constructor Summary
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.
 
Method Summary
 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)
          
 List<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>
List<T>
getChildrenByType(Class<T> blockClass, boolean recurse)
          Deprecated. 
 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.
<T extends Block>
T
getParentBlockByType(Class<T> blockClass)
          Deprecated. 
<T extends Block>
T
getPreviousBlockByType(Class<T> blockClass, boolean recurse)
          Deprecated. 
 Block getPreviousSibling()
          
 Block getRoot()
          Gets the top level Block.
 int hashCode()
          
 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 Blocks.
 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.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

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 block
parameters - the parameters to set
Since:
3.0M1

AbstractBlock

public AbstractBlock(List<? extends Block> childrenBlocks,
                     Map<String,String> parameters)
Construct a block with children blocks and parameters.

Parameters:
childrenBlocks - the list of children blocks of the block to construct
parameters - the parameters to set
Since:
3.0M1
Method Detail

addChild

public void addChild(Block blockToAdd)
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 use Block.addChildren(java.util.List).

Specified by:
addChild in interface Block
Parameters:
blockToAdd - the child block to add
See Also:
Block.addChild(org.xwiki.rendering.block.Block)

addChildren

public void addChildren(List<? extends Block> blocksToAdd)
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 interface Block
Parameters:
blocksToAdd - the children blocks to add
See Also:
Block.addChildren(java.util.List)

setChildren

public void setChildren(List<? extends Block> children)
Replace current children by the provided list of Blocks.

Specified by:
setChildren in interface Block
Parameters:
children - the new children
See Also:
Block.setChildren(java.util.List)

setNextSiblingBlock

public void setNextSiblingBlock(Block nextSiblingBlock)

Specified by:
setNextSiblingBlock in interface Block
Parameters:
nextSiblingBlock - see Block.getNextSibling()
Since:
2.6RC1
See Also:
Block.setNextSiblingBlock(Block)

setPreviousSiblingBlock

public void setPreviousSiblingBlock(Block previousSiblingBlock)

Specified by:
setPreviousSiblingBlock in interface Block
Parameters:
previousSiblingBlock - see Block.getPreviousSibling() ()}
Since:
2.6RC1
See Also:
Block.setPreviousSiblingBlock(Block)

insertChildBefore

public void insertChildBefore(Block blockToInsert,
                              Block nextBlock)
Helper method to add a single child block to the current block before the provided existing child block. For adding several blocks at once use Block.addChildren(java.util.List).

Specified by:
insertChildBefore in interface Block
Parameters:
blockToInsert - the child block to add
nextBlock - the child block that will be just after the added block
See Also:
Block.insertChildBefore(org.xwiki.rendering.block.Block, org.xwiki.rendering.block.Block)

insertChildAfter

public void insertChildAfter(Block blockToInsert,
                             Block previousBlock)
Helper method to add a single child block to the current block after the provided existing child block. For adding several blocks at once use Block.addChildren(java.util.List).

Specified by:
insertChildAfter in interface Block
Parameters:
blockToInsert - the child block to add
previousBlock - the child block that will be just before the added block
See Also:
Block.insertChildAfter(org.xwiki.rendering.block.Block, org.xwiki.rendering.block.Block)

replaceChild

public void replaceChild(Block newBlock,
                         Block oldBlock)
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 interface Block
Parameters:
newBlock - the new block to replace the old block with
oldBlock - the block to replace with the new block
See Also:
Block.replaceChild(Block, Block)

replaceChild

public void replaceChild(List<Block> newBlocks,
                         Block oldBlock)
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 interface Block
Parameters:
newBlocks - the new blocks to replace the old block with
oldBlock - the block to replace with the new blocks
See Also:
Block.replaceChild(List, Block)

getChildren

public List<Block> getChildren()
Gets all children blocks.

Specified by:
getChildren in interface Block
Returns:
the children blocks
See Also:
Block.getChildren()

getParent

public Block getParent()
Get the parent block. All blocks have a parent and the top level parent is the XDOM object.

Specified by:
getParent in interface Block
Returns:
the parent block
See Also:
Block.getParent()

getParameters

public Map<String,String> getParameters()

Specified by:
getParameters in interface Block
Returns:
all parameters
See Also:
Block.getParameters()

getParameter

public String getParameter(String name)
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 interface Block
Parameters:
name - the name of the parameter to return
Returns:
the parameter or null if the parameter doesn't exist
See Also:
Block.getParameter(java.lang.String)

setParameter

public void setParameter(String name,
                         String value)
Set a parameter on the current block. See Block.getParameter(String) for more details.

Specified by:
setParameter in interface Block
Parameters:
name - the parameter's name
value - the parameter's value
See Also:
Block.setParameter(java.lang.String, java.lang.String)

setParameters

public void setParameters(Map<String,String> parameters)
Set several parameters at once.

Specified by:
setParameters in interface Block
Parameters:
parameters - the parameters to set
Since:
1.7M2
See Also:
Block.setParameters(java.util.Map)

setParent

public void setParent(Block parentBlock)
Sets the parent block.

Specified by:
setParent in interface Block
Parameters:
parentBlock - the parent block
See Also:
Block.setParent(org.xwiki.rendering.block.Block)

getRoot

public Block getRoot()
Gets the top level Block. If the current block is the top level Block, it return itself.

Specified by:
getRoot in interface Block
Returns:
the top level Block
See Also:
Block.getRoot()

getNextSibling

public Block getNextSibling()

Specified by:
getNextSibling in interface Block
Returns:
the next sibling block or null if there's no next sibling
Since:
2.6RC1
See Also:
Block.getNextSibling()

getPreviousSibling

public Block getPreviousSibling()

Specified by:
getPreviousSibling in interface Block
Returns:
the previous sibling block or null if there's no previous sibling
Since:
2.6RC1
See Also:
Block.getPreviousSibling()

removeBlock

public void removeBlock(Block childBlockToRemove)
Removes a Block.

Specified by:
removeBlock in interface Block
Parameters:
childBlockToRemove - the child block to remove
Since:
2.6RC1
See Also:
Block.removeBlock(Block)

equals

public boolean equals(Object obj)

Overrides:
equals in class Object
See Also:
EqualsBuilder.reflectionEquals(Object, Object)

hashCode

public int hashCode()

Overrides:
hashCode in class Object
See Also:
HashCodeBuilder.reflectionHashCode(Object)

clone

public Block clone()

Specified by:
clone in interface Block
Overrides:
clone in class Object
See Also:
Block.clone()

clone

public Block clone(BlockFilter blockFilter)
Return a copy of the block with filtered children.

Specified by:
clone in interface Block
Parameters:
blockFilter - the Block filter.
Returns:
the filtered Block.
Since:
1.8RC2
See Also:
Block.clone(org.xwiki.rendering.block.BlockFilter)

traverse

public void traverse(Listener listener)
Let the block send Listener events corresponding to its content. For example a Paragraph block will send the Listener.beginParagraph(java.util.Map) and Listener.endParagraph(java.util.Map) events when this method is called.

Specified by:
traverse in interface Block
Parameters:
listener - the listener to which to send the events to.
See Also:
traverse(org.xwiki.rendering.listener.Listener)

before

public void before(Listener listener)
Send 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>.

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)
Send 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>.

Parameters:
listener - the listener that will receive the events sent by this block before its children blocks have emitted their own events.

getBlocks

public List<Block> getBlocks(BlockMatcher matcher,
                             Block.Axes axes)
Get all blocks following provided BlockMatcher and Block.Axes.

Specified by:
getBlocks in interface Block
Parameters:
matcher - filter the blocks to return
axes - indicate the search axes
Returns:
the matched Blocks, empty list of none was found
See Also:
Block.getBlocks(org.xwiki.rendering.block.match.BlockMatcher, org.xwiki.rendering.block.Block.Axes)

getFirstBlock

public Block getFirstBlock(BlockMatcher matcher,
                           Block.Axes axes)
Get the first matched block in the provided Block.Axes.

Specified by:
getFirstBlock in interface Block
Parameters:
matcher - indicate which block to stop to
axes - indicate the search axes
Returns:
the matched Block, null if none was found
See Also:
Block.getFirstBlock(org.xwiki.rendering.block.match.BlockMatcher, org.xwiki.rendering.block.Block.Axes)

getChildrenByType

@Deprecated
public <T extends Block> List<T> getChildrenByType(Class<T> blockClass,
                                                              boolean recurse)
Deprecated. 

Gets all the Blocks in the tree which are of the passed Block class.

Specified by:
getChildrenByType in interface Block
Type Parameters:
T - the class of the Blocks to return
Parameters:
blockClass - the block class to look for
recurse - if true also search recursively children
Returns:
all the matching blocks
See Also:
Block.getChildrenByType(java.lang.Class, boolean)

getPreviousBlockByType

@Deprecated
public <T extends Block> T getPreviousBlockByType(Class<T> blockClass,
                                                             boolean recurse)
Deprecated. 

Look upward to find a block which inherit or is provided type.

The difference with Block.getParentBlockByType(Class) is that this one look also at previous block in the same parent when Block.getParentBlockByType(Class) only look at parents.

Specified by:
getPreviousBlockByType in interface Block
Type Parameters:
T - the class of the Blocks to return
Parameters:
blockClass - the block class to look for
recurse - if true also search in parents levels
Returns:
the found block, null if nothing is found
See Also:
Block.getPreviousBlockByType(java.lang.Class, boolean)

getParentBlockByType

@Deprecated
public <T extends Block> T getParentBlockByType(Class<T> blockClass)
Deprecated. 

Recursively look at parents to find a block which inherits or is provided type.

The difference with Block.getPreviousBlockByType(Class, boolean) is that this one only look at parent when Block.getPreviousBlockByType(Class, boolean) look at previous block in the same parent.

Specified by:
getParentBlockByType in interface Block
Type Parameters:
T - the class of the Blocks to return
Parameters:
blockClass - the block class to look for
Returns:
the found block, null if nothing is found
See Also:
Block.getParentBlockByType(java.lang.Class)


Copyright © 2004-2011 XWiki. All Rights Reserved.