jp.terasoluna.fw.web.taglib
Class DateFormatterTagBase

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by jp.terasoluna.fw.web.taglib.DateFormatterTagBase
All Implemented Interfaces:
java.io.Serializable, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.Tag
Direct Known Subclasses:
DateTag, JDateTag

public abstract class DateFormatterTagBase
extends javax.servlet.jsp.tagext.TagSupport

Abstract class for the custom tag that formats and outputs the date and time or defines it as scripting variable.

The class of custom tag that formats the date and time, is created by inheriting this class.

Two types of date and time data namely, java.util.Date type or java.lang.String are supported. While formatting the data of java.lang.String type, the string should be in "yyyy/MM/dd HH:mm:ss" format. (It can be changed by overriding the getDefaultDateFormat() method or by using the format attribute.)

Abstract method "doFormat(Date date)" that formats the actual string, is implemented in the subclass. This subclass inherits DateFormatterTagBase class.

Attribute supported by tag

In DateFormatterTagBase, following attributes are supported.

Attribute name Default value Required Execution time format Overview
id - false false It is specified when the formatted string is to be set to scripting variable and not to be output to response. In case when the formatted string is set to scripting variable, irrespective of whether the filter attribute is specified or not, the special HTML characters are not escaped.
filter true false true At the time of outputting the formatted string, specify whether the special HTML characters are to be escaped. When id attribute is specified, it is ignored.
ignore false false true Specify whether to ignore when the bean, which is specified in name attribute, is not found. If false is specified, JspException exception is thrown when bean is not found.
name - false true Bean name that contains the string to be formatted in the property. When property attribute is not specified,instance specified in the name attribute needs to be formatted. In this case, that instance itself should either belong to java.util.Date type or java.lang.String type(should be in "yyyy/MM/dd HH:mm:ss" format). When value attribute is specified, it is ignored.
property - false true Property name which is accessed in bean that is specified by name attribute.It is ignored when value attribute is specified.
scope false true (Search order of findAttribute()method) Scope to search the bean which is specified in name attribute.
value - false true String to be formatted.String should be in "yyyy/MM/dd HH:mm:ss" format. (It can be changed by overriding the getDefaultDateFormat() method or by using the format attribute) When value attribute is specified, name attribute and property attribute are ignored.
pattern - true true Output format to be formatted. Output format specified in pattern attribute is parsed in subclass of DateFormatterTagBase class. For details, refer to the documents of subclass.
format yyyy/MM/dd HH:mm:ss false true Date and time format.To change the default value, override getDefaultDateFormat() method.


Scripting variable of custom tag

Following variables are supported in DateFormatterTagBase.

Variable name Type Valid range Description
Name specified in id attribute of custom tag String After start tag Variable name in case when formatted string is output to a scripting variable and not output in this custom tag.

See Also:
DateTag, JDateTag, Serialized Form

Field Summary
private static java.lang.String DATE_FORMAT
          Default value of date and time format. It is used at the time of parsing the string data as date and time.
protected  boolean filter
          Check whether the special HTML characters are to be filtered. Default is true.
protected  java.lang.String format
          Date and time format to be entered.
protected  java.lang.String id
          Name of scripting variable that can be used on respective page.
protected  boolean ignore
          Check whether to ignore (nothing is output) when bean is not found. Throws exception when it is not to be ignored. Default is false. (Throws exception).
private static org.apache.commons.logging.Log log
          Log class.
protected  java.lang.String name
          bean name that includes the data to be formatted.
protected  java.lang.String pattern
          Pattern that specifies the output format. Pattern should be same as SimpleDateFormat.
protected  java.lang.String property
          Property name which is accessed in the specified bean.
protected  java.lang.String scope
          Scope to search the specified bean.
protected  java.lang.String value
          Value to be formatted(string).
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
pageContext
 
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
DateFormatterTagBase()
           
 
Method Summary
protected abstract  java.lang.String doFormat(java.util.Date date)
          Abstract method that formats the date and time. It is overridden in subclass.
 int doStartTag()
          Method which is called at the time of starting tag evaluation.
