当前位置: 首页>>代码示例>>Java>>正文


Java MessageSource类代码示例

本文整理汇总了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;
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:12,代码来源:LocaleConfiguration.java

示例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));
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:20,代码来源:ClassUtilsTest.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:AbstractMessageSource.java

示例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;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:ResourceBundleThemeSource.java

示例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;
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:LoadedMessageSourceService.java

示例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);
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:27,代码来源:MessageSourceUtil.java

示例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);
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:34,代码来源:MessageSourceUtil.java

示例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);
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:28,代码来源:MessageSourceUtil.java

示例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);
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:35,代码来源:MessageSourceUtil.java

示例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;
}
 
开发者ID:grantharper,项目名称:security-demo,代码行数:9,代码来源:WebConfiguration.java

示例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;
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:9,代码来源:MailService.java

示例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;
}
 
开发者ID:JonkiPro,项目名称:REST-Web-Services,代码行数:12,代码来源:ErrorFieldsExceptionHandler.java

示例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;
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:10,代码来源:ThymeleafConfiguration.java

示例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;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:22,代码来源:MessageHelper.java

示例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;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:37,代码来源:MessageUtils.java


注:本文中的org.springframework.context.MessageSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。