|
Devsphere.com |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--javax.servlet.jsp.tagext.TagSupport
|
+--javax.servlet.jsp.tagext.BodyTagSupport
|
+--com.devsphere.xml.taglib.support.tag.CommonSupport
This class provides support for custom tag handlers and is the base class for all tag classes. It provides methods to validate tags, evaluate expressions export and restore variables, logging and debugging.
| Field Summary | |
protected java.lang.Boolean |
cachedDebug
the cached value of the debug flag |
protected AbstractLogger |
cachedLogger
the cached reference to the logger object |
static java.lang.String |
DEBUG_ATTR
|
protected static boolean |
DEFAULT_DEBUG
|
protected static boolean |
DEFAULT_RESTORE_VALUE
|
protected static int |
DEFAULT_SCOPE
|
static java.lang.String |
LOGGER_ATTR
|
protected java.util.Map[] |
originalValues
the original values of the variables that were exported |
| Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport |
bodyContent |
| Fields inherited from class javax.servlet.jsp.tagext.TagSupport |
id, pageContext |
| Fields inherited from interface javax.servlet.jsp.tagext.BodyTag |
EVAL_BODY_BUFFERED, EVAL_BODY_TAG |
| Fields inherited from interface javax.servlet.jsp.tagext.IterationTag |
EVAL_BODY_AGAIN |
| Fields inherited from interface javax.servlet.jsp.tagext.Tag |
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE |
| Constructor Summary | |
CommonSupport()
Calls init() |
|
| Method Summary | |
protected java.lang.String |
checkVarName(java.lang.String varName)
Verifies the name of a variable. |
protected int |
checkVarScope(java.lang.String scope)
Verifies the scope of a variable. |
void |
doCatch(java.lang.Throwable t)
Catches an exception that was thrown during the handling of the tag or during the processing of its body. |
void |
doFinally()
This method is invoked by the Servlet container after tag handling. |
protected java.lang.Object |
eval(java.lang.String attributeName,
java.lang.String expression,
java.lang.Class expectedType)
Evaluates an expression that follows the syntax defined by JSTL. |
protected boolean |
evalBoolean(java.lang.String attributeName,
java.lang.String expression)
Evaluates a JSTL expression to a boolean. |
protected double |
evalDouble(java.lang.String attributeName,
java.lang.String expression)
Evaluates a JSTL expression to a double. |
protected int |
evalInt(java.lang.String attributeName,
java.lang.String expression)
Evaluates a JSTL expression to a int. |
protected java.lang.String |
evalString(java.lang.String attributeName,
java.lang.String expression)
Evaluates a JSTL expression to a String. |
protected void |
export(java.lang.String name,
java.lang.Object value,
int scope)
Exports a JSP variable with the given name, value and scope. |
protected void |
export(java.lang.String name,
java.lang.Object value,
int scope,
boolean restoreValue)
Exports a JSP variable with the given name, value and scope. |
protected abstract java.util.List |
getAllowedAncestors()
Subclasses must implement this method to return the list of names of the tags that may contain the tag that is handled by this class. |
protected boolean |
getDebug()
Returns true if there is a page/request/session/application
variable called com.devsphere.xml.taglib.debug and its
value is true. |
protected AbstractLogger |
getLogger()
Returns the logger used by this tag handler, which must be an instance of a subclass of com.devsphere.logging.AbstractLogger. |
abstract java.lang.String |
getTagName()
Subclasses must implement this method to return the tag name. |
protected void |
init()
Initializes the fields of this tag handler. |
protected void |
log(java.lang.String message)
Logs a message. |
void |
log(java.lang.String message,
java.lang.Throwable throwable)
Logs a message and an exception. |
void |
log(java.lang.Throwable throwable)
Logs an exception. |
protected void |
restore()
Restores the values of the variables that were exported with restoreValue == true and had a previous value. |
protected void |
validate(CommonSupport ancestor)
Subclasses may call this method to verify if the handled tag was placed in the right context. |
| Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport |
doAfterBody, doEndTag, doInitBody, doStartTag, getBodyContent, getPreviousOut, release, setBodyContent |
| Methods inherited from class javax.servlet.jsp.tagext.TagSupport |
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface javax.servlet.jsp.tagext.Tag |
getParent, setPageContext, setParent |
| Field Detail |
public static final java.lang.String DEBUG_ATTR
public static final java.lang.String LOGGER_ATTR
protected static final boolean DEFAULT_DEBUG
protected static final int DEFAULT_SCOPE
protected static final boolean DEFAULT_RESTORE_VALUE
protected java.lang.Boolean cachedDebug
protected AbstractLogger cachedLogger
protected java.util.Map[] originalValues
| Constructor Detail |
public CommonSupport()
init()
| Method Detail |
protected void init()
init() is also called in doFinally()
to let the object in its initial state after handling a tag.
public abstract java.lang.String getTagName()
protected abstract java.util.List getAllowedAncestors()
validate()
null if the tag context doesn't matter.
protected void validate(CommonSupport ancestor)
throws javax.servlet.jsp.JspException
JspException if
ancestor is null,
but the allowed ancestors list is not empty or
ancestor is not null,
but the allowed ancestors list is empty or
ancestor tag
is not found in the allowed ancestors list
returned by getAllowedAncestors().
ancestor - the tag handler of an ancestor whose name
is searched in the list of allowed ancestors
javax.servlet.jsp.JspException - to signal a tag validation error
protected java.lang.String checkVarName(java.lang.String varName)
throws javax.servlet.jsp.JspException
javax.servlet.jsp.JspException - to signal an attribute validation error
protected int checkVarScope(java.lang.String scope)
throws javax.servlet.jsp.JspException
page
request
session
application
javax.servlet.jsp.JspException - to signal an attribute validation errorprotected boolean getDebug()
true if there is a page/request/session/application
variable called com.devsphere.xml.taglib.debug and its
value is true. This value is cached. Also a tag may look
for this debug flag to an ancestor tag instead of checking the variable.
The com.devsphere.xml.taglib.debug should
be set at the beginning of a page with the page or
request scope or in the login/welcome page of an application
with the session or application scope depending
on what you want to debug: a page, a page together with its included
pages, a user session or the entire Web application.
com.devsphere.xml.taglib.debug
flag or false if this variable is not set.protected AbstractLogger getLogger()
com.devsphere.logging.AbstractLogger.
You may set a logger for a page, request, session or application
by registering your logger object as the value of a variable called
com.devsphere.xml.taglib.logger.
A tag handler derived from this class should look for a logger object
at an ancestor tag of its tag library and set cachedLogger.
If this field is null, getLogger() tries
to get the logger from com.devsphere.xml.taglib.logger
and caches it. If such a variable doesn't exist, a default logger
will be created.
The com.devsphere.xml.taglib.logger should
be set at the beginning of a page within the page or
request scope or in the login/welcome page of an application
within the session or application scope.
The default logger forwards the logging requests to the
ServletContext object, by calling its log()
methods. If the debug flag is set, the logged messages and exceptions
are also printed to System.err
protected void log(java.lang.String message)
message - the message that has to be logged.public void log(java.lang.Throwable throwable)
throwable - the exception that has to be logged.
public void log(java.lang.String message,
java.lang.Throwable throwable)
message - the message that has to be logged.throwable - the exception that has to be logged.
protected java.lang.Object eval(java.lang.String attributeName,
java.lang.String expression,
java.lang.Class expectedType)
throws javax.servlet.jsp.JspException
The current implementation uses the expression evaluator of JSTL 1.0 implemented by Apache.
attributeName - the name of the tag attribute whose value
is the expression that must be evaluated.expression - the expression that is evaluatedexpectedType - the type of the object returned by this method
javax.servlet.jsp.JspException
protected java.lang.String evalString(java.lang.String attributeName,
java.lang.String expression)
throws javax.servlet.jsp.JspException
String.
attributeName - the name of the tag attribute whose value
is the expression that must be evaluated.expression - the expression that is evaluated
javax.servlet.jsp.JspException
protected boolean evalBoolean(java.lang.String attributeName,
java.lang.String expression)
throws javax.servlet.jsp.JspException
boolean.
attributeName - the name of the tag attribute whose value
is the expression that must be evaluated.expression - the expression that is evaluated
javax.servlet.jsp.JspException
protected int evalInt(java.lang.String attributeName,
java.lang.String expression)
throws javax.servlet.jsp.JspException
int.
attributeName - the name of the tag attribute whose value
is the expression that must be evaluated.expression - the expression that is evaluated
javax.servlet.jsp.JspException
protected double evalDouble(java.lang.String attributeName,
java.lang.String expression)
throws javax.servlet.jsp.JspException
double.
attributeName - the name of the tag attribute whose value
is the expression that must be evaluated.expression - the expression that is evaluated
javax.servlet.jsp.JspException
protected void export(java.lang.String name,
java.lang.Object value,
int scope)
pageContext.setAttribute()
if the value is not null. Otherwise it calls
pageContext.removeAttribute().
name - the name of the variablevalue - the value of the variablescope - the scope of the variable
protected void export(java.lang.String name,
java.lang.Object value,
int scope,
boolean restoreValue)
pageContext.setAttribute()
if the value is not null. Otherwise it calls
pageContext.removeAttribute().
If restoreValue is true and there is
already a variable with the given name within the given scope,
the existent value is saved before setting the new value.
In this case, doFinally() will restore the old value.
name - the name of the variablevalue - the value of the variablescope - the scope of the variablerestoreValue - indicates if the old value should be restored.
If there is no old value, the new value will remain
available after doFinally()protected void restore()
restoreValue == true and had a previous value.
This method is called by doFinally().
public void doCatch(java.lang.Throwable t)
throws java.lang.Throwable
true, this method throws the exception further.
Otherwise it logs the exception.
doCatch in interface javax.servlet.jsp.tagext.TryCatchFinallyt - the exception that occurred during
tag handling or body processing
java.lang.Throwable - the same exception if the debug flag is
truepublic void doFinally()
restore() and init().
doFinally in interface javax.servlet.jsp.tagext.TryCatchFinally
|
Devsphere.com |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||