1 25 26 package com.j2biz.blogunity.web.taglibs; 27 28 import java.io.IOException ; 29 import java.util.Locale ; 30 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.jsp.JspException ; 33 import javax.servlet.jsp.tagext.TagSupport ; 34 35 import org.apache.commons.lang.StringUtils; 36 37 import com.j2biz.blogunity.IConstants; 38 import com.j2biz.blogunity.exception.BlogunityRuntimeException; 39 import com.j2biz.blogunity.i18n.I18N; 40 import com.j2biz.blogunity.i18n.I18NMessageManager; 41 import com.j2biz.blogunity.i18n.I18NStatusFactory; 42 43 public class I18NTag extends TagSupport { 44 45 48 private static final long serialVersionUID = 3257001073016387897L; 49 50 private String key; 51 52 private String params; 53 54 59 public int doStartTag() throws JspException { 60 61 HttpServletRequest request = (HttpServletRequest ) pageContext.getRequest(); 62 Locale currentLocale = (Locale ) request.getAttribute(IConstants.Request.LOCALE); 63 64 String [] _params = new String []{}; 65 if (StringUtils.isNotEmpty(params)) { 66 _params = (String []) request.getAttribute(params); 67 } 68 69 String msg = I18NMessageManager.getInstance().getMessage(getKey(), _params, currentLocale); 70 71 try { 72 pageContext.getOut().print(msg); 73 } catch (IOException e) { 74 throw new BlogunityRuntimeException(I18NStatusFactory.create( 75 I18N.ERRORS.TAGLIB_RENDERING, e)); 76 } 77 78 return SKIP_BODY; 79 } 80 81 86 public int doEndTag() throws JspException { 87 return EVAL_PAGE; 88 } 89 90 public String getKey() { 91 return key; 92 } 93 94 public void setKey(String key) { 95 this.key = key; 96 } 97 98 public String getParams() { 99 return params; 100 } 101 102 public void setParams(String params) { 103 this.params = params; 104 } 105 } | Popular Tags |