1 14 package org.wings.util; 15 16 import org.apache.commons.logging.Log; 17 import org.apache.commons.logging.LogFactory; 18 19 import java.io.InputStream ; 20 import java.util.Locale ; 21 import java.util.Properties ; 22 23 28 public class LocaleCharSet { 29 32 public final static String DEFAULT_ENCODING = "ISO-8859-1"; 33 private static LocaleCharSet fInstance = null; 34 private final transient static Log log = LogFactory.getLog(LocaleCharSet.class); 35 private Properties fCharSet; 36 private final static String CHARSET_PROPERTIES = "org/wings/util/charset.properties"; 37 38 protected LocaleCharSet() { 39 fCharSet = new Properties (); 40 try { 41 InputStream in = this.getClass().getClassLoader().getResourceAsStream(CHARSET_PROPERTIES); 42 fCharSet.load(in); 43 in.close(); 44 } catch (Exception e) { 45 log.warn("Unexpected error on loading " + CHARSET_PROPERTIES + " via class path.", e); 46 } 47 } 48 49 54 public static LocaleCharSet getInstance() { 55 if (fInstance == null) { 56 fInstance = new LocaleCharSet(); 57 } 58 return fInstance; 59 } 60 61 67 public String getCharSet(Locale aLocale) { 68 String cs = null; 69 if (aLocale == null) { 70 return DEFAULT_ENCODING; 71 } 72 73 cs = fCharSet.getProperty(aLocale.getCountry() + "_" + aLocale.getLanguage()); 74 75 if (cs == null) { 76 cs = fCharSet.getProperty(aLocale.getCountry()); 77 } 78 79 if (cs == null) { 80 cs = fCharSet.getProperty(aLocale.getLanguage()); 81 } 82 83 return cs != null ? cs : DEFAULT_ENCODING; 84 } 85 } | Popular Tags |