1 28 29 package com.caucho.jstl.rt; 30 31 import com.caucho.jsp.PageContextImpl; 32 import com.caucho.jstl.ParamContainerTag; 33 34 import javax.servlet.jsp.JspException ; 35 import javax.servlet.jsp.JspWriter ; 36 import javax.servlet.jsp.jstl.fmt.LocalizationContext; 37 import javax.servlet.jsp.tagext.BodyTagSupport ; 38 import java.io.IOException ; 39 import java.util.ArrayList ; 40 41 44 public class MessageTag extends BodyTagSupport implements ParamContainerTag { 45 private String _key; 46 private Object _bundle; 47 48 private ArrayList <Object > _params; 49 50 private String _var; 51 private String _scope; 52 53 58 public void setKey(String key) 59 { 60 _key = key; 61 } 62 63 68 public void setBundle(Object bundle) 69 { 70 _bundle = bundle; 71 } 72 73 78 public void setVar(String var) 79 { 80 _var = var; 81 } 82 83 88 public void setScope(String scope) 89 { 90 _scope = scope; 91 } 92 93 96 public void addParam(Object value) 97 { 98 if (_params == null) 99 _params = new ArrayList <Object >(); 100 101 _params.add(value); 102 } 103 104 107 public int doEndTag() 108 throws JspException 109 { 110 Object []args = null; 111 112 if (_params != null) { 113 args = _params.toArray(new Object [_params.size()]); 114 _params = null; 115 } 116 117 try { 118 PageContextImpl pc = (PageContextImpl) pageContext; 119 120 JspWriter out = pc.getOut(); 121 122 String key = _key; 123 124 if (_key != null) 125 key = _key; 126 else 127 key = getBodyContent().getString().trim(); 128 129 String msg; 130 131 if (_bundle != null) { 132 msg = pc.getLocalizedMessage(_bundle, key, args, null); 133 } 134 else { 135 LocalizationContext lc; 136 lc = (LocalizationContext) pageContext.getAttribute("caucho.bundle"); 137 138 if (lc == null) 139 msg = pc.getLocalizedMessage(key, args, null); 140 else 141 msg = pc.getLocalizedMessage(lc, key, args, null); 142 } 143 144 if (_var != null) 145 CoreSetTag.setValue(pc, _var, _scope, msg); 146 else 147 out.print(msg); 148 } catch (IOException e) { 149 } 150 151 return EVAL_PAGE; 152 } 153 } 154 | Popular Tags |