1 10 11 package org.enhydra.shark.corbaclient; 12 13 import java.net.*; 14 import java.util.*; 15 16 21 public class ResourceManager { 22 private static final String resourcePath= 23 "org.enhydra.shark.corbaclient.resources.SharkClient"; 24 25 public static Locale defaultLocale; 26 public static ResourceBundle defaultResource; 27 public static Locale choosenLocale; 28 public static ResourceBundle choosenResource; 29 30 31 static { 32 try { 33 defaultLocale = new Locale("en"); 35 defaultResource = ResourceBundle. 36 getBundle(resourcePath,new Locale("")); 37 38 choosenLocale = Locale.getDefault(); 40 choosenResource = ResourceBundle.getBundle(resourcePath,choosenLocale); 41 } 42 catch (MissingResourceException mre) { 43 System.err.println(resourcePath+".properties not found"); 44 System.exit(1); 45 } 46 } 47 48 58 public static String getLanguageDependentString (String nm) { 59 String str; 60 try { 61 str=choosenResource.getString(nm); 62 } catch (MissingResourceException mre) { 63 try { 64 str=defaultResource.getString(nm); 65 } catch (MissingResourceException mre1) { 66 str = null; 67 } 68 } 69 return str; 70 } 71 72 78 public static URL getResource (String key) { 79 String name = getLanguageDependentString(key); 80 if (name != null) { 81 URL url = ResourceManager.class.getClassLoader().getResource(name); 82 return url; 83 } 84 return null; 85 } 86 87 88 public static void setDefault () { 89 choosenResource=defaultResource; 90 choosenLocale=defaultLocale; 91 } 92 93 96 public static ResourceBundle getDefaultResource() { 97 return defaultResource; 98 } 99 100 103 public static ResourceBundle getChoosenResource() { 104 return choosenResource; 105 } 106 107 110 public static Locale getDefaultLocale() { 111 return defaultLocale; 112 } 113 114 117 public static Locale getChoosenLocale() { 118 return choosenLocale; 119 } 120 121 124 public static void setChoosen (String language) throws MissingResourceException { 125 choosenLocale = new Locale(language); 126 String bundle=resourcePath+"_"+language; 127 choosenResource = ResourceBundle.getBundle(bundle); 128 } 129 130 133 public static void setChoosen (String language,String country) throws MissingResourceException { 134 choosenLocale = new Locale(language,country); 135 String bundle=resourcePath+"_"+language+"_"+country; 136 choosenResource = ResourceBundle.getBundle(bundle); 137 } 138 139 142 public static void setChoosen (String language,String country,String variant) throws MissingResourceException { 143 choosenLocale = new Locale(language,country,variant); 144 String bundle=resourcePath+"_"+language+"_"+country+"_"+variant; 145 choosenResource = ResourceBundle.getBundle(bundle); 146 } 147 148 } 149 150 | Popular Tags |