1 16 17 package org.apache.taglibs.datetime; 18 19 import java.util.*; 20 import java.text.*; 21 import javax.servlet.*; 22 import javax.servlet.http.*; 23 import javax.servlet.jsp.*; 24 import javax.servlet.jsp.tagext.*; 25 26 69 70 public class WeekdaysTag extends BodyTagSupport 71 { 72 private static String PATTERN = "yyyy"; 74 75 private boolean locale_flag = false; 77 private String localeRef = null; 78 79 private String [] short_weekdays = null; 80 private String [] long_weekdays = null; 81 private int day = 0; 82 private int day_num = 1; 83 84 89 public final int doStartTag() throws JspException 90 { 91 day = 0; 93 day_num = 1; 94 95 SimpleDateFormat sdf; 96 if( localeRef != null ) { 97 Locale locale = (Locale)pageContext.findAttribute(localeRef); 98 if( locale == null ) { 99 throw new JspException( 100 "datetime amPms tag could not find locale for localeRef \"" + 101 localeRef + "\"."); 102 } 103 104 sdf = new SimpleDateFormat(PATTERN,locale); 105 } else if( locale_flag ) { 106 sdf = new SimpleDateFormat(PATTERN, 107 (Locale)pageContext.getRequest().getLocale()); 108 } else { 109 sdf = new SimpleDateFormat(PATTERN); 110 } 111 112 DateFormatSymbols dfs = sdf.getDateFormatSymbols(); 113 short_weekdays = dfs.getShortWeekdays(); 114 long_weekdays = dfs.getWeekdays(); 115 while( day < long_weekdays.length && 117 (long_weekdays[day] == null || long_weekdays[day].length() == 0) ) 118 day++; 119 if( day >= short_weekdays.length ) 120 return SKIP_BODY; 121 122 pageContext.setAttribute(id,this,PageContext.PAGE_SCOPE); 123 return EVAL_BODY_TAG; 124 } 125 126 131 public final int doAfterBody() throws JspException 132 { 133 day++; 135 day_num++; 136 if( day >= short_weekdays.length ) 137 return SKIP_BODY; 138 while( day < long_weekdays.length && 140 (long_weekdays[day] == null || long_weekdays[day].length() == 0) ) 141 day++; 142 143 if( day >= short_weekdays.length ) 144 return SKIP_BODY; 145 146 return EVAL_BODY_TAG; 148 } 149 150 154 public final int doEndTag() throws JspException 155 { 156 pageContext.removeAttribute(id,PageContext.PAGE_SCOPE); 157 try 158 { 159 if(bodyContent != null) 160 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 161 } catch(java.io.IOException e) 162 { 163 throw new JspException("IO Error: " + e.getMessage()); 164 } 165 return EVAL_PAGE; 166 } 167 168 174 public final void setLocale(boolean flag) 175 { 176 locale_flag = flag; 177 } 178 179 185 public void setLocaleRef(String value) 186 { 187 localeRef = value; 188 } 189 190 197 public final String getShortWeekday() 198 { 199 return short_weekdays[day]; 200 } 201 202 209 public final String getWeekday() 210 { 211 return long_weekdays[day]; 212 } 213 214 221 public final String getDayOfWeek() 222 { 223 return "" + day_num; 224 } 225 226 } 227 | Popular Tags |