本文整理汇总了Java中org.springframework.context.support.ResourceBundleMessageSource类的典型用法代码示例。如果您正苦于以下问题:Java ResourceBundleMessageSource类的具体用法?Java ResourceBundleMessageSource怎么用?Java ResourceBundleMessageSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResourceBundleMessageSource类属于org.springframework.context.support包,在下文中一共展示了ResourceBundleMessageSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defaultMessageSource
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的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: getMessageService
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的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;
}
}
示例3: simpleTest
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的package包/类
@Test
public void simpleTest() throws Throwable
{
try
{
String dir = this.getClass().getResource("/").getFile();
String resource = "writer";
File dirFile = new File(dir);
new PropertiesWriter().writePropertiesSet(this.messages(), new Locale("de"), resource, dirFile, "ISO-8859-1");
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename(resource);
Assert.assertEquals(FR_TEST, messageSource.getMessage("test.key", null, new Locale("fr")));
Assert.assertEquals(DE_TEST, messageSource.getMessage("test.key", null, new Locale("de")));
}
finally
{
}
}
示例4: onContextRefreshed
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的package包/类
@Override
public void onContextRefreshed() {
Set<String> messages = new HashSet<>();
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
for (String beanName : BeanFactory.getBeanNames()) {
Package beanPackage = BeanFactory.getBeanClass(beanName).getPackage();
if (beanPackage == null) {
logger.warn(null, "无法获得Bean[{}]包。", beanName);
continue;
}
String packageName = beanPackage.getName();
if (resolver.getResource(packageName.replace('.', File.separatorChar) + "/message.properties").exists())
messages.add(packageName);
}
String[] names = new String[messages.size()];
int i = 0;
for (String name : messages)
names[i++] = name + ".message";
messageSource = new ResourceBundleMessageSource();
messageSource.setDefaultEncoding(context.getCharset(null));
messageSource.setBasenames(names);
}
示例5: getJstlAwareMessageSource
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的package包/类
/**
* Checks JSTL's "javax.servlet.jsp.jstl.fmt.localizationContext"
* context-param and creates a corresponding child message source,
* with the provided Spring-defined MessageSource as parent.
* @param servletContext the ServletContext we're running in
* (to check JSTL-related context-params in {@code web.xml})
* @param messageSource the MessageSource to expose, typically
* the ApplicationContext of the current DispatcherServlet
* @return the MessageSource to expose to JSTL; first checking the
* JSTL-defined bundle, then the Spring-defined MessageSource
* @see org.springframework.context.ApplicationContext
*/
public static MessageSource getJstlAwareMessageSource(
ServletContext servletContext, MessageSource messageSource) {
if (servletContext != null) {
String jstlInitParam = servletContext.getInitParameter(Config.FMT_LOCALIZATION_CONTEXT);
if (jstlInitParam != null) {
// Create a ResourceBundleMessageSource for the specified resource bundle
// basename in the JSTL context-param in web.xml, wiring it with the given
// Spring-defined MessageSource as parent.
ResourceBundleMessageSource jstlBundleWrapper = new ResourceBundleMessageSource();
jstlBundleWrapper.setBasename(jstlInitParam);
jstlBundleWrapper.setParentMessageSource(messageSource);
return jstlBundleWrapper;
}
}
return messageSource;
}
示例6: init
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的package包/类
public void init() {
URL url = buildMidpointHomeLocalizationFolderUrl();
ClassLoader classLoader = new URLClassLoader(new URL[]{url}, null);
sources.add(buildSource("Midpoint", classLoader));
sources.add(buildSource(SchemaConstants.BUNDLE_NAME, classLoader));
sources.add(buildSource("localization/Midpoint", null));
sources.add(buildSource(SchemaConstants.SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH, null));
// model security messages as fallback
ResourceBundleMessageSource modelSecurity = new ResourceBundleMessageSource();
modelSecurity.setBasename("com.evolveum.midpoint.security");
sources.add(modelSecurity);
// spring security messages as a fallback
ResourceBundleMessageSource springSecurity = new ResourceBundleMessageSource();
springSecurity.setBasename("org.springframework.security.messages");
sources.add(springSecurity);
}
示例7: resolve
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的package包/类
@Override
public void resolve(Component component) {
if( component.isPlain()) return;
logger.debug("Resolving {} {} feature", component, getName());
ApplicationContext parent = resolveContext.getRootContext() ;
ClassLoader realm = component.getClassLoader();
//在根据配置的情况下,根据 manifest里面的App-Message加载资源
String appMessage = getAppMessage(component);
if(StringUtils.isNotBlank(appMessage)){
CombinedMessageSource combined = parent.getBean(CombinedMessageSource.class);
ResourceBundleMessageSource source = new ResourceBundleMessageSource();
source.setBundleClassLoader(realm);
source.setBasenames(StringUtils.split(appMessage, CONFIG_LOCATION_DELIMITERS));
combined.combine(source);
}
resolveContext.registerFeature(component, getName(), realm);
}
示例8: beforeClass
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的package包/类
@BeforeClass
public void beforeClass()
{
AllPropertiesMessageSource molgenisLocalizationMessages = new AllPropertiesMessageSource();
molgenisLocalizationMessages.addMolgenisNamespaces("web");
ResourceBundleMessageSource hibernateValidationMessages = new ResourceBundleMessageSource();
hibernateValidationMessages.addBasenames("org.hibernate.validator.ValidationMessages");
molgenisLocalizationMessages.setParentMessageSource(hibernateValidationMessages);
MessageSourceHolder.setMessageSource(molgenisLocalizationMessages);
globalError = new ObjectError("entityCollectionRequestV2", new String[] { "TwoFieldsSet" }, new Object[] { 1 },
"must have two fields set");
fieldError = new FieldError("entityCollectionRequestV2", "num", -10, false,
new String[] { "Min.entityCollectionRequestV2.num", "Min.num", "Min.int", "Min" }, new Object[] {
new DefaultMessageSourceResolvable(new String[] { "entityCollectionRequestV2.num", "num" }, null,
"num"), 0 }, "must be greater than or equal to 0");
}
示例9: messageSource
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的package包/类
@Bean
public ResourceBundleMessageSource messageSource()
{
ResourceBundleMessageSource source = new ResourceBundleMessageSource();
source.setBasename("locale/messages");
source.setDefaultEncoding("UTF-8");
return source;
}
示例10: createMessageSource
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的package包/类
@Override
protected MessageSource createMessageSource(String basename) {
ResourceBundleMessageSource messageSource = (ResourceBundleMessageSource) super.createMessageSource(basename);
// Create parent theme recursively.
for (Theme theme : settingsService.getAvailableThemes()) {
if (basename.equals(basenamePrefix + theme.getId()) && theme.getParent() != null) {
String parent = basenamePrefix + theme.getParent();
messageSource.setParentMessageSource(createMessageSource(parent));
break;
}
}
return messageSource;
}
示例11: mailMessageSource
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的package包/类
@Bean
public MessageSource mailMessageSource() {
ResourceBundleMessageSource msgsource = new ResourceBundleMessageSource();
if (nixmashModeEnabled)
msgsource.setBasename("mail-nixmash");
else
msgsource.setBasename("mail-messages");
return msgsource;
}
示例12: messageSource
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的package包/类
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource msgsource = new ResourceBundleMessageSource();
if (nixmashModeEnabled)
msgsource.setBasename("nixmash");
else
msgsource.setBasename("messages");
msgsource.setUseCodeAsDefaultMessage(
Boolean.parseBoolean(environment.getRequiredProperty(USE_CODE_AS_DEFAULT_MESSAGE)));
return msgsource;
}
示例13: messageSource
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的package包/类
/**
* @return ResourceBundleMessageSource pour les messages de l'application
*/
@Bean
public ResourceBundleMessageSource messageSource() {
ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
resourceBundleMessageSource.setBasenames(
"i18n/messages",
"i18n/backoffice/backoffice-messages",
"i18n/backoffice/nomenclature-messages",
"i18n/candidat/candidat-messages");
resourceBundleMessageSource.setFallbackToSystemLocale(false);
return resourceBundleMessageSource;
}
示例14: messageSource
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的package包/类
@Bean
public ResourceBundleMessageSource messageSource() {
ResourceBundleMessageSource source = new ResourceBundleMessageSource();
source.setBasenames("i18n/messages");
source.setUseCodeAsDefaultMessage(true);
source.setDefaultEncoding("UTF-8");
return source;
}
示例15: messageSource
import org.springframework.context.support.ResourceBundleMessageSource; //导入依赖的package包/类
@Bean
public MessageSource messageSource()
{
ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
resourceBundleMessageSource.setDefaultEncoding("UTF-8");
resourceBundleMessageSource.addBasenames("templates/index");
return resourceBundleMessageSource;
}