1 7 8 package javax.accessibility; 9 10 import java.util.Enumeration ; 11 import java.util.Hashtable ; 12 import java.util.Vector ; 13 import java.util.Locale ; 14 import java.util.MissingResourceException ; 15 import java.util.ResourceBundle ; 16 17 33 public abstract class AccessibleBundle { 34 35 private static Hashtable table = new Hashtable (); 36 private final String defaultResourceBundleName 37 = "com.sun.accessibility.internal.resources.accessibility"; 38 39 public AccessibleBundle() { 40 } 41 42 47 protected String key = null; 48 49 61 protected String toDisplayString(String resourceBundleName, 62 Locale locale) { 63 64 loadResourceBundle(resourceBundleName, locale); 66 67 Object o = table.get(locale); 69 if (o != null && o instanceof Hashtable ) { 70 Hashtable resourceTable = (Hashtable ) o; 71 o = resourceTable.get(key); 72 73 if (o != null && o instanceof String ) { 74 return (String )o; 75 } 76 } 77 return key; 78 } 79 80 88 public String toDisplayString(Locale locale) { 89 return toDisplayString(defaultResourceBundleName, locale); 90 } 91 92 96 public String toDisplayString() { 97 return toDisplayString(Locale.getDefault()); 98 } 99 100 105 public String toString() { 106 return toDisplayString(); 107 } 108 109 112 private void loadResourceBundle(String resourceBundleName, 113 Locale locale) { 114 if (! table.contains(locale)) { 115 116 try { 117 Hashtable resourceTable = new Hashtable (); 118 119 ResourceBundle bundle = ResourceBundle.getBundle(resourceBundleName, locale); 120 121 Enumeration iter = bundle.getKeys(); 122 while(iter.hasMoreElements()) { 123 String key = (String )iter.nextElement(); 124 resourceTable.put(key, bundle.getObject(key)); 125 } 126 127 table.put(locale, resourceTable); 128 } 129 catch (MissingResourceException e) { 130 System.err.println("loadResourceBundle: " + e); 131 return; 134 } 135 } 136 } 137 138 } 139 | Popular Tags |