本文整理汇总了Java中org.springframework.context.support.StaticMessageSource.addMessage方法的典型用法代码示例。如果您正苦于以下问题:Java StaticMessageSource.addMessage方法的具体用法?Java StaticMessageSource.addMessage怎么用?Java StaticMessageSource.addMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.context.support.StaticMessageSource
的用法示例。
在下文中一共展示了StaticMessageSource.addMessage方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
}
示例3: 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));
}
示例4: 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());
}
示例5: 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());
}
示例6: 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(), '#', '.', '#');
}
示例7: registerBasicServices
import org.springframework.context.support.StaticMessageSource; //导入方法依赖的package包/类
protected void registerBasicServices(DefaultApplicationServices applicationServices) {
super.registerBasicServices(applicationServices);
StaticMessageSource messageSource = new StaticMessageSource();
messageSource.addMessage("dirty.message", Locale.getDefault(), "{0} has changed, original value was {1}.");
messageSource.addMessage("revert.message", Locale.getDefault(), "Revert value to {0}.");
messageSource.addMessage("property.label", Locale.getDefault(), "Property");
applicationServices.setMessageSource(messageSource);
}
示例8: testGetTableCellRendererComponent
import org.springframework.context.support.StaticMessageSource; //导入方法依赖的package包/类
public void testGetTableCellRendererComponent() {
StaticMessageSource messageSource = new StaticMessageSource();
messageSource.addMessage("org.springframework.richclient.table.renderer.EnumTableCellRendererTests$Numbers.ONE", Locale.getDefault(), "one");
messageSource.addMessage("org.springframework.richclient.table.renderer.EnumTableCellRendererTests$Numbers.TWO", Locale.getDefault(), "two");
messageSource.addMessage("org.springframework.richclient.table.renderer.EnumTableCellRendererTests$Numbers.THREE", Locale.getDefault(), "three");
messageSource.addMessage("org.springframework.richclient.table.renderer.EnumTableCellRendererTests$Numbers.FOUR", Locale.getDefault(), "four");
messageSource.addMessage("org.springframework.richclient.table.renderer.EnumTableCellRendererTests$Numbers.FIVE", Locale.getDefault(), "five");
messageSource.addMessage("org.springframework.richclient.table.renderer.EnumTableCellRendererTests$Numbers.SIX", Locale.getDefault(), "six");
messageSource.addMessage("org.springframework.richclient.table.renderer.EnumTableCellRendererTests$Numbers.SEVEN", Locale.getDefault(), "seven");
messageSource.addMessage("org.springframework.richclient.table.renderer.EnumTableCellRendererTests$Numbers.EIGHT", Locale.getDefault(), "eight");
messageSource.addMessage("org.springframework.richclient.table.renderer.EnumTableCellRendererTests$Numbers.NINE", Locale.getDefault(), "nine");
messageSource.addMessage("org.springframework.richclient.table.renderer.EnumTableCellRendererTests$Numbers.TEN", Locale.getDefault(), "ten");
MessageSourceAccessor msa = new MessageSourceAccessor(messageSource);
tetcr = new EnumTableCellRenderer(msa);
Object[][] rowData = {
{ Numbers.ONE },
{ Numbers.TWO },
{ Numbers.THREE },
{ Numbers.FOUR },
{ Numbers.FIVE },
{ Numbers.SIX },
{ Numbers.SEVEN },
{ Numbers.EIGHT },
{ Numbers.NINE },
{ Numbers.TEN }
};
Object[] columnNames = { "Numbers" };
JTable table = new JTable(rowData, columnNames);
TableColumnModel tcm = table.getColumnModel();
tcm.getColumn(0).setCellRenderer(tetcr);
tetcr.getTableCellRendererComponent(table, Numbers.SEVEN, false, false, 6, 0);
Component component = tetcr.getTableCellRendererComponent(table, Numbers.SEVEN, false, false, 6, 0);
assertTrue(component instanceof EnumTableCellRenderer);
}
示例9: testLoadFieldFace
import org.springframework.context.support.StaticMessageSource; //导入方法依赖的package包/类
public void testLoadFieldFace() {
Icon testIcon = new TestIcon(Color.RED);
MessageSourceFieldFaceSource fieldFaceSource = new MessageSourceFieldFaceSource();
StaticMessageSource messageSource = new StaticMessageSource();
messageSource.addMessage("context.field.caption", Locale.getDefault(), "the caption");
messageSource.addMessage("context.field.description", Locale.getDefault(), "the description");
messageSource.addMessage("context.field.label", Locale.getDefault(), "the label");
messageSource.addMessage("context.field.icon", Locale.getDefault(), "iconName");
fieldFaceSource.setMessageSourceAccessor(new MessageSourceAccessor(messageSource));
IconSource mockIconSource = (IconSource) EasyMock.createMock(IconSource.class);
EasyMock.expect(mockIconSource.getIcon("iconName")).andReturn(testIcon);
EasyMock.replay(mockIconSource);
fieldFaceSource.setIconSource(mockIconSource);
FieldFace face = fieldFaceSource.loadFieldFace("field", "context");
assertEquals("the caption", face.getCaption());
assertEquals("the label", face.getDisplayName());
assertEquals("the description", face.getDescription());
assertEquals(testIcon, face.getIcon());
EasyMock.verify(mockIconSource);
}
示例10: setUp
import org.springframework.context.support.StaticMessageSource; //导入方法依赖的package包/类
protected void setUp() {
this.personService = mock(PersonService.class);
final StaticMessageSource staticMessageSource = new StaticMessageSource();
staticMessageSource.addMessage("personAddedFinalConfirm", Locale.getDefault(), "test");
staticMessageSource.addMessage("roleAdded", Locale.getDefault(), "test");
staticMessageSource.addMessage("errorCode", Locale.getDefault(), "test");
this.messageContext = new DefaultMessageContext(staticMessageSource);
this.personSearchAction = new PersonSearchAction(this.personService);
this.personSearchAction.setPreferredPersonIdentifierType("NETID");
this.referenceRepository = new MockReferenceRepository();
this.reconciliationCriteriaFactory = new MockReconciliationCriteriaFactory();
}
示例11: testLoadingBeansWithMessageSource
import org.springframework.context.support.StaticMessageSource; //导入方法依赖的package包/类
/**
* Confirms that the post processor correctly notifies a given progress
* monitor as the bean factory is loaded, providing the expected localized
* messages. The following assertions are made:
*
* <ul>
* <li>The {@link ProgressMonitor#taskStarted(String, int)} method is
* called exactly once with a localized message, provided by the key
* {@link ProgressMonitoringBeanPostProcessor#LOADING_APP_CONTEXT_KEY}, and
* the number of singleton beans in the bean factory.</li>
* <li>The {@link ProgressMonitor#subTaskStarted(String)} method is called,
* with the localized message provided by
* {@link ProgressMonitoringBeanPostProcessor#LOADING_BEAN_KEY}, for each
* singleton bean defined in the bean factory being loaded.</li>
* <li>The {@link ProgressMonitor#worked(int)} method is called with the
* argument '1' the same number of times as there are singleton beans
* defined in the bean factory.</li>
* </ul>
*/
public void testLoadingBeansWithMessageSource() {
String loadingAppCtxMessage = "Loading Application Context Message Test";
int expectedSingletonBeanCount = 2;
String beanName1 = "beanName1";
String beanName2 = "beanName2";
String beanName3 = "beanName3";
String loadingBeanMessage = "LoadBeanTestMessage {0}";
String expectedLoadBean1Message = "LoadBeanTestMessage beanName1";
String expectedLoadBean2Message = "LoadBeanTestMessage beanName2";
StaticApplicationContext appCtx = new StaticApplicationContext();
appCtx.registerSingleton(beanName1, Object.class);
appCtx.registerSingleton(beanName2, Object.class);
appCtx.registerPrototype(beanName3, Object.class);
StaticMessageSource messageSource = new StaticMessageSource();
messageSource.addMessage(ProgressMonitoringBeanFactoryPostProcessor.LOADING_APP_CONTEXT_KEY, Locale
.getDefault(), loadingAppCtxMessage);
messageSource.addMessage(ProgressMonitoringBeanFactoryPostProcessor.LOADING_BEAN_KEY, Locale.getDefault(),
loadingBeanMessage);
ProgressMonitor mockProgressMonitor = (ProgressMonitor) EasyMock.createStrictMock(ProgressMonitor.class);
mockProgressMonitor.taskStarted(loadingAppCtxMessage, expectedSingletonBeanCount);
mockProgressMonitor.subTaskStarted(expectedLoadBean1Message);
mockProgressMonitor.worked(1);
mockProgressMonitor.subTaskStarted(expectedLoadBean2Message);
mockProgressMonitor.worked(1);
EasyMock.replay(mockProgressMonitor);
ProgressMonitoringBeanFactoryPostProcessor processor = new ProgressMonitoringBeanFactoryPostProcessor(
mockProgressMonitor, messageSource);
appCtx.addBeanFactoryPostProcessor(processor);
appCtx.refresh();
EasyMock.verify(mockProgressMonitor);
}
开发者ID:shevek,项目名称:spring-rich-client,代码行数:60,代码来源:ProgressMonitoringBeanFactoryPostProcessorTests.java