javawebparts.taglib.basicstr
Class SubstrTag

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

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

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

type - This is the type of substring to get. Valid values are "mid", "left" and "right". Required: Yes.
count - This attribute is required when type is "left" or "right". It is the number of characters from the left or right of the source string, depending on what type is, that will be returned. If this value is <= 0 then nothing will returned. If this value is > the length of the source string then the entire source string will be returned. Required: Yes, if type is "left" or "right".
start - This attribute is required when type is "mid". It is the 1-based character the substring begins at, inclusive. In other words, the first character of the string is 1, so a value of 1 will start with the first character. If this value is less than 1 or is greater than the length of the source string, the value 1 will be used. Required: Yes, if type is "mid".
end - This attribute is required when type is "mid". It is the 1-based character the substring ends at, inclusive. If this value is less than 1 or is greater than the length of the source string, the length of the string will be user. Required: Yes, if type is "mid".

Note that in all cases if an attribute is unparsable as a number either because it is not present or has a non-parsable value, this tag will return nothing.

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

Field Summary
private  java.lang.String count
          Number of characters to return when doing "left" or "right" type.
private  java.lang.String end
          End of substring when type is "mid".
private static org.apache.commons.logging.Log log
          Log instance.
private  java.lang.String start
          Start of substring when type is "mid".
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
SubstrTag()
           
 
Method Summary
 int doAfterBody()
          Alter the body content.
 int doEndTag()
          Render the altered body.
 void setCount(java.lang.String inCount)
          count mutator.
 void setEnd(java.lang.String inEnd)
          end mutator.
 void setStart(java.lang.String inStart)
          start 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.


count

private java.lang.String count
Number of characters to return when doing "left" or "right" type.


start

private java.lang.String start
Start of substring when type is "mid".


end

private java.lang.String end
End of substring when type is "mid".

Constructor Detail

SubstrTag

public SubstrTag()
Method Detail

setType

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

Parameters:
inType - Trim type.

setCount

public void setCount(java.lang.String inCount)
count mutator.

Parameters:
inCount - count.

setStart

public void setStart(java.lang.String inStart)
start mutator.

Parameters:
inStart - start.

setEnd

public void setEnd(java.lang.String inEnd)
end mutator.

Parameters:
inEnd - end.

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