1 7 package com.ibm.icu.util; 8 9 import java.util.MissingResourceException ; 10 11 import com.ibm.icu.impl.ICUResourceBundle; 12 import com.ibm.icu.text.UnicodeSet; 13 14 19 public final class LocaleData { 20 21 private static final String EXEMPLAR_CHARS = "ExemplarCharacters"; 22 private static final String MEASUREMENT_SYSTEM = "MeasurementSystem"; 23 private static final String PAPER_SIZE = "PaperSize"; 24 private boolean noSubstitute; 25 private ICUResourceBundle bundle; 26 27 32 public static final int ES_STANDARD = 0; 33 34 39 public static final int ES_AUXILIARY = 1; 40 41 46 public static final int ES_COUNT = 2; 47 48 53 public static final int QUOTATION_START = 0; 54 55 60 public static final int QUOTATION_END = 1; 61 62 67 public static final int ALT_QUOTATION_START = 2; 68 69 74 public static final int ALT_QUOTATION_END = 3; 75 76 81 public static final int DELIMITER_COUNT = 4; 82 83 private LocaleData(){} 86 88 104 public static UnicodeSet getExemplarSet(ULocale locale, int options) { 105 ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale); 106 String pattern = bundle.getString(EXEMPLAR_CHARS); 107 return new UnicodeSet(pattern, UnicodeSet.IGNORE_SPACE | options); 108 } 109 110 127 public UnicodeSet getExemplarSet(int options, int extype) { 128 String [] exemplarSetTypes = { "ExemplarCharacters", "AuxExemplarCharacters" }; 129 try{ 130 ICUResourceBundle stringBundle = bundle.get(exemplarSetTypes[extype]); 131 132 if ( noSubstitute && (stringBundle.getLoadingStatus() == ICUResourceBundle.FROM_ROOT) ) 133 return null; 134 135 return new UnicodeSet(stringBundle.getString(), UnicodeSet.IGNORE_SPACE | options); 136 }catch(MissingResourceException ex){ 137 if(extype==LocaleData.ES_AUXILIARY){ 138 return new UnicodeSet(); 139 } 140 throw ex; 141 } 142 } 143 144 152 public static final LocaleData getInstance(ULocale locale) { 153 LocaleData ld = new LocaleData(); 154 ld.bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale ); 155 ld.noSubstitute = false; 156 return ld; 157 } 158 159 166 public static final LocaleData getInstance() { 167 return LocaleData.getInstance(ULocale.getDefault()); 168 } 169 170 180 public void setNoSubstitute(boolean setting) { 181 noSubstitute = setting; 182 } 183 184 194 public boolean getNoSubstitute() { 195 return noSubstitute; 196 } 197 198 208 public String getDelimiter(int type) { 209 String [] delimiterTypes = { "quotationStart", 210 "quotationEnd", 211 "alternateQuotationStart", 212 "alternateQuotationEnd" }; 213 214 ICUResourceBundle stringBundle = bundle.get("delimiters").get(delimiterTypes[type]); 215 216 if ( noSubstitute && (stringBundle.getLoadingStatus() == ICUResourceBundle.FROM_ROOT) ) 217 return null; 218 219 return new String (stringBundle.getString()); 220 } 221 222 226 public static final class MeasurementSystem{ 227 232 public static final MeasurementSystem SI = new MeasurementSystem(0); 233 234 238 public static final MeasurementSystem US = new MeasurementSystem(1); 239 240 private int systemID; 241 private MeasurementSystem(int id){ 242 systemID = id; 243 } 244 245 private boolean equals(int id){ 246 return systemID == id; 247 } 248 } 249 250 257 public static final MeasurementSystem getMeasurementSystem(ULocale locale){ 258 ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale); 259 ICUResourceBundle sysBundle = bundle.get(MEASUREMENT_SYSTEM); 260 261 int system = sysBundle.getInt(); 262 if(MeasurementSystem.US.equals(system)){ 263 return MeasurementSystem.US; 264 } 265 if(MeasurementSystem.SI.equals(system)){ 266 return MeasurementSystem.SI; 267 } 268 return null; 271 } 272 273 278 public static final class PaperSize{ 279 private int height; 280 private int width; 281 282 private PaperSize(int h, int w){ 283 height = h; 284 width = w; 285 } 286 291 public int getHeight(){ 292 return height; 293 } 294 299 public int getWidth(){ 300 return width; 301 } 302 } 303 304 311 public static final PaperSize getPaperSize(ULocale locale){ 312 ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale); 313 ICUResourceBundle obj = bundle.get(PAPER_SIZE); 314 int[] size = obj.getIntVector(); 315 return new PaperSize(size[0], size[1]); 316 } 317 } 318 | Popular Tags |