protected  java.lang.String getDefaultDateFormat()
          Fetches the default value of date and time format.
 java.lang.String getFormat()
          Fetches the date and time format which is the input.
 void release()
          Release all allocated resources.
 void setFilter(boolean filter)
          setFilter method to decide whether special HTML characters that are being output are to be filtered.
 void setFormat(java.lang.String format)
          Sets the format of date and time which is the input.
 void setId(java.lang.String id)
          Sets the name of scripting variable.
 void setIgnore(boolean ignore)
          setIgnore method to decide whether to ignore when bean is not found.
 void setName(java.lang.String name)
          Sets the bean name that includes the data to be formatted.
 void setPattern(java.lang.String pattern)
          Sets the pattern that specifies the output format.
 void setProperty(java.lang.String property)
          Sets the property name which is accessed in spcified bean.
 void setScope(java.lang.String scope)
          Sets the scope to search the specified bean.
 void setValue(java.lang.String value)
          Sets the value to be formatted.
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
doAfterBody, doEndTag, findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Log class.


DATE_FORMAT

private static final java.lang.String DATE_FORMAT
Default value of date and time format. It is used at the time of parsing the string data as date and time.

See Also:
Constant Field Values

format

protected java.lang.String format
Date and time format which is the input.


id

protected java.lang.String id
Name of scripting variable which can be used on the respective page.


filter

protected boolean filter
Decide whether to filter the special HTML characters. Default is true.


ignore

protected boolean ignore
Check whether to ignore (noting is output) when bean is not found. Throws an exception when it is not to be ignored. Default is false (Throws exception).


name

protected java.lang.String name
Name of bean that includes the data to be formatted.


property

protected java.lang.String property
Property anme which is accessed in the specified bean.


scope

protected java.lang.String scope
Scope to search the specified bean.


pattern

protected java.lang.String pattern
Pattern that specifies the output format. It should be same as SimpleDateFormat.


value

protected java.lang.String value
Value to be formatted.(string).

Constructor Detail

DateFormatterTagBase

public DateFormatterTagBase()
Method Detail

getDefaultDateFormat

protected java.lang.String getDefaultDateFormat()
Fetches the default value of date and time format.

To change the default value, override this method.

*Default value is "yyyy/MM/dd HH:mm:ss"

Returns:
Default value of date and time format

getFormat

public java.lang.String getFormat()
Fetches the format of date and time which is the input.

Returns:
Date and time format

setFormat

public void setFormat(java.lang.String format)
Sets the date and time format which is the input.

Parameters:
format - Date and time format

setId

public void setId(java.lang.String id)
Sets the name of scripting variable.

Overrides:
setId in class javax.servlet.jsp.tagext.TagSupport
Parameters:
id - Scripting variable name

setFilter

public void setFilter(boolean filter)
setFilter method to decide whether to filter the special HTML characters.

Parameters:
filter - When the Special HTML character are to be filtered,it is true
.

setIgnore

public void setIgnore(boolean ignore)
setIgnore method to decide whether to ignore when bean is not found.

Parameters:
ignore - It is true
when it is to be ignored.

setName

public void setName(java.lang.String name)
Sets the bean name which includes the data to be formatted.

Parameters:
name - bean name

setProperty

public void setProperty(java.lang.String property)
Sets the property name which is accessed in the specified bean.

Parameters:
property - Property name

setScope

public void setScope(java.lang.String scope)
Sets the scope to search the specified bean.

Parameters:
scope - Scope

setPattern

public void setPattern(java.lang.String pattern)
Sets the pattern that specifies the output format.

Parameters:
pattern - Pattern

setValue

public void setValue(java.lang.String value)
Sets the value to be formatted.

Parameters:
value - Value to be formatted

doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException
Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doStartTag in class javax.servlet.jsp.tagext.TagSupport
Returns:
Process control instructions. Always SKIP_BODY
Throws:
javax.servlet.jsp.JspException - JSP exception

release

public void release()
Releases all allocated resources.

Specified by:
release in interface javax.servlet.jsp.tagext.Tag
Overrides:
release in class javax.servlet.jsp.tagext.TagSupport

doFormat

protected abstract java.lang.String doFormat(java.util.Date date)
Abstract method that formats the date and time. It is overridden in subclass.

Parameters:
date - Date and time
Returns:
Formatted string