1 18 package org.apache.roller.ui.core.util; 19 20 import java.util.ArrayList ; 21 import java.util.Date ; 22 import java.util.List ; 23 import java.util.Locale ; 24 import java.util.TimeZone ; 25 import java.util.TreeSet ; 26 27 import org.apache.struts.util.LabelValueBean; 28 import org.apache.roller.util.LocaleComparator; 29 import org.apache.roller.util.TimeZoneComparator; 30 31 public class StrutsUtil 32 { 33 public static ArrayList locales; 34 public static ArrayList timeZones; 35 36 48 public static List getLocaleBeans() 49 { 50 if (locales == null) 51 { 52 locales = new ArrayList (); 53 TreeSet locTree = new TreeSet (new LocaleComparator()); 54 Locale [] localeArray = Locale.getAvailableLocales(); 55 for (int i=0; i<localeArray.length; i++) 56 { 57 locTree.add(localeArray[i]); 58 } 59 java.util.Iterator it = locTree.iterator(); 60 while (it.hasNext()) 61 { 62 Locale loc = (Locale )it.next(); 63 locales.add(new LabelValueBean( 64 loc.getDisplayName(), 65 loc.toString())); 66 } 67 68 } 69 return locales; 70 } 71 72 78 public static List getTimeZoneBeans() 79 { 80 if (timeZones == null) 81 { 82 Date today = new Date (); 83 timeZones = new ArrayList (); 84 TreeSet zoneTree = new TreeSet (new TimeZoneComparator()); 85 String [] zoneArray = TimeZone.getAvailableIDs(); 86 for (int i=0; i<zoneArray.length; i++) 87 { 88 zoneTree.add((TimeZone )TimeZone.getTimeZone(zoneArray[i])); 89 } 90 java.util.Iterator it = zoneTree.iterator(); 91 while (it.hasNext()) 92 { 93 StringBuffer sb = new StringBuffer (); 94 TimeZone zone = (TimeZone )it.next(); 95 sb.append(zone.getDisplayName(zone.inDaylightTime(today), TimeZone.SHORT)); 96 sb.append(" - "); 97 sb.append(zone.getID()); 98 timeZones.add(new LabelValueBean( 99 sb.toString(), 100 zone.getID())); 101 } 102 } 103 return timeZones; 104 } 105 } 106 | Popular Tags |