1 28 package net.sf.jasperreports.engine.util; 29 30 import java.util.Locale ; 31 import java.util.TimeZone ; 32 33 34 38 public class JRDataUtils 39 { 40 41 42 public static String getLocaleCode(Locale locale) 43 { 44 return locale.toString(); 45 } 46 47 48 public static Locale getLocale(String code) 49 { 50 String language; 51 String country; 52 String variant; 53 54 int firstSep = code.indexOf('_'); 55 if (firstSep < 0) { 56 language = code; 57 country = variant = ""; 58 } else { 59 language = code.substring(0, firstSep); 60 61 int secondSep = code.indexOf('_', firstSep + 1); 62 if (secondSep < 0) { 63 country = code.substring(firstSep + 1); 64 variant = ""; 65 } else { 66 country = code.substring(firstSep + 1, secondSep); 67 variant = code.substring(secondSep + 1); 68 } 69 } 70 71 return new Locale (language, country, variant); 72 } 73 74 75 public static String getTimeZoneId(TimeZone tz) 76 { 77 return tz.getID(); 78 } 79 80 81 public static TimeZone getTimeZone(String id) 82 { 83 return TimeZone.getTimeZone(id); 84 } 85 86 } 87 | Popular Tags |