本文整理汇总了Java中org.springframework.context.support.StaticMessageSource类的典型用法代码示例。如果您正苦于以下问题:Java StaticMessageSource类的具体用法?Java StaticMessageSource怎么用?Java StaticMessageSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StaticMessageSource类属于org.springframework.context.support包,在下文中一共展示了StaticMessageSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRejectWithoutDefaultMessage
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
@Test
public void testRejectWithoutDefaultMessage() throws Exception {
TestBean tb = new TestBean();
tb.setName("myName");
tb.setAge(99);
BeanPropertyBindingResult ex = new BeanPropertyBindingResult(tb, "tb");
ex.reject("invalid");
ex.rejectValue("age", "invalidField");
StaticMessageSource ms = new StaticMessageSource();
ms.addMessage("invalid", Locale.US, "general error");
ms.addMessage("invalidField", Locale.US, "invalid field");
assertEquals("general error", ms.getMessage(ex.getGlobalError(), Locale.US));
assertEquals("invalid field", ms.getMessage(ex.getFieldError("age"), Locale.US));
}
示例2: getAdvicesAndAdvisorsForBean
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
@Override
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String name, TargetSource customTargetSource) {
if (StaticMessageSource.class.equals(beanClass)) {
return DO_NOT_PROXY;
}
else if (name.endsWith("ToBeProxied")) {
boolean isFactoryBean = FactoryBean.class.isAssignableFrom(beanClass);
if ((this.proxyFactoryBean && isFactoryBean) || (this.proxyObject && !isFactoryBean)) {
return new Object[] {this.testInterceptor};
}
else {
return DO_NOT_PROXY;
}
}
else {
return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
}
}
示例3: statusCodeAndReasonMessage
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
@Test
public void statusCodeAndReasonMessage() {
Locale locale = Locale.CHINESE;
LocaleContextHolder.setLocale(locale);
try {
StaticMessageSource messageSource = new StaticMessageSource();
messageSource.addMessage("gone.reason", locale, "Gone reason message");
exceptionResolver.setMessageSource(messageSource);
StatusCodeAndReasonMessageException ex = new StatusCodeAndReasonMessageException();
exceptionResolver.resolveException(request, response, null, ex);
assertEquals("Invalid status reason", "Gone reason message", response.getErrorMessage());
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例4: removeLocalizations
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
/**
* Removes the additional localization for the given key.
*
* @param key
* Key of the localizations.
*/
public synchronized void removeLocalizations(String key) {
StaticMessageSource removedDictionary = bundlesToLocalizations.remove(key);
if (removedDictionary != null) {
ArrayList<StaticMessageSource> newLocalizations = new ArrayList<StaticMessageSource>(
localizations);
newLocalizations.remove(removedDictionary);
this.localizations = newLocalizations;
}
Iterator<Entry<String, Set<String>>> iterator = languageCodesToKeys.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, Set<String>> languageCodeToKeys = iterator.next();
Set<String> keys = languageCodeToKeys.getValue();
keys.remove(key);
if (keys.isEmpty()) {
iterator.remove();
}
}
ServiceLocator.findService(EventDispatcher.class).fire(new ResourceBundleChangedEvent());
}
示例5: testRejectWithoutDefaultMessage
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
public void testRejectWithoutDefaultMessage() throws Exception {
TestBean tb = new TestBean();
tb.setName("myName");
tb.setAge(99);
BeanPropertyBindingResult ex = new BeanPropertyBindingResult(tb, "tb");
ex.reject("invalid");
ex.rejectValue("age", "invalidField");
StaticMessageSource ms = new StaticMessageSource();
ms.addMessage("invalid", Locale.US, "general error");
ms.addMessage("invalidField", Locale.US, "invalid field");
assertEquals("general error", ms.getMessage(ex.getGlobalError(), Locale.US));
assertEquals("invalid field", ms.getMessage(ex.getFieldError("age"), Locale.US));
}
示例6: testConstructorWithoutMessageSource
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
public void testConstructorWithoutMessageSource() {
BeanTableModel beanTableModel = new BeanTableModel(TestBean.class) {
protected String[] createColumnPropertyNames() {
return new String[] { "stringProperty", "dateProperty" };
}
protected Class[] createColumnClasses() {
return new Class[] { String.class, Date.class };
}
};
try {
beanTableModel.setRowNumbers(false);
fail("Must throw IllegalStateException: no messagesource set");
}
catch (IllegalStateException e) {
// test passes
}
StaticMessageSource messageSource = new StaticMessageSource();
beanTableModel.setMessageSource(messageSource);
beanTableModel.setRowNumbers(false);
}
示例7: testGetErrorMessage
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
public void testGetErrorMessage() {
DefaultBindingErrorMessageProvider provider = new DefaultBindingErrorMessageProvider();
TestAbstractFormModel formModel = new TestAbstractFormModel(new Object()) {
public FieldFace getFieldFace(String field) {
return new DefaultFieldFace("Some Property", "", "", new LabelInfo("Some Property"), null);
}
};
formModel.add("someProperty", new ValueHolder("value"));
StaticMessageSource messageSource = new StaticMessageSource();
messageSource.addMessage("typeMismatch", Locale.getDefault(), "{0} has an invalid format \"{1}\"");
MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(messageSource);
provider.setMessageSourceAccessor(messageSourceAccessor);
ValidationMessage message = provider.getErrorMessage(formModel, "someProperty", "new value",
new IllegalArgumentException());
assertNotNull(message);
assertEquals("someProperty", message.getProperty());
assertEquals("Some Property has an invalid format \"new value\"", message.getMessage());
}
示例8: beanPostProcessorPublishesEvents
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
@Test
public void beanPostProcessorPublishesEvents() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("listener", new RootBeanDefinition(BeanThatListens.class));
context.registerBeanDefinition("messageSource", new RootBeanDefinition(StaticMessageSource.class));
context.registerBeanDefinition("postProcessor", new RootBeanDefinition(EventPublishingBeanPostProcessor.class));
context.refresh();
context.publishEvent(new MyEvent(this));
BeanThatListens listener = context.getBean(BeanThatListens.class);
assertEquals(4, listener.getEventCount());
context.close();
}
示例9: setupFactory
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
private void setupFactory() throws IOException {
this.factory = new PropertiesConfigurationFactory<Foo>(Foo.class);
this.factory.setValidator(this.validator);
this.factory.setTargetName(this.targetName);
this.factory.setIgnoreUnknownFields(this.ignoreUnknownFields);
this.factory.setMessageSource(new StaticMessageSource());
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:PropertiesConfigurationFactoryMapTests.java
示例10: testRequiredFieldsValidation
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
@Test
public void testRequiredFieldsValidation() throws Exception {
TargetWithValidatedMap target = new TargetWithValidatedMap();
BindingResult result = bind(target, "info[foo]: bar");
assertThat(result.getErrorCount()).isEqualTo(2);
for (FieldError error : result.getFieldErrors()) {
System.err.println(
new StaticMessageSource().getMessage(error, Locale.getDefault()));
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:RelaxedDataBinderTests.java
示例11: createFoo
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
private Foo createFoo(final String yaml) throws Exception {
YamlConfigurationFactory<Foo> factory = new YamlConfigurationFactory<Foo>(
Foo.class);
factory.setYaml(yaml);
factory.setExceptionIfInvalid(true);
factory.setPropertyAliases(this.aliases);
factory.setValidator(this.validator);
factory.setMessageSource(new StaticMessageSource());
factory.afterPropertiesSet();
return factory.getObject();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:YamlConfigurationFactoryTests.java
示例12: createJee
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
private Jee createJee(final String yaml) throws Exception {
YamlConfigurationFactory<Jee> factory = new YamlConfigurationFactory<Jee>(
Jee.class);
factory.setYaml(yaml);
factory.setExceptionIfInvalid(true);
factory.setPropertyAliases(this.aliases);
factory.setValidator(this.validator);
factory.setMessageSource(new StaticMessageSource());
factory.afterPropertiesSet();
return factory.getObject();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:YamlConfigurationFactoryTests.java
示例13: addLocalizations
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
/**
* Adds a map with additional localizations for a specified local to this manager.
*
* @param key
* Key of the localizations. If there is already a dictionary for this key, it will
* be overwritten.
* @param locale
* The locale the localizations are for.
* @param localizations
* The localizations. The key is the message key and and value the value.
*/
public synchronized void addLocalizations(String key, Locale locale,
Map<String, String> localizations) {
if (localizations == null || localizations.isEmpty()) {
LOGGER.debug("You can't add empty localizations for {}. The key was {}", locale, key);
return;
}
String languageCode = locale.toString();
StaticMessageSource innerLocalizations = bundlesToLocalizations.containsKey(key) ? bundlesToLocalizations
.get(key) : new StaticMessageSource();
for (Entry<String, String> localization : localizations.entrySet()) {
innerLocalizations.addMessage(localization.getKey(), locale, localization.getValue());
}
Set<String> keys = languageCodesToKeys.get(languageCode);
if (keys == null) {
keys = new HashSet<String>();
languageCodesToKeys.put(languageCode, keys);
}
keys.add(key);
this.bundlesToLocalizations.put(key, innerLocalizations);
ArrayList<StaticMessageSource> newLocalizations = new ArrayList<StaticMessageSource>(
this.localizations);
newLocalizations.remove(innerLocalizations);
newLocalizations.add(0, innerLocalizations);
this.localizations = newLocalizations;
ServiceLocator.findService(EventDispatcher.class).fire(new ResourceBundleChangedEvent());
}
示例14: testRequiredFieldsValidation
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
@Test
public void testRequiredFieldsValidation() throws Exception {
TargetWithValidatedMap target = new TargetWithValidatedMap();
BindingResult result = bind(target, "info[foo]: bar");
assertEquals(2, result.getErrorCount());
for (FieldError error : result.getFieldErrors()) {
System.err.println(
new StaticMessageSource().getMessage(error, Locale.getDefault()));
}
}
示例15: buildTemplateFactory
import org.springframework.context.support.StaticMessageSource; //导入依赖的package包/类
private TemplateFactory buildTemplateFactory()
{
StaticMessageSource messageSource = new StaticMessageSource();
messageSource.addMessage("test", Locale.getDefault(), "A very useful message");
ExpressionHandlerRegistry registry = new DefaultExpressionHandlerRegistry();
registry.registerExpressionHandler(new MessageExpressionHandler(messageSource));
return new SimpleTemplateFactory(registry, new DefaultContentEscapeHandlerRegistry(), '#', '.', '#');
}