1 16 17 package org.apache.cocoon.taglib.datetime; 18 19 import java.text.DateFormatSymbols ; 20 import java.util.Locale ; 21 22 import org.apache.cocoon.taglib.IterationTag; 23 import org.apache.cocoon.taglib.TagSupport; 24 import org.apache.cocoon.taglib.VarTagSupport; 25 import org.apache.cocoon.taglib.i18n.LocaleTag; 26 import org.xml.sax.Attributes ; 27 import org.xml.sax.SAXException ; 28 29 38 public class MonthsTag extends VarTagSupport implements IterationTag { 39 private String [] short_months = null; 40 private String [] long_months = null; 41 private int month; 42 private int month_num; 43 44 49 public final int doStartTag(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 50 month = 0; 52 month_num = 1; 53 54 Locale locale = null; 55 LocaleTag localeTag = (LocaleTag) TagSupport.findAncestorWithClass(this, LocaleTag.class); 56 if (localeTag != null) { 57 locale = localeTag.getLocale(); 58 } else { 59 locale = Locale.getDefault(); 60 } 61 62 DateFormatSymbols dfs = new DateFormatSymbols (locale); 63 short_months = dfs.getShortMonths(); 64 long_months = dfs.getMonths(); 65 66 while (month < long_months.length && (long_months[month] == null || long_months[month].length() == 0)) { 68 month++; 69 } 70 71 if (month >= short_months.length) 72 return SKIP_BODY; 73 74 setVariable(var, this); 75 return EVAL_BODY; 76 } 77 78 81 public int doEndTag(String namespaceURI, String localName, String qName) throws SAXException { 82 removeVariable(var); 83 return EVAL_PAGE; 84 } 85 86 91 public final int doAfterBody() throws SAXException { 92 month++; 94 month_num++; 95 if (month >= short_months.length) 96 return SKIP_BODY; 97 98 while (month < long_months.length && (long_months[month] == null || long_months[month].length() == 0)) { 100 month++; 101 } 102 103 if (month >= short_months.length) 104 return SKIP_BODY; 105 106 return EVAL_BODY_AGAIN; 108 } 109 110 115 public final String getShortMonth() { 116 return short_months[month]; 117 } 118 119 124 public final String getMonth() { 125 return long_months[month]; 126 } 127 128 133 public final String getMonthOfYear() { 134 if (month_num < 10) 135 return "0" + month_num; 136 return "" + month_num; 137 } 138 139 142 public void recycle() { 143 this.short_months = null; 144 this.long_months = null; 145 super.recycle(); 146 } 147 148 } 149 | Popular Tags |