1 16 package com.blandware.atleap.webapp.taglib.core.html; 17 18 import com.blandware.atleap.common.util.StringUtil; 19 import com.blandware.atleap.webapp.util.core.ApplicationResources; 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 import org.apache.struts.taglib.TagUtils; 23 import org.apache.struts.util.RequestUtils; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.jsp.JspException ; 27 import javax.servlet.jsp.PageContext ; 28 import javax.servlet.jsp.tagext.SimpleTagSupport ; 29 import java.util.Locale ; 30 31 80 public class MessageTag extends SimpleTagSupport { 81 82 protected transient final Log log = LogFactory.getLog(MessageTag.class); 83 84 87 protected String key; 88 89 92 protected Boolean ignore = Boolean.FALSE; 93 94 97 protected Boolean filter = Boolean.FALSE; 98 99 102 protected String var; 103 104 107 protected String scope; 108 109 112 protected String language; 113 114 117 protected String arg0 = null; 118 119 122 protected String arg1 = null; 123 124 127 protected String arg2 = null; 128 129 132 protected String arg3 = null; 133 134 137 protected String arg4 = null; 138 139 140 149 public String getKey() { 150 return key; 151 } 152 153 158 public void setKey(String key) { 159 this.key = key; 160 } 161 162 171 public Boolean getIgnore() { 172 return ignore; 173 } 174 175 180 public void setIgnore(Boolean ignore) { 181 this.ignore = ignore; 182 } 183 184 193 public Boolean getFilter() { 194 return filter; 195 } 196 197 202 public void setFilter(Boolean filter) { 203 this.filter = filter; 204 } 205 206 215 public String getLanguage() { 216 return language; 217 } 218 219 224 public void setLanguage(String language) { 225 this.language = language; 226 } 227 228 237 public String getVar() { 238 return var; 239 } 240 241 246 public void setVar(String var) { 247 this.var = var; 248 } 249 250 259 public String getScope() { 260 return scope; 261 } 262 263 268 public void setScope(String scope) { 269 this.scope = scope; 270 } 271 272 281 public String getArg0() { 282 return arg0; 283 } 284 285 290 public void setArg0(String arg0) { 291 this.arg0 = arg0; 292 } 293 294 303 public String getArg1() { 304 return arg1; 305 } 306 307 312 public void setArg1(String arg1) { 313 this.arg1 = arg1; 314 } 315 316 317 326 public String getArg2() { 327 return arg2; 328 } 329 330 335 public void setArg2(String arg2) { 336 this.arg2 = arg2; 337 } 338 339 348 public String getArg3() { 349 return arg3; 350 } 351 352 357 public void setArg3(String arg3) { 358 this.arg3 = arg3; 359 } 360 361 362 371 public String getArg4() { 372 return arg4; 373 } 374 375 380 public void setArg4(String arg4) { 381 this.arg4 = arg4; 382 } 383 384 389 public void doTag() throws JspException { 390 391 PageContext pageContext = (PageContext ) getJspContext(); 392 HttpServletRequest request = (HttpServletRequest ) pageContext.getRequest(); 393 394 if ( ignore == null ) { 395 ignore = Boolean.FALSE; 396 } 397 398 if ( filter == null ) { 399 filter = Boolean.FALSE; 400 } 401 402 Locale locale = null; 403 if ( language != null ) { 404 locale = new Locale (language); 405 } else { 406 locale = RequestUtils.getUserLocale(request, null); 407 if ( locale == null ) { 408 locale = Locale.getDefault(); 409 } 410 } 411 412 Object [] args = null; 413 if ( arg0 != null || arg1 != null || arg2 != null || arg3 != null || arg4 != null ) { 414 args = new Object []{arg0, arg1, arg2, arg3, arg4}; 415 } 416 417 String message = ApplicationResources.getInstance(pageContext.getServletContext()).getMessage(locale, key, args); 418 419 if ( message == null ) { 420 if ( !ignore.booleanValue() ) { 421 JspException e = new JspException ("No message for key '" + key + "' could be found"); 422 throw e; 423 } else { 424 if ( log.isDebugEnabled() ) { 425 log.debug("No message for key '" + key + "' could be found. Ignored"); 426 } 427 } 428 } else if ( message.length() == 0 ) { 429 if ( log.isDebugEnabled() ) { 430 log.debug("Value for key '" + key + "' is empty string"); 431 } 432 } 433 434 TagUtils tagUtils = TagUtils.getInstance(); 435 if ( var != null ) { 436 int varScope = PageContext.PAGE_SCOPE; 438 if ( scope != null ) { 439 varScope = tagUtils.getScope(scope); 440 } 441 pageContext.setAttribute(var, message, varScope); 442 443 } else { 444 445 if ( filter.booleanValue() ) { 447 message = StringUtil.htmlEncode(message); 448 } 449 450 tagUtils.write(pageContext, message); 452 } 453 454 } 455 } 456 | Popular Tags |