1 5 package com.opensymphony.webwork.views.jsp; 6 7 import com.opensymphony.webwork.views.jsp.ParamTag; 8 import com.opensymphony.webwork.views.jsp.WebWorkBodyTagSupport; 9 import com.opensymphony.xwork.TextProvider; 10 import com.opensymphony.xwork.util.OgnlValueStack; 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 14 import javax.servlet.jsp.JspException ; 15 import java.io.IOException ; 16 import java.util.ArrayList ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 import java.util.Map ; 20 21 22 36 public class TextTag extends WebWorkBodyTagSupport implements ParamTag.UnnamedParametric { 37 39 private static final Log LOG = LogFactory.getLog(TextTag.class); 40 41 43 protected String value0Attr; 44 protected String value1Attr; 45 protected String value2Attr; 46 protected String value3Attr; 47 List values; 48 String actualName; 49 String nameAttr; 50 51 53 public void setName(String name) { 54 this.nameAttr = name; 55 } 56 57 public Map getParameters() { 58 return null; 59 } 60 61 public void setValue0(String aName) { 62 LOG.warn("The value attributes of TextTag are deprecated."); 63 value0Attr = aName; 64 } 65 66 public void setValue1(String aName) { 67 LOG.warn("The value attributes of TextTag are deprecated."); 68 value1Attr = aName; 69 } 70 71 public void setValue2(String aName) { 72 LOG.warn("The value attributes of TextTag are deprecated."); 73 value2Attr = aName; 74 } 75 76 public void setValue3(String aName) { 77 LOG.warn("The value attributes of TextTag are deprecated."); 78 value3Attr = aName; 79 } 80 81 public void addParameter(String key, Object value) { 82 addParameter(value); 83 } 84 85 public void addParameter(Object value) { 86 if (value == null) { 87 return; 88 } 89 90 if (values == null) { 91 values = new ArrayList (); 92 } 93 94 values.add(value); 95 } 96 97 public int doEndTag() throws JspException { 98 actualName = (String ) findString(nameAttr); 99 100 if (value0Attr != null) { 103 addParameter(findValue(value0Attr)); 104 } 105 106 if (value1Attr != null) { 107 addParameter(findValue(value1Attr)); 108 } 109 110 if (value2Attr != null) { 111 addParameter(findValue(value2Attr)); 112 } 113 114 if (value3Attr != null) { 115 addParameter(findValue(value3Attr)); 116 } 117 118 String defaultMessage; 119 120 if ((bodyContent != null) && (bodyContent.getString().trim().length() > 0)) { 121 defaultMessage = bodyContent.getString().trim(); 122 } else { 123 defaultMessage = actualName; 124 } 125 126 String msg = null; 127 OgnlValueStack stack = getStack(); 128 129 for (Iterator iterator = getStack().getRoot().iterator(); 130 iterator.hasNext();) { 131 Object o = iterator.next(); 132 133 if (o instanceof TextProvider) { 134 TextProvider tp = (TextProvider) o; 135 msg = tp.getText(actualName, defaultMessage, values, stack); 136 137 break; 138 } 139 } 140 141 if (msg != null) { 142 try { 143 if (getId() == null) { 144 pageContext.getOut().write(msg); 145 } else { 146 stack.getContext().put(getId(), msg); 147 } 148 } catch (IOException e) { 149 throw new JspException (e); 150 } 151 } 152 153 return EVAL_PAGE; 154 } 155 156 public int doStartTag() throws JspException { 157 values = null; 158 159 return super.doStartTag(); 160 } 161 } 162 | Popular Tags |