1 19 20 21 package org.apache.cayenne.util; 22 23 import java.util.MissingResourceException ; 24 import java.util.ResourceBundle ; 25 26 import org.apache.cayenne.CayenneRuntimeException; 27 28 31 37 public class LocalizedStringsHandler { 38 39 public static final String DEFAULT_MESSAGE_BUNDLE = "org.apache.cayenne.cayenne-strings"; 40 41 protected static ResourceBundle bundle; 42 43 46 public static String getString(String key) { 47 if (getBundle() == null) { 48 return ""; 49 } 50 51 try { 52 return getBundle().getString(key); 53 } 54 catch (Throwable e) { 55 return ""; 56 } 57 } 58 59 protected synchronized static ResourceBundle getBundle() { 60 if (bundle == null) { 61 try { 62 bundle = ResourceBundle.getBundle(DEFAULT_MESSAGE_BUNDLE); 63 } 64 catch (MissingResourceException e) { 65 throw new CayenneRuntimeException("Can't load properties: " 66 + DEFAULT_MESSAGE_BUNDLE, e); 67 } 68 } 69 return bundle; 70 } 71 } 72 | Popular Tags |