本文整理匯總了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;
}