FileDocCategorySizeDatePackage
TagSupport.javaAPI DocApache Tomcat 6.0.147752Fri Jul 20 04:20:36 BST 2007javax.servlet.jsp.tagext

TagSupport

public class TagSupport extends Object implements IterationTag, Serializable
A base class for defining new tag handlers implementing Tag.

The TagSupport class is a utility class intended to be used as the base class for new tag handlers. The TagSupport class implements the Tag and IterationTag interfaces and adds additional convenience methods including getter methods for the properties in Tag. TagSupport has one static method that is included to facilitate coordination among cooperating tags.

Many tag handlers will extend TagSupport and only redefine a few methods.

Fields Summary
private Tag
parent
private Hashtable
values
protected String
id
The value of the id attribute of this tag; or null.
protected javax.servlet.jsp.PageContext
pageContext
The PageContext.
Constructors Summary
public TagSupport()
Default constructor, all subclasses are required to define only a public constructor with the same signature, and to call the superclass constructor. This constructor is called by the code generated by the JSP translator.

 
Methods Summary
public intdoAfterBody()
Default processing for a body.

return
SKIP_BODY
throws
JspException if an error occurs while processing this tag
see
IterationTag#doAfterBody()

	return SKIP_BODY;
    
public intdoEndTag()
Default processing of the end tag returning EVAL_PAGE.

return
EVAL_PAGE
throws
JspException if an error occurs while processing this tag
see
Tag#doEndTag()

	return EVAL_PAGE;
    
public intdoStartTag()
Default processing of the start tag, returning SKIP_BODY.

return
SKIP_BODY
throws
JspException if an error occurs while processing this tag
see
Tag#doStartTag()

        return SKIP_BODY;
    
public static final TagfindAncestorWithClass(Tag from, java.lang.Class klass)
Find the instance of a given class type that is closest to a given instance. This method uses the getParent method from the Tag interface. This method is used for coordination among cooperating tags.

The current version of the specification only provides one formal way of indicating the observable type of a tag handler: its tag handler implementation class, described in the tag-class subelement of the tag element. This is extended in an informal manner by allowing the tag library author to indicate in the description subelement an observable type. The type should be a subtype of the tag handler implementation class or void. This addititional constraint can be exploited by a specialized container that knows about that specific tag library, as in the case of the JSP standard tag library.

When a tag library author provides information on the observable type of a tag handler, client programmatic code should adhere to that constraint. Specifically, the Class passed to findAncestorWithClass should be a subtype of the observable type.

param
from The instance from where to start looking.
param
klass The subclass of Tag or interface to be matched
return
the nearest ancestor that implements the interface or is an instance of the class specified

	boolean isInterface = false;

	if (from == null ||
	    klass == null ||
	    (!Tag.class.isAssignableFrom(klass) &&
	     !(isInterface = klass.isInterface()))) {
	    return null;
	}

	for (;;) {
	    Tag tag = from.getParent();

	    if (tag == null) {
		return null;
	    }

	    if ((isInterface && klass.isInstance(tag)) ||
	        klass.isAssignableFrom(tag.getClass()))
		return tag;
	    else
		from = tag;
	}
    
public java.lang.StringgetId()
The value of the id attribute of this tag; or null.

return
the value of the id attribute, or null

	return id;
    
public TaggetParent()
The Tag instance most closely enclosing this tag instance.

see
Tag#getParent()
return
the parent tag instance or null

	return parent;
    
public java.lang.ObjectgetValue(java.lang.String k)
Get a the value associated with a key.

param
k The string key.
return
The value associated with the key, or null.

	if (values == null) {
	    return null;
	} else {
	    return values.get(k);
	}
    
public java.util.EnumerationgetValues()
Enumerate the keys for the values kept by this tag handler.

return
An enumeration of all the keys for the values set, or null or an empty Enumeration if no values have been set.

	if (values == null) {
	    return null;
	}
	return values.keys();
    
public voidrelease()
Release state.

see
Tag#release()

	parent = null;
	id = null;
	if( values != null ) {
	    values.clear();
	}
	values = null;
    
public voidremoveValue(java.lang.String k)
Remove a value associated with a key.

param
k The string key.

	if (values != null) {
	    values.remove(k);
	}
    
public voidsetId(java.lang.String id)
Set the id attribute for this tag.

param
id The String for the id.

	this.id = id;
    
public voidsetPageContext(javax.servlet.jsp.PageContext pageContext)
Set the page context.

param
pageContext The PageContext.
see
Tag#setPageContext

	this.pageContext = pageContext;
    
public voidsetParent(Tag t)
Set the nesting tag of this tag.

param
t The parent Tag.
see
Tag#setParent(Tag)

	parent = t;
    
public voidsetValue(java.lang.String k, java.lang.Object o)
Associate a value with a String key.

param
k The key String.
param
o The value to associate.

	if (values == null) {
	    values = new Hashtable<String, Object>();
	}
	values.put(k, o);