webwork/src/main/webwork/view/taglib PropertyTag.java,1.1,1.2
[email protected] Tue, 07 May 2002 18:40:11 -0700
| Newsgroups | gmane.comp.java.webwork.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/webwork/webwork/src/main/webwork/view/taglib In directory usw-pr-cvs1:/tmp/cvs-serv31235 Modified Files: PropertyTag.java Log Message: added escaping HTML Index: PropertyTag.java =================================================================== RCS file: /cvsroot/webwork/webwork/src/main/webwork/view/taglib/PropertyTag.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PropertyTag.java 3 Mar 2002 04:11:47 -0000 1.1 --- PropertyTag.java 8 May 2002 01:40:08 -0000 1.2 *************** *** 7,10 **** --- 7,12 ---- package webwork.view.taglib; + import webwork.util.TextUtil; + import javax.servlet.ServletException; import javax.servlet.jsp.JspException; *************** *** 14,28 **** /** ! * Access the value of a named property. * * @author Rickard Öberg ([email protected]) * @version $Revision$ */ public final class PropertyTag ! extends WebWorkBodyTagSupport { // Attributes ---------------------------------------------------- String valueAttr; ! boolean hadBody; --- 16,33 ---- /** ! * Access the value of a named property. By default, this tag ! * will escape its contents if it does not have a body. If it ! * does, it will not escape the contents. * * @author Rickard Öberg ([email protected]) + * @author Matt Baldree ([email protected]) * @version $Revision$ */ public final class PropertyTag ! extends WebWorkBodyTagSupport { // Attributes ---------------------------------------------------- String valueAttr; ! Boolean escape; boolean hadBody; *************** *** 33,36 **** --- 38,46 ---- } + public void setEscape(boolean escape) + { + this.escape = new Boolean(escape); + } + // BodyTag implementation ---------------------------------------- public int doStartTag() throws JspException *************** *** 41,46 **** String id = getId(); ! if(id != null && value != null) ! { pageContext.setAttribute(id, value); pageContext.setAttribute(id, value, PageContext.REQUEST_SCOPE); --- 51,55 ---- String id = getId(); ! if (id != null && value != null) { pageContext.setAttribute(id, value); pageContext.setAttribute(id, value, PageContext.REQUEST_SCOPE); *************** *** 57,72 **** String body = getBodyContent().getString(); hadBody = body.length() != 0; ! if (hadBody) ! { ! try ! { bodyContent.getEnclosingWriter().write(body); ! } catch(java.io.IOException e) ! { ! throw new JspTagException("Could not show attribute "+valueAttr+":"+e); } } - return SKIP_BODY; } --- 66,84 ---- String body = getBodyContent().getString(); hadBody = body.length() != 0; + //by default, we do not want to escape the body + if (escape == null) { + escape = new Boolean(!hadBody); + } ! if (hadBody) { ! try { ! if (escape.booleanValue()) { ! body = TextUtil.escapeHTML(body); ! } bodyContent.getEnclosingWriter().write(body); ! } catch (java.io.IOException e) { ! throw new JspTagException("Could not show attribute " + valueAttr + ":" + e); } } return SKIP_BODY; } *************** *** 76,108 **** Object value = getStack().popValue(); ! if(!hadBody) ! { // No body used. This means that we want to print the parameter out ! try ! { //Category.getInstance(this.getClass()).debug("Property value:"+value); ! if(value != null) ! if (value instanceof Iterator) ! { ! Iterator enum = (Iterator)value; ! if (enum.hasNext()) ! pageContext.getOut().write(enum.next().toString()); ! } else if ( value instanceof char[] ) ! { ! pageContext.getOut().write( String.valueOf( (char[]) value ) ); ! } else ! { ! pageContext.getOut().write(value.toString()); } else pageContext.getOut().write(""); // Printing out null gives no output return EVAL_PAGE; ! } catch(Exception e) ! { ! new ServletException("Could not show value "+valueAttr, e); } } return EVAL_PAGE; } } --- 88,135 ---- Object value = getStack().popValue(); ! if (!hadBody) { // No body used. This means that we want to print the parameter out ! try { //Category.getInstance(this.getClass()).debug("Property value:"+value); ! if (value != null) ! if (value instanceof Iterator) { ! Iterator enum = (Iterator) value; ! if (enum.hasNext()) { ! if (escape.booleanValue()) { ! pageContext.getOut().write(TextUtil.escapeHTML(enum.next().toString())); ! } else { ! pageContext.getOut().write(enum.next().toString()); ! } ! } ! } else if (value instanceof char[]) { ! if (escape.booleanValue()) { ! pageContext.getOut().write(TextUtil.escapeHTML(String.valueOf((char[]) value))); ! //pageContext.getOut().write(String.valueOf((char[]) value)); ! } else { ! pageContext.getOut().write(String.valueOf((char[]) value)); ! } ! } else { ! if (escape.booleanValue()) { ! pageContext.getOut().write(TextUtil.escapeHTML(value.toString())); ! //pageContext.getOut().write(value.toString()); ! } else { ! pageContext.getOut().write(value.toString()); ! } } else pageContext.getOut().write(""); // Printing out null gives no output return EVAL_PAGE; ! } catch (Exception e) { ! new ServletException("Could not show value " + valueAttr, e); } } return EVAL_PAGE; + } + + public void release() + { + escape = null; + super.release(); } } _______________________________________________________________ Have big pipes? SourceForge.net is looking for download mirrors. We supply the hardware. You get the recognition. Email Us: [email protected]