jp.terasoluna.fw.web.taglib
Class StringFormatterTagBase

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by jp.terasoluna.fw.web.taglib.StringFormatterTagBase
All Implemented Interfaces:
java.io.Serializable, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.Tag
Direct Known Subclasses:
LeftTag, LTrimTag, RTrimTag, TrimTag

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

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

The class of custom tag that formats the trimming of the string,is created by inheriting this class. (fmtx custom tag library which is provided by TERASOLUNA)

Depending on the id attribute, the string which is formatted by this class is either output to the response or set to scripting variable.

The priority sequence for the string to be formatted is as follows.

  1. When value attribute is specified, the string specified in that attribute is formatted.
  2. When bean name is specified in the name attribute, property which is specified in property attribute of bean instance, is formatted.

When name attribute is specified and property attribute is not specified, value of the instance (string of object which is returned by toString() method) which is specified in name attribute needs to be formatted.

When the bean specified in name attribute is not found, the custom tag operation is decided depending on the ignore attribute. When ignore attribute is true and bean is not found, it is ignored and nothing is output. (When id attribute is specified, it is not set to scripting variable).

When ignore attribute is false(default) and the bean specified by name attribute, is not found, JspException is thrown.

scope attribute can be specified as the search target of bean. When scope attribute is not specified, search is performed as per the search order of findAttribute() method in javax.servlet.jsp.PageContext class.

When id attribute is specified,the formatted string is not output but is set to the scripting variable with the name specified in id attribute.

