1 5 package com.opensymphony.webwork.views.jsp; 6 7 import com.opensymphony.xwork.ActionContext; 8 import com.opensymphony.xwork.LocaleProvider; 9 import com.opensymphony.xwork.TextProviderSupport; 10 import com.opensymphony.xwork.util.LocalizedTextUtil; 11 import org.apache.commons.logging.LogFactory; 12 13 import javax.servlet.jsp.JspException ; 14 import java.util.Locale ; 15 import java.util.ResourceBundle ; 16 17 18 26 public class I18nTag extends WebWorkTagSupport { 27 29 protected String nameAttr; 31 32 34 public void setName(String aName) { 36 nameAttr = aName; 37 } 38 39 public int doEndTag() throws JspException { 40 getStack().pop(); 41 42 return EVAL_PAGE; 43 } 44 45 public int doStartTag() throws JspException { 47 try { 49 String name = this.findString(nameAttr); 50 ResourceBundle bundle = (ResourceBundle ) findValue("texts('" + name + "')"); 51 52 if (bundle == null) { 53 bundle = LocalizedTextUtil.findResourceBundle(name, (Locale ) getStack().getContext().get(ActionContext.LOCALE)); 54 } 55 56 if (bundle != null) { 57 final Locale locale = (Locale ) getStack().getContext().get(ActionContext.LOCALE); 58 getStack().push(new TextProviderSupport(bundle, new LocaleProvider() { 59 public Locale getLocale() { 60 return locale; 61 } 62 })); 63 } 64 } catch (Exception e) { 65 LogFactory.getLog(getClass()).error("Could not find the bundle " + nameAttr, e); 66 throw new JspException ("Could not find the bundle " + nameAttr); 67 } 68 69 return EVAL_BODY_INCLUDE; 70 } 71 } 72 | Popular Tags |