1 7 package com.ibm.icu.util; 8 9 import java.util.*; 10 11 62 public class OverlayBundle extends ResourceBundle { 65 66 70 private String [] baseNames; 71 72 75 private Locale locale; 76 77 81 private ResourceBundle[] bundles; 82 83 89 public OverlayBundle(String [] baseNames, 90 Locale locale) { 91 this.baseNames = baseNames; 92 this.locale = locale; 93 bundles = new ResourceBundle[baseNames.length]; 94 } 95 96 102 protected Object handleGetObject(String key) 103 throws MissingResourceException { 104 105 Object o = null; 106 107 for (int i=0; i<bundles.length; ++i) { 108 load(i); 109 try { 110 o = bundles[i].getObject(key); 111 } catch (MissingResourceException e) { 112 if (i == bundles.length-1) { 113 throw e; 114 } 115 } 116 if (o != null) { 117 break; 118 } 119 } 120 121 return o; 122 } 123 124 130 public Enumeration getKeys() { 131 int i = bundles.length - 1; 134 load(i); 135 return bundles[i].getKeys(); 136 } 137 138 141 private void load(int i) 142 throws MissingResourceException { 143 144 if (bundles[i] == null) { 145 boolean tryWildcard = false; 146 try { 147 bundles[i] = ResourceBundle.getBundle(baseNames[i], locale); 148 if (bundles[i].getLocale().equals(locale)) { 149 return; 150 } 151 if (locale.getCountry().length() != 0 && i != bundles.length-1) { 152 tryWildcard = true; 153 } 154 } catch (MissingResourceException e) { 155 if (i == bundles.length-1) { 156 throw e; 157 } 158 tryWildcard = true; 159 } 160 if (tryWildcard) { 161 Locale wildcard = new Locale("xx", locale.getCountry(), 162 locale.getVariant()); 163 try { 164 bundles[i] = ResourceBundle.getBundle(baseNames[i], wildcard); 165 } catch (MissingResourceException e) { 166 if (bundles[i] == null) { 167 throw e; 168 } 169 } 170 } 171 } 172 } 173 } 174 | Popular Tags |