com.opensymphony.webwork.views.velocity
Class AbstractTagDirective

java.lang.Object
  extended byorg.apache.velocity.runtime.directive.Directive
      extended bycom.opensymphony.webwork.views.velocity.AbstractTagDirective
All Implemented Interfaces:
Cloneable, org.apache.velocity.runtime.directive.DirectiveConstants
Direct Known Subclasses:
BodyTagDirective, TagDirective

public abstract class AbstractTagDirective
extends org.apache.velocity.runtime.directive.Directive

Custom user Directive that enables the WebWork2 UI tags to be easily accessed from Velocity pages

Version:
$id$
Author:
$author$

Field Summary
protected static org.apache.commons.logging.Log log
           
protected static Map tagclassMap
          a params of tagname to tagclass that provides faster lookup that searching through the tagpath.
static String VELOCITY_WRITER
           
 
Fields inherited from class org.apache.velocity.runtime.directive.Directive
rsvc
 
Fields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants
BLOCK, LINE
 
Constructor Summary
AbstractTagDirective()
           
 
Method Summary
protected  Object createObject(org.apache.velocity.runtime.parser.node.Node node)
          create a new instance of our rendering object.
protected  Map createPropertyMap(org.apache.velocity.context.InternalContextAdapter contextAdapter, org.apache.velocity.runtime.parser.node.Node node)
          create a Map of properties that the user has passed in.
protected  Class findTagInPath(String tagname)
          Searches for tags (class that are instances of Renderers or Tags) in the webwork.velocity.tag.path using the following rules: append the tagname + 'Tag' to the path and see if a class exists and is a Renderer or Tag append the tagname to the path and see if a class exists and is a Renderer or Tag For example, let us say that we're search for a custom tag, Foobar.
protected  String[] getTagPath()
          todo it would be nice for the Configuration object to allow listeners to be registered so that they can be notified of changes to the Configuration files
protected  boolean processTag(PageContext pageContext, Tag tag, org.apache.velocity.context.InternalContextAdapter context, Writer writer, org.apache.velocity.runtime.parser.node.Node node, org.apache.velocity.runtime.parser.node.Node bodyNode)
           
protected  void putProperty(Map propertyMap, org.apache.velocity.context.InternalContextAdapter contextAdapter, org.apache.velocity.runtime.parser.node.Node node)
          adds a given Node's key/value pair to the propertyMap.
 boolean render(org.apache.velocity.context.InternalContextAdapter contextAdapter, Writer writer, org.apache.velocity.runtime.parser.node.Node node)
          the guts of this directive that indicates how this directive should be rendered.
 
Methods inherited from class org.apache.velocity.runtime.directive.Directive
getColumn, getLine, getName, getType, init, setLocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.commons.logging.Log log

VELOCITY_WRITER

public static final String VELOCITY_WRITER
See Also:
Constant Field Values

tagclassMap

protected static Map tagclassMap
a params of tagname to tagclass that provides faster lookup that searching through the tagpath. for example,
#tag( TextField )
would result in "TextField" and com.opensymphony.webwork.views.jsp.ui.TextFieldTag.class being stored in the tagclassMap todo enable this params to be reloaded or reset

Constructor Detail

AbstractTagDirective

public AbstractTagDirective()
Method Detail

render

public boolean render(org.apache.velocity.context.InternalContextAdapter contextAdapter,
                      Writer writer,
                      org.apache.velocity.runtime.parser.node.Node node)
               throws IOException,
                      org.apache.velocity.exception.ResourceNotFoundException,
                      org.apache.velocity.exception.ParseErrorException,
                      org.apache.velocity.exception.MethodInvocationException
the guts of this directive that indicates how this directive should be rendered. Conceptually, this method is a controller that delegates the work to other methods. by convention, i'm using process* for the delegated methods. processRenderer and processTag respectively.

