1 5 package com.opensymphony.webwork.views.jsp; 6 7 import com.opensymphony.util.TextUtils; 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 11 import javax.servlet.jsp.JspException ; 12 import java.io.IOException ; 13 14 15 19 public class PropertyTag extends WebWorkTagSupport { 20 22 private static final Log log = LogFactory.getLog(PropertyTag.class); 23 24 26 private String defaultValue; 27 private String value; 28 private boolean escape = true; 29 30 32 public void setDefault(String defaultValue) { 33 this.defaultValue = defaultValue; 34 } 35 36 public void setEscape(boolean escape) { 37 this.escape = escape; 38 } 39 40 public void setValue(String value) { 41 this.value = value; 42 } 43 44 public int doStartTag() throws JspException { 45 try { 46 Object actualValue = null; 47 48 if (value == null) { 49 value = "top"; 50 } 51 52 actualValue = getStack().findValue(value, String .class); 56 57 if (actualValue != null) { 58 pageContext.getOut().print(prepare(actualValue)); 59 } else if (defaultValue != null) { 60 pageContext.getOut().print(prepare(defaultValue)); 61 } 62 } catch (IOException e) { 63 log.info("Could not print out value '" + value + "': " + e.getMessage()); 64 } 65 66 return SKIP_BODY; 67 } 68 69 private Object prepare(Object value) { 70 if (escape) { 71 return TextUtils.htmlEncode(value.toString()); 72 } else { 73 return value; 74 } 75 } 76 } 77 | Popular Tags |