1 16 package cintoo.messages; 17 18 import api.cintoo.messages.MessageHandler; 19 import api.cintoo.messages.bundle.BundleManager; 20 import api.cintoo.messages.context.Context; 21 import cintoo.messages.format.Formatter; 22 import cintoo.messages.locale.ThreadLocale; 23 import cintoo.messages.locale.LocaleManager; 24 25 import java.util.Locale ; 26 import java.util.ResourceBundle ; 27 28 38 public class DefaultMessageHandler implements MessageHandler { 39 private BundleManager bundleManager; 40 41 private Formatter formatter; 42 43 48 public DefaultMessageHandler(BundleManager bundleManager) { 49 super(); 50 this.bundleManager = bundleManager; 51 formatter = new Formatter(); 52 } 53 54 public void setBundleManager(BundleManager manager) { 55 this.bundleManager = manager; 56 } 57 58 public void clear() { 59 bundleManager.clear(); 60 } 61 62 private LocaleManager localeManager() { 63 return LocaleManager.getManager(); 64 } 65 66 72 public void setThreadLocale(String language) { 73 localeManager().setThreadLocale(new Locale(language)); 74 } 75 76 83 public void setThreadLocale(String language, String country) { 84 localeManager().setThreadLocale(new Locale(language, country)); 85 } 86 87 95 public void setThreadLocale(String language, String country, String variant) { 96 localeManager().setThreadLocale(new Locale(language, country, variant)); 97 } 98 99 105 public void setThreadLocale(Locale locale) { 106 localeManager().setThreadLocale(locale); 107 } 108 109 114 public void setLocale(String language) { 115 localeManager().setLocale(new Locale(language)); 116 } 117 118 124 public void setLocale(String language, String country) { 125 localeManager().setLocale(new Locale(language, country)); 126 } 127 128 134 public void setLocale(String language, String country, String variant) { 135 localeManager().setLocale(new Locale(language, country, variant)); 136 } 137 138 143 public void setLocale(Locale locale) { 144 localeManager().setLocale(locale); 145 } 146 147 152 public Locale getLocale() { 153 return localeManager().getLocale(); 154 } 155 156 161 public void setBundle(String bundleName) { 162 bundleManager.setBundle(bundleName); 163 } 164 165 171 public void setBundle(String bundleName, String packageName) { 172 bundleManager.setBundle(bundleName, packageName); 173 } 174 175 181 public void setBundle(String bundleName, Context context) { 182 bundleManager.setBundle(bundleName, context); 183 } 184 185 public String format(Object context, String key) { 186 return formatter.format(getBundle(context), key); 187 } 188 189 public String format(String key) { 190 return formatter.format(getBundle(), key); 191 } 192 193 public String format(Object context, String key, Object arg) { 194 return formatter.format(getBundle(context), key, arg); 195 } 196 197 public String format(String key, Object arg) { 198 return formatter.format(getBundle(), key, arg); 199 } 200 201 public String format(Object context, String key, Object ... args) { 202 return formatter.format(getBundle(context), key, args); 203 } 204 205 public String format(String key, Object ... args) { 206 return formatter.format(getBundle(), key, args); 207 } 208 209 214 public ResourceBundle getBundle() { 215 return bundleManager.getBundle(getLocale()); 216 } 217 218 224 public ResourceBundle getBundle(Object context) { 225 return bundleManager.getBundle(context, getLocale()); 226 } 227 } 228 | Popular Tags |