1 16 17 package org.apache.taglibs.standard.tag.common.fmt; 18 19 import java.io.IOException ; 20 import java.util.TimeZone ; 21 22 import javax.servlet.jsp.JspException ; 23 import javax.servlet.jsp.JspTagException ; 24 import javax.servlet.jsp.PageContext ; 25 import javax.servlet.jsp.jstl.core.Config; 26 import javax.servlet.jsp.tagext.BodyTagSupport ; 27 import javax.servlet.jsp.tagext.Tag ; 28 29 35 36 public abstract class TimeZoneSupport extends BodyTagSupport { 37 38 39 42 protected Object value; 44 45 48 private TimeZone timeZone; 49 50 51 54 public TimeZoneSupport() { 55 super(); 56 init(); 57 } 58 59 private void init() { 60 value = null; 61 } 62 63 64 67 public TimeZone getTimeZone() { 68 return timeZone; 69 } 70 71 72 75 public int doStartTag() throws JspException { 76 77 if (value == null) { 78 timeZone = TimeZone.getTimeZone("GMT"); 79 } else if (value instanceof String ) { 80 if (((String ) value).trim().equals("")) { 81 timeZone = TimeZone.getTimeZone("GMT"); 82 } else { 83 timeZone = TimeZone.getTimeZone((String ) value); 84 } 85 } else { 86 timeZone = (TimeZone ) value; 87 } 88 89 return EVAL_BODY_BUFFERED; 90 } 91 92 public int doEndTag() throws JspException { 93 try { 94 pageContext.getOut().print(bodyContent.getString()); 95 } catch (IOException ioe) { 96 throw new JspTagException (ioe.toString(), ioe); 97 } 98 99 return EVAL_PAGE; 100 } 101 102 public void release() { 104 init(); 105 } 106 107 108 111 130 static TimeZone getTimeZone(PageContext pc, Tag fromTag) { 131 TimeZone tz = null; 132 133 Tag t = findAncestorWithClass(fromTag, TimeZoneSupport.class); 134 if (t != null) { 135 TimeZoneSupport parent = (TimeZoneSupport) t; 137 tz = parent.getTimeZone(); 138 } else { 139 Object obj = Config.find(pc, Config.FMT_TIME_ZONE); 141 if (obj != null) { 142 if (obj instanceof TimeZone ) { 143 tz = (TimeZone ) obj; 144 } else { 145 tz = TimeZone.getTimeZone((String ) obj); 146 } 147 } 148 } 149 150 return tz; 151 } 152 } 153 | Popular Tags |