org.sitemesh.tagprocessor
Class BasicBlockRule<T>

java.lang.Object
  extended by org.sitemesh.tagprocessor.BasicRule
      extended by org.sitemesh.tagprocessor.BasicBlockRule<T>
All Implemented Interfaces:
TagRule
Direct Known Subclasses:
ContentBlockExtractingRule, DivExtractingRule, ExportTagToContentRule, SiteMeshDecorateRule, SiteMeshWriteRule, TitleExtractingRule

public abstract class BasicBlockRule<T>
extends BasicRule

TagRule helper class for dealing with blocks surrounded by an opening and closing tag. e.g. <tag>...</tag>.

Subclasses should implement processStart(Tag) and processEnd(Tag, Object), which get called at the start and end of the block, respectively. Optionally, data may be passed between the two by returning an object from processStart(Tag) which will get passed to the matching processEnd(Tag, Object) call, even if there are nested tags. The class type of data used matches the generic type T of this class.

Author:
Joe Walnes

Field Summary
 
Fields inherited from class org.sitemesh.tagprocessor.BasicRule
tagProcessorContext
 
Constructor Summary
BasicBlockRule()
           
 
Method Summary
 void process(Tag tag)
          Implementations can use this to do any necessary work on the Tag such as extracting values or transforming it.
protected abstract  void processEnd(Tag tag, T data)
          Called when a block is ended (i.e.
protected abstract  T processStart(Tag tag)
          Called when a block is started (i.e.
 
Methods inherited from class org.sitemesh.tagprocessor.BasicRule
setTagProcessorContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicBlockRule

public BasicBlockRule()
Method Detail

processStart

protected abstract T processStart(Tag tag)
                           throws IOException
Called when a block is started (i.e. <opening> tag is encountered).

Parameters:
tag - Opening tag.
Returns:
Any data that needs to be passed to processEnd(Tag, Object). May be null.
Throws:
IOException

processEnd

protected abstract void processEnd(Tag tag,
                                   T data)
                            throws IOException
Called when a block is ended (i.e. </closing> tag is encountered).

Parameters:
tag - Closing tag. This will not have any attributes available (as they are associated with an opening tag. To get access to the attributes, the processStart(Tag) method should access them and return them as data.
data - Data returned from processStart(Tag). May be null.
Throws:
IOException

process

public void process(Tag tag)
             throws IOException
Description copied from interface: TagRule
Implementations can use this to do any necessary work on the Tag such as extracting values or transforming it.

Specified by:
process in interface TagRule
Specified by:
process in class BasicRule
Throws:
IOException


Copyright © 2011. All Rights Reserved.