Throws:
IOException
org.apache.velocity.exception.ResourceNotFoundException
org.apache.velocity.exception.ParseErrorException
org.apache.velocity.exception.MethodInvocationException

getTagPath

protected String[] getTagPath()
                       throws org.apache.velocity.exception.ResourceNotFoundException
todo it would be nice for the Configuration object to allow listeners to be registered so that they can be notified of changes to the Configuration files

Returns:
an array of paths to search for our tag library
Throws:
org.apache.velocity.exception.ResourceNotFoundException

createObject

protected Object createObject(org.apache.velocity.runtime.parser.node.Node node)
                       throws org.apache.velocity.exception.ResourceNotFoundException
create a new instance of our rendering object. this will usually be a Tag, but I've left it as an Object just in case we want to define more abitrary rendering mechanisms that are not JSP tags

Parameters:
node - the node that contains the label for our rendering object. this will usually be something like TextField, Password, or Component
Returns:
a new instance of the object specified by the Node
Throws:
org.apache.velocity.exception.ResourceNotFoundException

createPropertyMap

protected Map createPropertyMap(org.apache.velocity.context.InternalContextAdapter contextAdapter,
                                org.apache.velocity.runtime.parser.node.Node node)
                         throws org.apache.velocity.exception.ParseErrorException,
                                org.apache.velocity.exception.MethodInvocationException
create a Map of properties that the user has passed in. for example,
 #tag( TextField "name=hello" "value=world" "template=foo" )
 
would yield a params that contains {["name", "hello"], ["value", "world"], ["template", "foo"]}

Parameters:
node - the Node passed in to the render method
Returns:
a Map of the user specified properties
Throws:
org.apache.velocity.exception.ParseErrorException - if the was an error in the format of the property
org.apache.velocity.exception.MethodInvocationException
See Also:
render(org.apache.velocity.context.InternalContextAdapter, java.io.Writer, org.apache.velocity.runtime.parser.node.Node)

findTagInPath

protected Class findTagInPath(String tagname)
                       throws org.apache.velocity.exception.ResourceNotFoundException
Searches for tags (class that are instances of Renderers or Tags) in the webwork.velocity.tag.path using the following rules: For example, let us say that we're search for a custom tag, Foobar. Assuming our webwork.velocity.tag.path is the default ("com.opensymphony.webwork.views.jsp.ui", "com.opensymphony.webwork.views.jsp", ""), then we will search for our tag in the following locations:

Parameters:
tagname -
Throws:
org.apache.velocity.exception.ResourceNotFoundException
See Also:
getTagPath()

processTag

protected boolean processTag(PageContext pageContext,
                             Tag tag,
                             org.apache.velocity.context.InternalContextAdapter context,
                             Writer writer,
                             org.apache.velocity.runtime.parser.node.Node node,
                             org.apache.velocity.runtime.parser.node.Node bodyNode)
                      throws org.apache.velocity.exception.ParseErrorException,
                             IOException,
                             org.apache.velocity.exception.MethodInvocationException,
                             org.apache.velocity.exception.ResourceNotFoundException
Throws:
org.apache.velocity.exception.ParseErrorException
IOException
org.apache.velocity.exception.MethodInvocationException
org.apache.velocity.exception.ResourceNotFoundException

putProperty

protected void putProperty(Map propertyMap,
                           org.apache.velocity.context.InternalContextAdapter contextAdapter,
                           org.apache.velocity.runtime.parser.node.Node node)
                    throws org.apache.velocity.exception.ParseErrorException,
                           org.apache.velocity.exception.MethodInvocationException
adds a given Node's key/value pair to the propertyMap. For example, if this Node contained the value "rows=20", then the key, rows, would be added to the propertyMap with the String value, 20.

Parameters:
propertyMap - a params containing all the properties that we wish to set
node - the parameter to set expressed in "name=value" format
Throws:
org.apache.velocity.exception.ParseErrorException
org.apache.velocity.exception.MethodInvocationException

WebWork Project Page