1 56 57 package org.objectstyle.cayenne.util; 58 59 import java.util.MissingResourceException ; 60 import java.util.ResourceBundle ; 61 62 import org.apache.log4j.Logger; 63 64 67 73 public class LocalizedStringsHandler { 74 static final Logger logObj = Logger.getLogger(LocalizedStringsHandler.class); 75 76 public static final String DEFAULT_MESSAGE_BUNDLE = 77 "org.objectstyle.cayenne.cayenne-strings"; 78 79 protected static ResourceBundle bundle; 80 81 84 public static String getString(String key) { 85 if (getBundle() == null) { 86 return ""; 87 } 88 89 try { 90 return getBundle().getString(key); 91 } 92 catch (Throwable e) { 93 logObj.info("Error getting resource: " + key, e); 94 return ""; 95 } 96 } 97 98 protected synchronized static ResourceBundle getBundle() { 99 if (bundle == null) { 100 try { 101 bundle = ResourceBundle.getBundle(DEFAULT_MESSAGE_BUNDLE); 102 } 103 catch (MissingResourceException e) { 104 logObj.error("Can't load properties: " + DEFAULT_MESSAGE_BUNDLE, e); 105 } 106 } 107 return bundle; 108 } 109 } 110 | Popular Tags |