1 28 29 package com.caucho.jstl.el; 30 31 import com.caucho.el.Expr; 32 import com.caucho.jsp.PageContextImpl; 33 import com.caucho.util.L10N; 34 35 import javax.el.ELContext; 36 import javax.el.ELException; 37 import javax.servlet.jsp.JspException ; 38 import javax.servlet.jsp.jstl.core.Config; 39 import javax.servlet.jsp.tagext.TagSupport ; 40 import java.util.Locale ; 41 42 45 public class SetLocaleTag extends TagSupport { 46 private static L10N L = new L10N(SetBundleTag.class); 47 48 private Expr _valueExpr; 49 private Expr _variantExpr; 50 private String _scope; 51 52 55 public void setValue(Expr value) 56 { 57 _valueExpr = value; 58 } 59 60 63 public void setVariant(Expr variant) 64 { 65 _variantExpr = variant; 66 } 67 68 71 public void setScope(String scope) 72 { 73 _scope = scope; 74 } 75 76 79 public int doStartTag() 80 throws JspException 81 { 82 try { 83 PageContextImpl pageContext = (PageContextImpl) this.pageContext; 84 ELContext env = pageContext.getELContext(); 85 86 Object valueObj = _valueExpr.evalObject(env); 87 Locale locale = null; 88 89 if (valueObj instanceof Locale ) { 90 locale = (Locale ) valueObj; 91 } 92 else if (valueObj instanceof String ) { 93 String variant = null; 94 95 if (_variantExpr != null) 96 variant = _variantExpr.evalString(env); 97 98 locale = pageContext.getLocale((String ) valueObj, variant); 99 } 100 101 CoreSetTag.setValue(pageContext, Config.FMT_LOCALE, _scope, locale); 102 103 return SKIP_BODY; 104 } catch (ELException e) { 105 throw new JspException (e); 106 } 107 } 108 } 109 | Popular Tags |