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


Java NoSuchMessageException类代码示例

本文整理汇总了Java中org.springframework.context.NoSuchMessageException的典型用法代码示例。如果您正苦于以下问题:Java NoSuchMessageException类的具体用法?Java NoSuchMessageException怎么用?Java NoSuchMessageException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NoSuchMessageException类属于org.springframework.context包,在下文中一共展示了NoSuchMessageException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMessage

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
@Override
public final String getMessage(MessageSourceResolvable resolvable, Locale locale)
		throws NoSuchMessageException {

	String[] codes = resolvable.getCodes();
	if (codes == null) {
		codes = new String[0];
	}
	for (String code : codes) {
		String msg = getMessageInternal(code, resolvable.getArguments(), locale);
		if (msg != null) {
			return msg;
		}
	}
	String defaultMessage = resolvable.getDefaultMessage();
	if (defaultMessage != null) {
		return renderDefaultMessage(defaultMessage, resolvable.getArguments(), locale);
	}
	if (codes.length > 0) {
		String fallback = getDefaultMessage(codes[0]);
		if (fallback != null) {
			return fallback;
		}
	}
	throw new NoSuchMessageException(codes.length > 0 ? codes[codes.length - 1] : null, locale);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:AbstractMessageSource.java

示例2: getMessage

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
public String getMessage(String[] keys, Object[] vars, Locale locale) {
	String msg = "???" + (keys.length > 0 ? keys[keys.length-1] : "") + "???";
	boolean found = false;
	int i = 0;
	while( ! found && i < keys.length) {		
		try {
			msg = messageSource.getMessage(
					keys[i],
					vars,
					locale);
			found = true;
		} catch (NoSuchMessageException ex) {
			i++;
		}
	}
	if( ! found ) {
		String key = keys[keys.length-1]; 
		if (key.startsWith("enum.")){
			msg = key.substring(key.lastIndexOf(".") + 1);
		}			
	}
	return msg;
}
 
开发者ID:GovernIB,项目名称:helium,代码行数:24,代码来源:MessageHelper.java

示例3: withoutMessageSource

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
/**
 * Overridden in order to use MockPortletConfig
 * @see org.springframework.web.context.XmlWebApplicationContextTests#testWithoutMessageSource()
 */
@Test
@SuppressWarnings("resource")
public void withoutMessageSource() throws Exception {
	MockPortletContext portletContext = new MockPortletContext("");
	MockPortletConfig portletConfig = new MockPortletConfig(portletContext);
	XmlPortletApplicationContext pac = new XmlPortletApplicationContext();
	pac.setParent(root);
	pac.setPortletConfig(portletConfig);
	pac.setNamespace("testNamespace");
	pac.setConfigLocations(new String[] {"/org/springframework/web/portlet/context/WEB-INF/test-portlet.xml"});
	pac.refresh();
	try {
		pac.getMessage("someMessage", null, Locale.getDefault());
		fail("Should have thrown NoSuchMessageException");
	}
	catch (NoSuchMessageException ex) {
		// expected;
	}
	String msg = pac.getMessage("someMessage", null, "default", Locale.getDefault());
	assertEquals("Default message returned", "default", msg);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:XmlPortletApplicationContextTests.java

示例4: testReloadableResourceBundleMessageSourceWithInappropriateDefaultCharset

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
@Test
public void testReloadableResourceBundleMessageSourceWithInappropriateDefaultCharset() {
	ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
	ms.setBasename("org/springframework/context/support/messages");
	ms.setDefaultEncoding("unicode");
	Properties fileCharsets = new Properties();
	fileCharsets.setProperty("org/springframework/context/support/messages_de", "unicode");
	ms.setFileEncodings(fileCharsets);
	ms.setFallbackToSystemLocale(false);
	try {
		ms.getMessage("code1", null, Locale.ENGLISH);
		fail("Should have thrown NoSuchMessageException");
	}
	catch (NoSuchMessageException ex) {
		// expected
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:ResourceBundleMessageSourceTests.java

示例5: testReloadableResourceBundleMessageSourceWithInappropriateEnglishCharset

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
@Test
public void testReloadableResourceBundleMessageSourceWithInappropriateEnglishCharset() {
	ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
	ms.setBasename("org/springframework/context/support/messages");
	ms.setFallbackToSystemLocale(false);
	Properties fileCharsets = new Properties();
	fileCharsets.setProperty("org/springframework/context/support/messages", "unicode");
	ms.setFileEncodings(fileCharsets);
	try {
		ms.getMessage("code1", null, Locale.ENGLISH);
		fail("Should have thrown NoSuchMessageException");
	}
	catch (NoSuchMessageException ex) {
		// expected
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:ResourceBundleMessageSourceTests.java

示例6: messageSourceResolvable

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
@Test
public void messageSourceResolvable() {
	// first code valid
	String[] codes1 = new String[] {"message.format.example3", "message.format.example2"};
	MessageSourceResolvable resolvable1 = new DefaultMessageSourceResolvable(codes1, null, "default");
	assertTrue("correct message retrieved", MSG_TXT3_US.equals(sac.getMessage(resolvable1, Locale.US)));

	// only second code valid
	String[] codes2 = new String[] {"message.format.example99", "message.format.example2"};
	MessageSourceResolvable resolvable2 = new DefaultMessageSourceResolvable(codes2, null, "default");
	assertTrue("correct message retrieved", MSG_TXT2_US.equals(sac.getMessage(resolvable2, Locale.US)));

	// no code valid, but default given
	String[] codes3 = new String[] {"message.format.example99", "message.format.example98"};
	MessageSourceResolvable resolvable3 = new DefaultMessageSourceResolvable(codes3, null, "default");
	assertTrue("correct message retrieved", "default".equals(sac.getMessage(resolvable3, Locale.US)));

	// no code valid, no default
	String[] codes4 = new String[] {"message.format.example99", "message.format.example98"};
	MessageSourceResolvable resolvable4 = new DefaultMessageSourceResolvable(codes4);

	exception.expect(NoSuchMessageException.class);
	sac.getMessage(resolvable4, Locale.US);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:StaticMessageSourceTests.java

示例7: withoutMessageSource

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
@Test
@SuppressWarnings("resource")
public void withoutMessageSource() throws Exception {
	MockServletContext sc = new MockServletContext("");
	XmlWebApplicationContext wac = new XmlWebApplicationContext();
	wac.setParent(root);
	wac.setServletContext(sc);
	wac.setNamespace("testNamespace");
	wac.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/test-servlet.xml"});
	wac.refresh();
	try {
		wac.getMessage("someMessage", null, Locale.getDefault());
		fail("Should have thrown NoSuchMessageException");
	}
	catch (NoSuchMessageException ex) {
		// expected;
	}
	String msg = wac.getMessage("someMessage", null, "default", Locale.getDefault());
	assertTrue("Default message returned", "default".equals(msg));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:XmlWebApplicationContextTests.java

示例8: resolveLocalizedErrorMessage

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
/**
 * 解析错误信息
 * TODO 国际化错误信息应该异常中处理
 * @param fieldError
 * @return
 */
private String resolveLocalizedErrorMessage(org.springframework.validation.FieldError fieldError) {
    Locale currentLocale =  LocaleContextHolder.getLocale();
    String localizedErrorMessage = null;
    if(messageSource != null){
        try {
            localizedErrorMessage = messageSource.getMessage(fieldError.getCode(), fieldError.getArguments(), currentLocale);
        }catch (NoSuchMessageException noSuchMessageException){
            logger.debug(noSuchMessageException);
            noSuchMessageException.printStackTrace();
        }
    }
    //If the message was not found, return the most accurate field error code instead.
    //You can remove this check if you prefer to get the default error message.
    if (localizedErrorMessage.equals(fieldError.getDefaultMessage())) {
        String[] fieldErrorCodes = fieldError.getCodes();
        localizedErrorMessage = fieldErrorCodes[0];
    }

    return localizedErrorMessage;
}
 
开发者ID:xmomen,项目名称:easy-mybatis,代码行数:27,代码来源:RestExceptionHandler.java

示例9: interpolate

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
@Override
public String interpolate(final String s, final Context context, final Locale locale) {
    try {
        return this.messageSource.getMessage(s,
                context.getConstraintDescriptor().getAttributes().values().toArray(
                new Object[context.getConstraintDescriptor().getAttributes().size()]), locale);
    } catch (final NoSuchMessageException e) {
        return this.defaultMessageInterpolator.interpolate(s, context, locale);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:11,代码来源:SpringAwareMessageMessageInterpolator.java

示例10: get

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
public String get(String key, Object... args) {
    try {
        if (messageSource != null) {
            return messageSource.getMessage(key, args, key, LocaleUtil.getLocale());
        }
        return key;
    } catch (NoSuchMessageException e) {
        return key;
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:11,代码来源:MessageResourceServiceImpl.java

示例11: interpolate

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
public String interpolate(final String s, final Context context, final Locale locale) {
    try {
        return this.messageSource.getMessage(s,
                context.getConstraintDescriptor().getAttributes().values().toArray(
                new Object[context.getConstraintDescriptor().getAttributes().size()]), locale);
    } catch (final NoSuchMessageException e) {
        return this.defaultMessageInterpolator.interpolate(s, context, locale);
    }
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:10,代码来源:SpringAwareMessageMessageInterpolator.java

示例12: getMessage

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
protected String getMessage(String key, String defaultMessageKey, Object... parameters) {
    try {
        return this.messageSource.getMessage(key, parameters, LocaleContextHolder.getLocale());
    } catch (NoSuchMessageException e) {
        this.log.warn("No message key <{}> found, defaulting to <{}> ", key, defaultMessageKey);
        return this.getMessage(defaultMessageKey);
    }
}
 
开发者ID:e-gov,项目名称:TARA-Server,代码行数:9,代码来源:AbstractService.java

示例13: getI18nMessage

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
public String getI18nMessage(String key, Object[] args) {
    String msg = "";
    if (StringUtils.isBlank(key)) {
        log.warn("Missing i18n key, returning warning message");
        msg = "{ERROR: MISSING KEY}";
    } else {
        try {
            msg = messageSource.getMessage(key, args, null);
        } catch (NoSuchMessageException e) {
            log.warn("Invalid i18n key ("+key+") could not be found, returning warning message");
            msg = "{ERROR: INVALID KEY: "+key+"}";
        }
    }
    return msg;
}
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:16,代码来源:SakaiExternalLogicImpl.java

示例14: handleGetObject

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
/**
 * This implementation resolves the code in the MessageSource.
 * Returns {@code null} if the message could not be resolved.
 */
@Override
protected Object handleGetObject(String key) {
	try {
		return this.messageSource.getMessage(key, null, this.locale);
	}
	catch (NoSuchMessageException ex) {
		return null;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:MessageSourceResourceBundle.java

示例15: containsKey

import org.springframework.context.NoSuchMessageException; //导入依赖的package包/类
/**
 * This implementation checks whether the target MessageSource can resolve
 * a message for the given key, translating {@code NoSuchMessageException}
 * accordingly. In contrast to ResourceBundle's default implementation in
 * JDK 1.6, this does not rely on the capability to enumerate message keys.
 */
@Override
public boolean containsKey(String key) {
	try {
		this.messageSource.getMessage(key, null, this.locale);
		return true;
	}
	catch (NoSuchMessageException ex) {
		return false;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:MessageSourceResourceBundle.java


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