本文整理匯總了Java中org.springframework.context.MessageSource類的典型用法代碼示例。如果您正苦於以下問題:Java MessageSource類的具體用法?Java MessageSource怎麽用?Java MessageSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MessageSource類屬於org.springframework.context包,在下文中一共展示了MessageSource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: defaultMessageSource
import org.springframework.context.MessageSource; //導入依賴的package包/類
@Bean
public MessageSource defaultMessageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasenames("messages", "i18n/messages");
messageSource.setDefaultEncoding(Charset.forName("UTF-8").name());
messageSource.setFallbackToSystemLocale(true);
messageSource.setCacheSeconds(-1);
messageSource.setAlwaysUseMessageFormat(false);
messageSource.setUseCodeAsDefaultMessage(true);
return messageSource;
}
示例2: testAppContextClassHierarchy
import org.springframework.context.MessageSource; //導入依賴的package包/類
public void testAppContextClassHierarchy() {
Class<?>[] clazz =
ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class, ClassUtils.ClassSet.ALL_CLASSES);
//Closeable.class,
Class<?>[] expected =
new Class<?>[] { OsgiBundleXmlApplicationContext.class,
AbstractDelegatedExecutionApplicationContext.class, AbstractOsgiBundleApplicationContext.class,
AbstractRefreshableApplicationContext.class, AbstractApplicationContext.class,
DefaultResourceLoader.class, ResourceLoader.class,
AutoCloseable.class,
DelegatedExecutionOsgiBundleApplicationContext.class,
ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class,
ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
HierarchicalBeanFactory.class, ApplicationEventPublisher.class, ResourcePatternResolver.class,
MessageSource.class, BeanFactory.class, DisposableBean.class };
assertTrue(compareArrays(expected, clazz));
}
示例3: getMessageFromParent
import org.springframework.context.MessageSource; //導入依賴的package包/類
/**
* Try to retrieve the given message from the parent MessageSource, if any.
* @param code the code to lookup up, such as 'calculator.noRateSet'
* @param args array of arguments that will be filled in for params
* within the message
* @param locale the Locale in which to do the lookup
* @return the resolved message, or {@code null} if not found
* @see #getParentMessageSource()
*/
protected String getMessageFromParent(String code, Object[] args, Locale locale) {
MessageSource parent = getParentMessageSource();
if (parent != null) {
if (parent instanceof AbstractMessageSource) {
// Call internal method to avoid getting the default code back
// in case of "useCodeAsDefaultMessage" being activated.
return ((AbstractMessageSource) parent).getMessageInternal(code, args, locale);
}
else {
// Check parent MessageSource, returning null if not found there.
return parent.getMessage(code, args, null, locale);
}
}
// Not found in parent either.
return null;
}
示例4: getTheme
import org.springframework.context.MessageSource; //導入依賴的package包/類
/**
* This implementation returns a SimpleTheme instance, holding a
* ResourceBundle-based MessageSource whose basename corresponds to
* the given theme name (prefixed by the configured "basenamePrefix").
* <p>SimpleTheme instances are cached per theme name. Use a reloadable
* MessageSource if themes should reflect changes to the underlying files.
* @see #setBasenamePrefix
* @see #createMessageSource
*/
@Override
public Theme getTheme(String themeName) {
if (themeName == null) {
return null;
}
synchronized (this.themeCache) {
Theme theme = this.themeCache.get(themeName);
if (theme == null) {
String basename = this.basenamePrefix + themeName;
MessageSource messageSource = createMessageSource(basename);
theme = new SimpleTheme(themeName, messageSource);
initParent(theme);
this.themeCache.put(themeName, theme);
if (logger.isDebugEnabled()) {
logger.debug("Theme created: name '" + themeName + "', basename [" + basename + "]");
}
}
return theme;
}
}
示例5: getMessageService
import org.springframework.context.MessageSource; //導入依賴的package包/類
@Override
public MessageSource getMessageService(String messageFilename) {
if (messageFilename != null) {
MessageSource ms = messageServices.get(messageFilename);
if (ms == null) {
ResourceBundleMessageSource rbms = (ResourceBundleMessageSource) beanFactory
.getBean(LOADED_MESSAGE_SOURCE_BEAN);
rbms.setBasename(messageFilename);
messageServices.put(messageFilename, rbms);
ms = rbms;
}
return ms;
} else {
return null;
}
}
示例6: getChinese
import org.springframework.context.MessageSource; //導入依賴的package包/類
/**
* 查找錯誤消息
*
* @param source
* @param code
* @param params
* @param defaultMsg
* @return
*/
public static String getChinese(MessageSource source, String code, Object[] params, String defaultMsg) {
if (Check.NuNObj(source)) {
throw new IllegalArgumentException("message source is null");
}
if (Check.NuNStrStrict(code)) {
throw new IllegalArgumentException("code is empty");
}
//如果沒有object 默認設置為空數組
if (Check.NuNObj(params)) {
params = new Object[]{};
}
if (Check.NuNStrStrict(defaultMsg)) {
return source.getMessage(code, params, Locale.SIMPLIFIED_CHINESE);
} else {
return source.getMessage(code, params, defaultMsg, Locale.SIMPLIFIED_CHINESE);
}
}
示例7: getIntMessage
import org.springframework.context.MessageSource; //導入依賴的package包/類
/**
* 查找錯誤消息
*
* @param source
* @param code
* @param params
* @param defaultMsg
* @return
*/
public static int getIntMessage(MessageSource source, String code, Object[] params, String defaultMsg) {
if (Check.NuNObj(source)) {
throw new IllegalArgumentException("message source is null");
}
if (Check.NuNStrStrict(code)) {
throw new IllegalArgumentException("code is empty");
}
//如果沒有object 默認設置為空數組
if (Check.NuNObj(params)) {
params = new Object[]{};
}
String message = null;
if (Check.NuNStrStrict(defaultMsg)) {
message = source.getMessage(code, params, Locale.SIMPLIFIED_CHINESE);
} else {
message = source.getMessage(code, params, defaultMsg, Locale.SIMPLIFIED_CHINESE);
}
if (Check.NuNStrStrict(message)) {
throw new NumberFormatException("message is empty");
} else {
return Integer.valueOf(message);
}
}
示例8: getChinese
import org.springframework.context.MessageSource; //導入依賴的package包/類
/**
* 查找錯誤消息
*
* @param source
* @param code
* @param params
* @param defaultMsg
*
* @return
*/
public static String getChinese(MessageSource source, String code, Object[] params, String defaultMsg) {
if (Check.isNull(source)) {
throw new IllegalArgumentException("message source is null");
}
if (Check.isNullOrEmpty(code)) {
throw new IllegalArgumentException("code is empty");
}
//如果沒有object 默認設置為空數組
if (Check.isNull(params)) {
params = new Object[]{};
}
if (Check.isNullOrEmpty(defaultMsg)) {
return source.getMessage(code, params, Locale.SIMPLIFIED_CHINESE);
} else {
return source.getMessage(code, params, defaultMsg, Locale.SIMPLIFIED_CHINESE);
}
}
示例9: getIntMessage
import org.springframework.context.MessageSource; //導入依賴的package包/類
/**
* 查找錯誤消息
*
* @param source
* @param code
* @param params
* @param defaultMsg
*
* @return
*/
public static int getIntMessage(MessageSource source, String code, Object[] params, String defaultMsg) {
if (Check.isNull(source)) {
throw new IllegalArgumentException("message source is null");
}
if (Check.isNullOrEmpty(code)) {
throw new IllegalArgumentException("code is empty");
}
//如果沒有object 默認設置為空數組
if (Check.isNull(params)) {
params = new Object[]{};
}
String message = null;
if (Check.isNullOrEmpty(defaultMsg)) {
message = source.getMessage(code, params, Locale.SIMPLIFIED_CHINESE);
} else {
message = source.getMessage(code, params, defaultMsg, Locale.SIMPLIFIED_CHINESE);
}
if (Check.isNullOrEmpty(message)) {
throw new NumberFormatException("message is empty");
} else {
return Integer.valueOf(message);
}
}
示例10: messageSource
import org.springframework.context.MessageSource; //導入依賴的package包/類
@Bean(name = "messageSource")
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource reloadMessage = new ReloadableResourceBundleMessageSource();
reloadMessage.setBasename("classpath:/messages");
reloadMessage.setDefaultEncoding("UTF-8");
reloadMessage.setCacheSeconds(0);
return reloadMessage;
}
示例11: MailService
import org.springframework.context.MessageSource; //導入依賴的package包/類
public MailService(JHipsterProperties jHipsterProperties, JavaMailSender javaMailSender,
MessageSource messageSource, SpringTemplateEngine templateEngine) {
this.jHipsterProperties = jHipsterProperties;
this.javaMailSender = javaMailSender;
this.messageSource = messageSource;
this.templateEngine = templateEngine;
}
示例12: ErrorFieldsExceptionHandler
import org.springframework.context.MessageSource; //導入依賴的package包/類
/**
* Constructor.
*
* @param messageSource The message source to use
*/
@Autowired
public ErrorFieldsExceptionHandler(
final MessageSource messageSource
) {
this.messageSource = messageSource;
}
示例13: emailMessageSource
import org.springframework.context.MessageSource; //導入依賴的package包/類
@Bean
@Description("Spring mail message resolver")
public MessageSource emailMessageSource() {
log.info("loading non-reloadable mail messages resources");
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasename("classpath:/mails/messages/messages");
messageSource.setDefaultEncoding(CharEncoding.UTF_8);
return messageSource;
}
示例14: singleton
import org.springframework.context.MessageSource; //導入依賴的package包/類
/**
* Represents a factory method to instantiate {@code MessageHelper} singleton following by
* "Double Checked Locking & Volatile" pattern.
*
* @param messageSource {@code MessageSource} used as the underlying messages bundle
* @return {@code MessageHelper}
*/
public static MessageHelper singleton(final MessageSource messageSource) {
MessageHelper helper = instance;
if (helper == null) {
synchronized (MessageHelper.class) {
helper = instance;
if (helper == null) {
Assert.notNull(messageSource);
instance = new MessageHelper(messageSource);
helper = instance;
}
}
}
return helper;
}
示例15: writeAfterThrowingApplicationMessage
import org.springframework.context.MessageSource; //導入依賴的package包/類
public static Message writeAfterThrowingApplicationMessage(Exception e,
User user, String type, MessageSource messageSource,
Locale locale) {
Message message = new Message();
String body = "";
message.setType(Message.ERROR);
message.setAuthor(user);
switch (type) {
case "CREATE":
body = messageSource.getMessage("app.create.error", null, locale);
break;
case "UPDATE":
body = "Error update application - " + e.getLocalizedMessage();
break;
case "DELETE":
body = "Error delete application - " + e.getLocalizedMessage();
break;
case "START":
body = "Error start application - " + e.getLocalizedMessage();
break;
case "STOP":
body = "Error stop application - " + e.getLocalizedMessage();
break;
case "RESTART":
body = "Error restart application - " + e.getLocalizedMessage();
break;
default:
body = "Error : unkown error";
break;
}
message.setEvent(body);
return message;
}