When filter attribute is true(default), special HTML characters (It is processed by using the filter() method of org.apache.struts.util.ResponceUtils class.The special HTML characters are namely, "<", ">", "&" and """) are escaped when they are output. At the time of setting the string to scripting variable, filter attribute is ignored and formatted string is set to scripting variable as it is.

When replaceSpToNbsp attribute is true(default), it is converted to "&nbsp;" when 1Byte code space (half-width space) exists. At the time of setting the string to scripting variable, replaceSpToNbsp attribute is ignored and formatted string is set to scripting variable as it is.

In the subclass that inherits StringFormatterTagBase class, abstract method doFormat() that formats the actual string, is implemented.


Attribute supported by tag

In StringFormatterTagBase, folowing attributes are supported.

Attribute name Default Required Execution time Description
id - Any false It is specified when the formatted string is to be set to scripting variable without outputting the string.When the formatted string is to be set to scripting variable, irrespective of whether the filter is specified or not, the special HTML characters are not escaped.
filter true - Any At the time of outputting the formatted string, specify whether the special HTML characetrs are to be escaped. It is ignored when id attribute is specified.
ignore false - Any When the bean which is specified in name attribute,specify whether to ignore. If falseis specified and bean is not found, JspException is thrown.
name - - Any bean name that contains the string to be formatted in the property. When property attribute is not specified, the string which is returned by string representation toString() method of the instance needs to be formatted. This instance is specified in string representation name attribute. When value attribute is specified, it is ignored.
property - - Any Property name which is accessed in bean. This bean is specified in the name attribute. When value attribute is specified, it is ignored.
scope (Search order of findAttribute() method) - Any Scope to search the bean which is specified in name attribute.
value None - Any String to be formatted. When value attribute is specified, name attribute and propertyattribute are ignored.
replaceSpToNbsp - false true This attribute is set to true. When the value of specified bean property contains 1Byte code space, it is replaced with &nbsp;. To invalidate, it is necessary to explicitly set false in this attribute. When id attribute is specified, it is ignored.

Scripting variable of custom tag

In StringFormatterTagBase, following variables are supported.

Scripting variable name Type Available range of variable Description
Name specified in idattribute of custom tag. java.lang.String After start tag Variable name in case when string is output to a scripting variable and not output in this custom tag.

See Also:
LeftTag, RTrimTag, LTrimTag, TrimTag, Serialized Form

Field Summary
protected  boolean filter
          Check whether to filter the special HTML characters. Default is true.
protected  java.lang.String id
          Name of scriptign variable which is used on the respective page.
protected  boolean ignore
          It is ignored when bean is not found.(nothing is output) Throws exception when it is not 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 property
          Property name which is accessed in specified bean.
protected  boolean replaceSpToNbsp
           Half-width space is replaced with &nbsp;.
protected  java.lang.String scope
          Scope to search the specified bean.
protected  java.lang.String value
          Value (string) to be formatted
 
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
StringFormatterTagBase()
           
 
Method Summary
protected abstract  java.lang.String doFormat(java.lang.String s)
          Abstract method that formats the string. It is overridden in subclass.
 int doStartTag()
          Method which is called at the time of starting the tag evaluation.
 boolean getFilter()
          Get filter method to decide whether the special HTML characters are to be filtered.
 java.lang.String getId()
          Fetches the name of scripting variable.
 boolean getIgnore()
          GetIgnore method to decide whether to ignore when bean is not found.
 java.lang.String getName()
          Fetches the bean name that includes the data to be formatted.
 java.lang.String getProperty()
          Fetches the property name which acccessed in the specified bean.
 boolean getReplaceSpToNbsp()
           get method of replaceSpToNbsp
 java.lang.String getScope()
          Fetches the scope to search the specified bean.
 java.lang.String getValue()
          Fetches the value to be formatted.
 void release()
          Releases all allocated resources.
 void setFilter(boolean filter)
          setFilter method to filter the special HTML characters.
 void setId(java.lang.String id)
          Sets 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 setProperty(java.lang.String property)
          Sets the property name which is accessed in specified bean.
 void setReplaceSpToNbsp(boolean replaceSpToNbsp)
           set method of replaceSpToNbsp
 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, 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


id

protected java.lang.String id
Name of scripting variable which is available on the respective page.


filter

protected boolean filter
Check whether the special HTML characters are to be filtered. Default is true.


ignore

protected boolean ignore
Check whether to ignore (nothing is output) when bean is not found. When it is not ignored, throws exception. Default is false(throws exception).


name

protected java.lang.String name
Bean name that includes the data to be formatted.


property

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


scope

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


value

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


replaceSpToNbsp

protected boolean replaceSpToNbsp

Replace half-width space with &nbsp;.

Constructor Detail

StringFormatterTagBase

public StringFormatterTagBase()
Method Detail

getId

public java.lang.String getId()
Fetches the name of scripting variable.

Overrides:
getId in class javax.servlet.jsp.tagext.TagSupport
Returns:
Scripting variable name

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

getFilter

public boolean getFilter()
Get filter method to decide whether to filter the special HTML characters.

Returns:
It is true when special HTML characters are to be filtered

setFilter

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

Parameters:
filter - It is true when special HTML characters are to be filtered

getIgnore

public boolean getIgnore()
Get ignore method to decide whether to ignore when bean is not found.

Returns:
It is true when it is to be ignored

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 ignored

getName

public java.lang.String getName()
Fetches the bean name that includes the data to be formatted.

Returns:
bean name

setName

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

Parameters:
name - bean name

getProperty

public java.lang.String getProperty()
Fetches the property name which is accessed in the specified bean.

Returns:
Property name

setProperty

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

Parameters:
property - Property name

getScope

public java.lang.String getScope()
Fetches the scope to search the specified bean.

Returns:
Scope

setScope

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

Parameters:
scope - Scope

getValue

public java.lang.String getValue()
Fetches the value to be formatted.

Returns:
Value to be formatted

setValue

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

Parameters:
value - Value to be formatted

getReplaceSpToNbsp

public boolean getReplaceSpToNbsp()

get method of replaceSpToNbsp

Returns:
replaceSpToNbsp Replace half-width space to &nbsp; conversion flag

setReplaceSpToNbsp

public void setReplaceSpToNbsp(boolean replaceSpToNbsp)

set method of replaceSpToNbsp

Parameters:
replaceSpToNbsp - Replace half-width space to &nbsp; conversion flag

doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException
Method which is called at the time of starting tag evaluation.

Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doStartTag in class javax.servlet.jsp.tagext.TagSupport
Returns:
Process control instructions
Throws:
javax.servlet.jsp.JspException - Error at the time of tag evaluation

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.lang.String s)
Abstract method that formats the string. It is overridden in subclass.

Parameters:
s - String to be formatted
Returns:
Formatted string