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.tagext.TagSupport ; 37 import javax.servlet.jsp.tagext.TryCatchFinally ; 38 import java.util.TimeZone ; 39 40 43 public class FmtTimeZoneTag extends TagSupport implements TryCatchFinally { 44 private static L10N L = new L10N(FmtTimeZoneTag.class); 45 46 private Expr _valueExpr; 47 48 private Object _oldTimeZone; 49 50 53 public void setValue(Expr value) 54 { 55 _valueExpr = value; 56 } 57 58 61 public int doStartTag() 62 throws JspException 63 { 64 try { 65 PageContextImpl pc = (PageContextImpl) pageContext; 66 67 _oldTimeZone = pc.getAttribute("com.caucho.time-zone"); 68 69 Object valueObj = _valueExpr.evalObject(pc.getELContext()); 70 TimeZone timeZone = null; 71 72 if (valueObj instanceof TimeZone ) { 73 timeZone = (TimeZone ) valueObj; 74 } 75 else if (valueObj instanceof String ) { 76 String string = (String ) valueObj; 77 string = string.trim(); 78 79 if (string.equals("")) 80 timeZone = TimeZone.getTimeZone("GMT"); 81 else 82 timeZone = TimeZone.getTimeZone(string); 83 } 84 else 85 timeZone = TimeZone.getTimeZone("GMT"); 86 87 pc.setAttribute("com.caucho.time-zone", timeZone); 88 89 return EVAL_BODY_INCLUDE; 90 } catch (Exception e) { 91 throw new JspException (e); 92 } 93 } 94 95 98 public void doCatch(Throwable t) 99 throws Throwable 100 { 101 throw t; 102 } 103 104 107 public void doFinally() 108 { 109 if (_oldTimeZone == null) 110 pageContext.removeAttribute("com.caucho.time-zone"); 111 else 112 pageContext.setAttribute("com.caucho.time-zone", _oldTimeZone); 113 } 114 } 115 | Popular Tags |