1 18 19 package org.apache.struts.taglib.bean; 20 21 import java.util.Locale ; 22 23 import javax.servlet.jsp.JspException ; 24 import javax.servlet.jsp.tagext.TagSupport ; 25 26 import org.apache.struts.Globals; 27 import org.apache.struts.taglib.TagUtils; 28 import org.apache.struts.util.MessageResources; 29 30 38 public class MessageTag extends TagSupport { 39 40 42 45 protected String arg0 = null; 46 47 public String getArg0() { 48 return (this.arg0); 49 } 50 51 public void setArg0(String arg0) { 52 this.arg0 = arg0; 53 } 54 55 58 protected String arg1 = null; 59 60 public String getArg1() { 61 return (this.arg1); 62 } 63 64 public void setArg1(String arg1) { 65 this.arg1 = arg1; 66 } 67 68 71 protected String arg2 = null; 72 73 public String getArg2() { 74 return (this.arg2); 75 } 76 77 public void setArg2(String arg2) { 78 this.arg2 = arg2; 79 } 80 81 84 protected String arg3 = null; 85 86 public String getArg3() { 87 return (this.arg3); 88 } 89 90 public void setArg3(String arg3) { 91 this.arg3 = arg3; 92 } 93 94 97 protected String arg4 = null; 98 99 public String getArg4() { 100 return (this.arg4); 101 } 102 103 public void setArg4(String arg4) { 104 this.arg4 = arg4; 105 } 106 107 110 protected String bundle = null; 111 112 public String getBundle() { 113 return (this.bundle); 114 } 115 116 public void setBundle(String bundle) { 117 this.bundle = bundle; 118 } 119 120 124 protected static final Locale defaultLocale = Locale.getDefault(); 125 126 129 protected String key = null; 130 131 public String getKey() { 132 return (this.key); 133 } 134 135 public void setKey(String key) { 136 this.key = key; 137 } 138 139 142 protected String name = null; 143 144 public String getName() { 145 return (this.name); 146 } 147 148 public void setName(String name) { 149 this.name = name; 150 } 151 152 155 protected String property = null; 156 157 public String getProperty() { 158 return (this.property); 159 } 160 161 public void setProperty(String property) { 162 this.property = property; 163 } 164 165 168 protected String scope = null; 169 170 public String getScope() { 171 return (this.scope); 172 } 173 174 public void setScope(String scope) { 175 this.scope = scope; 176 } 177 178 181 protected String localeKey = Globals.LOCALE_KEY; 182 183 public String getLocale() { 184 return (this.localeKey); 185 } 186 187 public void setLocale(String localeKey) { 188 this.localeKey = localeKey; 189 } 190 191 194 protected static MessageResources messages = 195 MessageResources.getMessageResources( 196 "org.apache.struts.taglib.bean.LocalStrings"); 197 198 200 205 public int doStartTag() throws JspException { 206 207 String key = this.key; 208 if (key == null) { 209 Object value = TagUtils.getInstance().lookup(pageContext, name, property, scope); 211 if (value != null && !(value instanceof String )) { 212 JspException e = 213 new JspException (messages.getMessage("message.property", key)); 214 TagUtils.getInstance().saveException(pageContext, e); 215 throw e; 216 } 217 key = (String ) value; 218 } 219 220 Object args[] = new Object [] { arg0, arg1, arg2, arg3, arg4 }; 222 223 String message = 225 TagUtils.getInstance().message( 226 pageContext, 227 this.bundle, 228 this.localeKey, 229 key, 230 args); 231 232 if (message == null) { 233 JspException e = 234 new JspException ( 235 messages.getMessage("message.message", "\"" + key + "\"")); 236 TagUtils.getInstance().saveException(pageContext, e); 237 throw e; 238 } 239 240 TagUtils.getInstance().write(pageContext, message); 241 242 return (SKIP_BODY); 243 244 } 245 246 249 public void release() { 250 251 super.release(); 252 arg0 = null; 253 arg1 = null; 254 arg2 = null; 255 arg3 = null; 256 arg4 = null; 257 bundle = Globals.MESSAGES_KEY; 258 key = null; 259 name = null; 260 property = null; 261 scope = null; 262 localeKey = Globals.LOCALE_KEY; 263 264 } 265 266 } 267 | Popular Tags |