1 10 11 package org.enhydra.jawe; 12 13 import org.enhydra.jawe.xml.*; 14 15 import java.awt.*; 16 import java.util.*; 17 import java.io.*; 18 import java.text.*; 19 import java.net.URL ; 20 import javax.accessibility.*; 21 22 26 public class ResourceManager { 27 private static Locale defaultLocale; 28 private static ResourceBundle defaultResourceBoundle; 29 private static Locale choosenLocale; 30 private static ResourceBundle choosenResourceBundle; 31 32 private static Properties properties=new Properties(); 33 34 static { 35 try { 36 defaultLocale = new Locale(""); 38 defaultResourceBoundle = ResourceBundle. 39 getBundle(JaWEConstants.RESOURCE_PATH,defaultLocale); 40 41 String startingLocale=JaWEConfig.getInstance().getStartingLocale(); 43 if (startingLocale!=null && startingLocale.length()>0) { 44 if (!startingLocale.equals("default")) { 45 choosenLocale=new Locale(startingLocale); 46 } else { 47 choosenLocale=defaultLocale; 48 } 49 } else { 50 choosenLocale=Locale.getDefault(); 51 } 52 if (!startingLocale.equals("default")) { 53 choosenResourceBundle = ResourceBundle.getBundle(JaWEConstants.RESOURCE_PATH,choosenLocale); 54 } else { 55 choosenResourceBundle = defaultResourceBoundle; 56 } 57 } catch (MissingResourceException mre) { 58 System.err.println(JaWEConstants.RESOURCE_PATH+".properties not found"); 59 System.exit(1); 60 } 61 62 try { 63 java.net.URL u=ResourceManager.class.getClassLoader(). 64 getResource("org/enhydra/jawe/resources/JaWE.res"); 65 InputStream is=(InputStream)u.getContent(); 66 properties.load(is); 67 } catch (Exception ex) {} 68 XMLUtil.setDefaultResources(defaultResourceBoundle); 69 XMLUtil.setChoosenResources(choosenResourceBundle); 70 XMLUtil.setProperties(properties); 71 } 72 73 83 public static String getLanguageDependentString (String nm) { 84 String str; 85 try { 86 str=choosenResourceBundle.getString(nm); 87 } catch (MissingResourceException mre) { 88 try { 89 str=defaultResourceBoundle.getString(nm); 90 } catch (MissingResourceException mre1) { 91 str = null; 92 } 93 } 94 return str; 95 } 96 97 public static String getResourceString (String nm) { 98 String str=null; 99 try { 100 str=properties.getProperty(nm); 101 } catch (Exception ex) {} 102 return str; 103 } 104 105 111 public static URL getResource (String key) { 112 String name=properties.getProperty(key); 113 if (name != null) { 114 URL url = ResourceManager.class.getClassLoader().getResource(name); 115 return url; 116 } 117 return null; 118 } 119 120 121 public static void setDefault () { 122 choosenResourceBundle=defaultResourceBoundle; 123 choosenLocale=defaultLocale; 124 XMLUtil.setChoosenResources(choosenResourceBundle); 125 } 126 127 public static void setSystem () { 128 choosenLocale=Locale.getDefault(); 129 choosenResourceBundle = ResourceBundle.getBundle(JaWEConstants.RESOURCE_PATH,choosenLocale); 130 XMLUtil.setChoosenResources(choosenResourceBundle); 131 } 132 133 136 public static ResourceBundle getDefaultResourceBundle() { 137 return defaultResourceBoundle; 138 } 139 140 143 public static ResourceBundle getChoosenResourceBundle() { 144 return choosenResourceBundle; 145 } 146 147 150 public static Locale getDefaultLocale() { 151 return defaultLocale; 152 } 153 154 157 public static Locale getChoosenLocale() { 158 return choosenLocale; 159 } 160 161 164 public static void setChoosen (Locale loc) throws MissingResourceException { 165 Locale previousLocale=choosenLocale; 166 try { 167 choosenLocale=loc; 168 choosenResourceBundle = ResourceBundle.getBundle(JaWEConstants.RESOURCE_PATH,loc); 169 XMLUtil.setChoosenResources(choosenResourceBundle); 170 } catch (Exception ex) { 171 choosenLocale=previousLocale; 172 } 173 } 174 } 175 | Popular Tags |