1 11 package org.eclipse.help.internal.webapp; 12 13 import java.text.*; 14 import java.util.*; 15 16 import org.eclipse.core.runtime.*; 17 18 22 public class WebappResources { 23 24 private static HashMap resourceBundleTable = new HashMap(); 26 27 31 public static String getString(String name, Locale locale) { 32 33 ResourceBundle bundle = getBundle(locale); 35 if (bundle == null) { 36 return name; 37 } 38 39 try { 41 return bundle.getString(name); 42 } catch (MissingResourceException mre) { 43 return name; 44 } 45 } 46 47 50 public static String getString(String name, Locale locale, String replace0) { 51 52 ResourceBundle bundle = getBundle(locale); 54 if (bundle == null) { 55 return name; 56 } 57 58 try { 60 String stringFromPropertiesFile = bundle.getString(name); 61 stringFromPropertiesFile = MessageFormat.format( 62 stringFromPropertiesFile, new Object []{replace0}); 63 return stringFromPropertiesFile; 64 } catch (Exception e) { 65 return name; 66 } 67 68 } 69 76 private static ResourceBundle getBundle(Locale locale) { 77 if (locale == null) 78 locale = getDefaultLocale(); 79 80 ResourceBundle bundle = (ResourceBundle) resourceBundleTable 82 .get(locale); 83 84 if (bundle == null) { 86 bundle = ResourceBundle.getBundle(WebappResources.class.getName(), 87 locale); 88 if (bundle != null) { 89 resourceBundleTable.put(locale, bundle); 90 } 91 } 92 return bundle; 93 } 94 private static Locale getDefaultLocale() { 95 String nl = Platform.getNL(); 96 if (nl == null) 98 return Locale.getDefault(); 99 100 StringTokenizer locales = new StringTokenizer(nl, "_"); if (locales.countTokens() == 1) 103 return new Locale(locales.nextToken(), ""); else if (locales.countTokens() == 2) 105 return new Locale(locales.nextToken(), locales.nextToken()); 106 else if (locales.countTokens() == 3) 107 return new Locale(locales.nextToken(), locales.nextToken(), locales 108 .nextToken()); 109 else 110 return Locale.getDefault(); 111 } 112 } 113 | Popular Tags |