1 28 29 package com.caucho.jstl.rt; 30 31 import com.caucho.jsp.PageContextImpl; 32 import com.caucho.util.L10N; 33 34 import javax.servlet.jsp.JspException ; 35 import javax.servlet.jsp.jstl.fmt.LocalizationContext; 36 import javax.servlet.jsp.tagext.TagSupport ; 37 import javax.servlet.jsp.tagext.TryCatchFinally ; 38 39 42 public class BundleTag extends TagSupport implements TryCatchFinally { 43 private static L10N L = new L10N(BundleTag.class); 44 45 private String _basename; 46 private String _prefix; 47 48 private Object _oldBundle; 49 private Object _oldPrefix; 50 51 54 public void setBasename(String basename) 55 { 56 _basename = basename; 57 } 58 59 62 public void setPrefix(String prefix) 63 { 64 _prefix = prefix; 65 } 66 67 70 public int doStartTag() 71 throws JspException 72 { 73 PageContextImpl pc = (PageContextImpl) pageContext; 74 75 _oldBundle = pc.getAttribute("caucho.bundle"); 76 _oldPrefix = pc.getAttribute("caucho.bundle.prefix"); 77 78 LocalizationContext bundle = pc.getBundle(_basename); 79 80 pc.setAttribute("caucho.bundle", bundle); 81 82 if (_prefix != null) 83 pc.setAttribute("caucho.bundle.prefix", _prefix); 84 else if (_oldPrefix != null) 85 pc.removeAttribute("caucho.bundle.prefix"); 86 87 return EVAL_BODY_INCLUDE; 88 } 89 90 93 public void doCatch(Throwable t) 94 throws Throwable 95 { 96 throw t; 97 } 98 99 102 public void doFinally() 103 { 104 if (_oldBundle == null) 105 pageContext.removeAttribute("caucho.bundle"); 106 else 107 pageContext.setAttribute("caucho.bundle", _oldBundle); 108 109 if (_oldPrefix == null) 110 pageContext.removeAttribute("caucho.bundle.prefix"); 111 else 112 pageContext.setAttribute("caucho.bundle.prefix", _oldPrefix); 113 } 114 115 public static Object setBundle(String baseName, PageContextImpl pc) 116 { 117 Object oldBundle = pc.getAttribute("caucho.bundle"); 118 119 LocalizationContext bundle = pc.getBundle(baseName); 120 121 pc.setAttribute("caucho.bundle", bundle); 122 123 return oldBundle; 124 } 125 } 126 | Popular Tags |