javawebparts.taglib.basicstr
Class TrimTag

java.lang.Object
  |
  +--javax.servlet.jsp.tagext.TagSupport
        |
        +--javax.servlet.jsp.tagext.BodyTagSupport
              |
              +--javawebparts.taglib.basicstr.TrimTag
All Implemented Interfaces:
javax.servlet.jsp.tagext.BodyTag, javax.servlet.jsp.tagext.IterationTag, java.io.Serializable, javax.servlet.jsp.tagext.Tag

public class TrimTag
extends javax.servlet.jsp.tagext.BodyTagSupport

This class is a custom tag that trims a string. This function can work in a number of ways, defined by setting the following attributes:

type - This is the type of trim to perform. This can be one of the following values: left, right or both. 'left' trims characters from the start of a string, 'right' trims them from the end and 'both' trims from the start as well as the end. Required: Yes.
chars - If specified, the characters listed will be trimmed, and only them. Note that these characters get inserted into a regular expressino, so if you need to trim characters that have special meaning to a regex, you will have to manually escape them properly. Required: No (when this attribute is not present, the default function of trimming only whitespace will be used).

Author:
Frank W. Zammetti.
See Also:
Serialized Form

Field Summary
private  java.lang.String chars
          This is the list of characters to trim when other than whitespace.
private static org.apache.commons.logging.Log log
          Log instance.
private  java.lang.String text
          This is the body content text to be altered.
private  java.lang.String type
          This is the trim type attribute.
 
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
TrimTag()
           
 
Method Summary
 int doAfterBody()
          Alter the body content.
 int doEndTag()
          Render the altered body.
 void setChars(java.lang.String inChars)
          chars mutator.
 void setType(java.lang.String inType)
          type mutator.
 
Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
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

log

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


text

private java.lang.String text
This is the body content text to be altered.


type

private java.lang.String type
This is the trim type attribute. Valid values are left, right, both.


chars

private java.lang.String chars
This is the list of characters to trim when other than whitespace.

Constructor Detail

TrimTag

public TrimTag()
Method Detail

setType

public void setType(java.lang.String inType)
type mutator.

Parameters:
inType - Trim type.

setChars

public void setChars(java.lang.String inChars)
chars mutator.

Parameters:
inChars - Chars to trim if other than whitespace.

doAfterBody

public int doAfterBody()
                throws javax.servlet.jsp.JspException
Alter the body content.

Specified by:
doAfterBody in interface javax.servlet.jsp.tagext.IterationTag
Overrides:
doAfterBody in class javax.servlet.jsp.tagext.BodyTagSupport
Returns:
Return code.
Throws:
javax.servlet.jsp.JspException - If anything goes wrong.

doEndTag

public int doEndTag()
             throws javax.servlet.jsp.JspException
Render the altered body.

Specified by:
doEndTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doEndTag in class javax.servlet.jsp.tagext.BodyTagSupport
Returns:
Return code.
Throws:
javax.servlet.jsp.JspException - If anything goes wrong.


Copyright 2005 Frank W. Zammetti