1 11 package com.sun.xml.fastinfoset; 12 13 import java.text.MessageFormat ; 14 import java.util.Enumeration ; 15 import java.util.Locale ; 16 import java.util.ResourceBundle ; 17 18 19 24 public abstract class AbstractResourceBundle extends ResourceBundle { 25 26 public static final String LOCALE = "com.sun.xml.fastinfoset.locale"; 27 static String _bundleName = null; 28 29 public static String getBundleName() { 30 return _bundleName; 31 } 32 public void setBundleName(String name) { 33 _bundleName = name; 34 } 35 42 public String getString(String key, Object args[]) { 43 String pattern = getBundle().getString(key); 44 return MessageFormat.format(pattern, args); 45 } 46 47 55 public String getString(String key, Object args[], Locale locale) { 56 String pattern = null; 57 if (locale == null) { 58 pattern = getBundle().getString(key); 59 } else { 60 pattern = getBundle(_bundleName, locale).getString(key); 61 } 62 return MessageFormat.format(pattern, args); 63 } 64 65 72 public static Locale parseLocale(String localeString) { 73 Locale locale = null; 74 if (localeString == null) { 75 locale = Locale.getDefault(); 76 } else { 77 try { 78 String [] args = localeString.split("_"); 79 if (args.length == 1) { 80 locale = new Locale (args[0]); 81 } else if (args.length == 2) { 82 locale = new Locale (args[0], args[1]); 83 } else if (args.length == 3) { 84 locale = new Locale (args[0], args[1], args[2]); 85 } 86 } catch (Throwable t) { 87 locale = Locale.getDefault(); 88 } 89 } 90 return locale; 91 } 92 93 101 public abstract ResourceBundle getBundle(); 102 103 104 116 protected Object handleGetObject(String key) { 117 return getBundle().getObject(key); 118 } 119 120 129 public final Enumeration getKeys() { 130 return getBundle().getKeys(); 131 } 132 } 133 | Popular Tags |