package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; import cwp.tags.*; /** A tag that replaces <, >, ", and & with their HTML * character entities (<, >, ", and &). * After filtering, arbitrary strings can be placed * in either the page body or in HTML attributes. *

* Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun Microsystems Press, * http://www.corewebprogramming.com/. * May be freely used or adapted. */ public class FilterTag extends BodyTagSupport { public int doAfterBody() { BodyContent body = getBodyContent(); String filteredBody = ServletUtilities.filter(body.getString()); try { JspWriter out = body.getEnclosingWriter(); out.println("*************"); out.print(filteredBody); out.println("*************"); } catch(IOException ioe) { System.out.println("Error in FilterTag: " + ioe); } // SKIP_BODY means we're done. If we wanted to evaluate // and handle the body again, we'd return EVAL_BODY_TAG. return(SKIP_BODY); } }