1 13 14 package info.magnolia.cms.i18n; 15 16 import java.text.MessageFormat ; 17 import java.util.Locale ; 18 import java.util.ResourceBundle ; 19 20 import org.apache.commons.lang.StringUtils; 21 import org.slf4j.Logger; 22 import org.slf4j.LoggerFactory; 23 24 25 31 32 public abstract class AbstractMessagesImpl implements Messages { 33 34 protected Logger log = LoggerFactory.getLogger(AbstractMessagesImpl.class); 35 36 39 public static final String JS_OBJECTNAME = "mgnlMessages"; 41 44 protected String basename = MessagesManager.DEFAULT_BASENAME; 45 46 49 protected Locale locale; 50 51 54 protected ResourceBundle bundle; 55 56 60 protected AbstractMessagesImpl(String basename, Locale locale) { 61 this.locale = locale; 62 this.basename = basename; 63 } 64 65 68 public Locale getLocale() { 69 return locale; 70 } 71 72 76 public String getBasename() { 77 return basename; 78 } 79 80 86 public String get(String key, Object [] args) { 87 return MessageFormat.format(get(key), args); 88 } 89 90 96 public String getWithDefault(String key, String defaultMsg) { 97 String msg = get(key); 98 if (msg.startsWith("???")) { msg = defaultMsg; 100 } 101 return msg; 102 } 103 104 111 public String getWithDefault(String key, Object [] args, String defaultMsg) { 112 return MessageFormat.format(getWithDefault(key, defaultMsg), args); 113 } 114 115 118 public boolean equals(Object arg0) { 119 return StringUtils.equals(((AbstractMessagesImpl) arg0).basename, this.basename) 120 && this.locale.equals(((AbstractMessagesImpl) arg0).locale); 121 } 122 123 126 public String toString() { 127 return this.basename + "(" + this.locale.toString() + ")"; 128 } 129 130 } | Popular Tags |