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.servlet.jsp.JspException ; 36 import javax.servlet.jsp.jstl.fmt.LocalizationContext; 37 import javax.servlet.jsp.tagext.TagSupport ; 38 import javax.servlet.jsp.tagext.TryCatchFinally ; 39 40 43 public class BundleTag extends TagSupport implements TryCatchFinally { 44 private static L10N L = new L10N(BundleTag.class); 45 46 private Expr _basenameExpr; 47 private Expr _prefixExpr; 48 49 private Object _oldBundle; 50 private Object _oldPrefix; 51 52 55 public void setBasename(Expr basename) 56 { 57 _basenameExpr = basename; 58 } 59 60 63 public void setPrefix(Expr prefix) 64 { 65 _prefixExpr = prefix; 66 } 67 68 71 public int doStartTag() 72 throws JspException 73 { 74 PageContextImpl pc = (PageContextImpl) pageContext; 75 76 String basename = _basenameExpr.evalString(pc.getELContext()); 77 78 _oldBundle = pc.getAttribute("caucho.bundle"); 79 _oldPrefix = pc.getAttribute("caucho.bundle.prefix"); 80 81 LocalizationContext bundle = pc.getBundle(basename); 82 83 pc.setAttribute("caucho.bundle", bundle); 84 85 if (_prefixExpr != null) { 86 String prefix = _prefixExpr.evalString(pc.getELContext()); 87 88 pc.setAttribute("caucho.bundle.prefix", prefix); 89 } 90 else if (_oldPrefix != null) 91 pc.removeAttribute("caucho.bundle.prefix"); 92 93 return EVAL_BODY_INCLUDE; 94 } 95 96 99 public void doCatch(Throwable t) 100 throws Throwable 101 { 102 throw t; 103 } 104 105 108 public void doFinally() 109 { 110 if (_oldBundle == null) 111 pageContext.removeAttribute("caucho.bundle"); 112 else 113 pageContext.setAttribute("caucho.bundle", _oldBundle); 114 115 if (_oldPrefix == null) 116 pageContext.removeAttribute("caucho.bundle.prefix"); 117 else 118 pageContext.setAttribute("caucho.bundle.prefix", _oldPrefix); 119 } 120 121 public static Object setBundle(String baseName, PageContextImpl pc) 122 { 123 Object oldBundle = pc.getAttribute("caucho.bundle"); 124 125 LocalizationContext bundle = pc.getBundle(baseName); 126 127 pc.setAttribute("caucho.bundle", bundle); 128 129 return oldBundle; 130 } 131 } 132 | Popular Tags |