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.jstl.ParamContainerTag; 34 35 import javax.el.ELContext; 36 import javax.servlet.jsp.JspException ; 37 import javax.servlet.jsp.JspWriter ; 38 import javax.servlet.jsp.jstl.fmt.LocalizationContext; 39 import javax.servlet.jsp.tagext.BodyTagSupport ; 40 import java.util.ArrayList ; 41 42 45 public class MessageTag extends BodyTagSupport implements ParamContainerTag { 46 private Expr _keyExpr; 47 private Expr _bundleExpr; 48 49 private ArrayList <Object > _params; 50 51 private String _var; 52 private String _scope; 53 54 59 public void setKey(Expr key) 60 { 61 _keyExpr = key; 62 } 63 64 69 public void setBundle(Expr bundle) 70 { 71 _bundleExpr = bundle; 72 } 73 74 79 public void setVar(String var) 80 { 81 _var = var; 82 } 83 84 89 public void setScope(String scope) 90 { 91 _scope = scope; 92 } 93 94 97 public void addParam(Object value) 98 { 99 if (_params == null) 100 _params = new ArrayList <Object >(); 101 102 _params.add(value); 103 } 104 105 108 public int doEndTag() 109 throws JspException 110 { 111 Object []args = null; 112 113 if (_params != null) { 114 args = _params.toArray(new Object [_params.size()]); 115 _params = null; 116 } 117 118 try { 119 PageContextImpl pageContext = (PageContextImpl) this.pageContext; 120 ELContext env = pageContext.getELContext(); 121 122 JspWriter out = pageContext.getOut(); 123 124 String key; 125 126 if (_keyExpr != null) 127 key = _keyExpr.evalString(env); 128 else 129 key = getBodyContent().getString().trim(); 130 131 String msg; 132 133 if (_bundleExpr != null) { 134 Object bundleObject = _bundleExpr.evalObject(env); 135 136 msg = pageContext.getLocalizedMessage(bundleObject, key, args, null); 137 } 138 else { 139 LocalizationContext lc; 140 lc = (LocalizationContext) pageContext.getAttribute("caucho.bundle"); 141 142 if (lc == null) 143 msg = pageContext.getLocalizedMessage(key, args, null); 144 else 145 msg = pageContext.getLocalizedMessage(lc, key, args, null); 146 } 147 148 if (_var != null) 149 CoreSetTag.setValue(pageContext, _var, _scope, msg); 150 else 151 out.print(msg); 152 } catch (Exception e) { 153 throw new JspException (e); 154 } 155 156 return EVAL_PAGE; 157 } 158 } 159 | Popular Tags |