javawebparts.taglib.jstags
Class StringContentValidTag

java.lang.Object
  |
  +--javax.servlet.jsp.tagext.TagSupport
        |
        +--javawebparts.taglib.jstags.StringContentValidTag
All Implemented Interfaces:
javax.servlet.jsp.tagext.IterationTag, java.io.Serializable, javax.servlet.jsp.tagext.Tag

public class StringContentValidTag
extends javax.servlet.jsp.tagext.TagSupport

This class is a custom tag that renders the JWPStringContentValid() Javascript function which can be called to determine if a string contains only valid characters, or if a string does no contain any of a list of valid characters.

This tag uses the following attributes:

renderScriptTags - true/false - When set to true, the Javascript will be rendered inside a <script> </script> tag pair. When set to false, this will not be done and it is expected that the <jstags:fullTrim/> tag appears inside a <script> </script> tag pair. If this attribute is not present, the script tags WILL be rendered.

It renders the following Javascript:

JWPSCV_FROMLIST = 1; JWPSCV_NOTFROMLIST = 2; function JWPStringContentValid(jwpscv_inString, jwpscv_charList, jwpscv_FromExcept) { if (jwpscv_inString == null) { alert("Input string was null"); return false; } if (jwpscv_charList == null) { alert("Character list was null"); return false; } if (jwpscv_FromExcept == null) { alert("FROMLIST/NOTFROMLIST was null"); return false; } if (jwpscv_FromExcept == JWPSCV_FROMLIST) { for (i = 0; i < jwpscv_inString.length; i++) { if (jwpscv_charList.indexOf(jwpscv_inString.charAt(i)) == -1) { return false; } }
return true;
}
if (jwpscv_FromExcept == JWPSCV_NOTFROMLIST) {
for (i = 0; i < jwpscv_inString.length; i++) {
if (jwpscv_charList.indexOf(jwpscv_inString.charAt(i)) != -1) {
return false;
}
}
return true;
}
}

Usage example:

alert(JWPStringContentValid("This is a test", " thisae", JWPSCV_FROMLIST));
This will result in an alert box displaying "true" in it because all the characters in the string "This is a test" are in the character list " thisae", and the JWPSCV_FROMLIST flag was sent in. If you replace one of the characters with 'z' in the string being tested for instance, false would be shown because 'z' is not in the list of allowed characters.

alert(JWPStringContentValid("This is a test", "xyz", JWPSCV_NOTFROMLIST));
This will result in an alert box displaying "true" in it because none the characters in the string "This is a test" are in the character list " thisae", and the JWPSCV_NOTFROMLIST flag was sent in. If you replace one of the characters with 'z' in the string being tested for instance, false would be shown because 'z' is in the list of characters not allowed.

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

Field Summary
private static org.apache.commons.logging.Log log
          Log instance.
private  java.lang.String renderScriptTags
          Whether to render the opening and closing script tags around the emitted Javascript.
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, 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
StringContentValidTag()
           
 
Method Summary
 int doStartTag()
          Render the results of the tag.
 void setRenderScriptTags(java.lang.String inRenderScriptTags)
          renderScriptTags mutator.
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
doAfterBody, doEndTag, findAncestorWithClass, getId, getParent, getValue, getValues, release, removeValue, setId, 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 instance.


renderScriptTags

private java.lang.String renderScriptTags
Whether to render the opening and closing script tags around the emitted Javascript.

Constructor Detail

StringContentValidTag

public StringContentValidTag()
Method Detail

setRenderScriptTags

public void setRenderScriptTags(java.lang.String inRenderScriptTags)
renderScriptTags mutator.

Parameters:
inRenderScriptTags - renderScriptTags.

doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException
Render the results of the tag.

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


Copyright 2005 Frank W. Zammetti