本文整理汇总了Java中org.springframework.context.MessageSource.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java MessageSource.getMessage方法的具体用法?Java MessageSource.getMessage怎么用?Java MessageSource.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.context.MessageSource
的用法示例。
在下文中一共展示了MessageSource.getMessage方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMessageFromParent
import org.springframework.context.MessageSource; //导入方法依赖的package包/类
/**
* Try to retrieve the given message from the parent MessageSource, if any.
* @param code the code to lookup up, such as 'calculator.noRateSet'
* @param args array of arguments that will be filled in for params
* within the message
* @param locale the Locale in which to do the lookup
* @return the resolved message, or {@code null} if not found
* @see #getParentMessageSource()
*/
protected String getMessageFromParent(String code, Object[] args, Locale locale) {
MessageSource parent = getParentMessageSource();
if (parent != null) {
if (parent instanceof AbstractMessageSource) {
// Call internal method to avoid getting the default code back
// in case of "useCodeAsDefaultMessage" being activated.
return ((AbstractMessageSource) parent).getMessageInternal(code, args, locale);
}
else {
// Check parent MessageSource, returning null if not found there.
return parent.getMessage(code, args, null, locale);
}
}
// Not found in parent either.
return null;
}
示例2: getChinese
import org.springframework.context.MessageSource; //导入方法依赖的package包/类
/**
* 查找错误消息
*
* @param source
* @param code
* @param params
* @param defaultMsg
* @return
*/
public static String getChinese(MessageSource source, String code, Object[] params, String defaultMsg) {
if (Check.NuNObj(source)) {
throw new IllegalArgumentException("message source is null");
}
if (Check.NuNStrStrict(code)) {
throw new IllegalArgumentException("code is empty");
}
//如果没有object 默认设置为空数组
if (Check.NuNObj(params)) {
params = new Object[]{};
}
if (Check.NuNStrStrict(defaultMsg)) {
return source.getMessage(code, params, Locale.SIMPLIFIED_CHINESE);
} else {
return source.getMessage(code, params, defaultMsg, Locale.SIMPLIFIED_CHINESE);
}
}
示例3: getIntMessage
import org.springframework.context.MessageSource; //导入方法依赖的package包/类
/**
* 查找错误消息
*
* @param source
* @param code
* @param params
* @param defaultMsg
* @return
*/
public static int getIntMessage(MessageSource source, String code, Object[] params, String defaultMsg) {
if (Check.NuNObj(source)) {
throw new IllegalArgumentException("message source is null");
}
if (Check.NuNStrStrict(code)) {
throw new IllegalArgumentException("code is empty");
}
//如果没有object 默认设置为空数组
if (Check.NuNObj(params)) {
params = new Object[]{};
}
String message = null;
if (Check.NuNStrStrict(defaultMsg)) {
message = source.getMessage(code, params, Locale.SIMPLIFIED_CHINESE);
} else {
message = source.getMessage(code, params, defaultMsg, Locale.SIMPLIFIED_CHINESE);
}
if (Check.NuNStrStrict(message)) {
throw new NumberFormatException("message is empty");
} else {
return Integer.valueOf(message);
}
}
示例4: getChinese
import org.springframework.context.MessageSource; //导入方法依赖的package包/类
/**
* 查找错误消息
*
* @param source
* @param code
* @param params
* @param defaultMsg
*
* @return
*/
public static String getChinese(MessageSource source, String code, Object[] params, String defaultMsg) {
if (Check.isNull(source)) {
throw new IllegalArgumentException("message source is null");
}
if (Check.isNullOrEmpty(code)) {
throw new IllegalArgumentException("code is empty");
}
//如果没有object 默认设置为空数组
if (Check.isNull(params)) {
params = new Object[]{};
}
if (Check.isNullOrEmpty(defaultMsg)) {
return source.getMessage(code, params, Locale.SIMPLIFIED_CHINESE);
} else {
return source.getMessage(code, params, defaultMsg, Locale.SIMPLIFIED_CHINESE);
}
}
示例5: getIntMessage
import org.springframework.context.MessageSource; //导入方法依赖的package包/类
/**
* 查找错误消息
*
* @param source
* @param code
* @param params
* @param defaultMsg
*
* @return
*/
public static int getIntMessage(MessageSource source, String code, Object[] params, String defaultMsg) {
if (Check.isNull(source)) {
throw new IllegalArgumentException("message source is null");
}
if (Check.isNullOrEmpty(code)) {
throw new IllegalArgumentException("code is empty");
}
//如果没有object 默认设置为空数组
if (Check.isNull(params)) {
params = new Object[]{};
}
String message = null;
if (Check.isNullOrEmpty(defaultMsg)) {
message = source.getMessage(code, params, Locale.SIMPLIFIED_CHINESE);
} else {
message = source.getMessage(code, params, defaultMsg, Locale.SIMPLIFIED_CHINESE);
}
if (Check.isNullOrEmpty(message)) {
throw new NumberFormatException("message is empty");
} else {
return Integer.valueOf(message);
}
}
示例6: getMessage
import org.springframework.context.MessageSource; //导入方法依赖的package包/类
public static String getMessage(MessageSource messageSource, String code, Object[] args, Locale locale) {
if (LOG.isDebugEnabled()) {
LOG.debug("getMessage(MessageSource messageSource, String code, Object[] args, Locale locale)");
LOG.debug("code=" + code + " args=" + args + " locale=" + locale);
}
String result = "";
try {
result = messageSource.getMessage(code, args, "", locale);// defaultMessage=""
} catch (Exception e) {
LOG.debug("Exception e code=" + code + " args=" + args + " locale=" + locale, e);
}
if (LOG.isDebugEnabled()) {
LOG.debug("result=" + result);
}
return result;
}
示例7: writeAfterThrowingApplicationMessage
import org.springframework.context.MessageSource; //导入方法依赖的package包/类
public static Message writeAfterThrowingApplicationMessage(Exception e,
User user, String type, MessageSource messageSource,
Locale locale) {
Message message = new Message();
String body = "";
message.setType(Message.ERROR);
message.setAuthor(user);
switch (type) {
case "CREATE":
body = messageSource.getMessage("app.create.error", null, locale);
break;
case "UPDATE":
body = "Error update application - " + e.getLocalizedMessage();
break;
case "DELETE":
body = "Error delete application - " + e.getLocalizedMessage();
break;
case "START":
body = "Error start application - " + e.getLocalizedMessage();
break;
case "STOP":
body = "Error stop application - " + e.getLocalizedMessage();
break;
case "RESTART":
body = "Error restart application - " + e.getLocalizedMessage();
break;
default:
body = "Error : unkown error";
break;
}
message.setEvent(body);
return message;
}
示例8: getI18NText
import org.springframework.context.MessageSource; //导入方法依赖的package包/类
/**
* Get the I18N description for this key. If the tool has supplied a messageService, then this is used to look up
* the key and hence get the text. Otherwise if the tool has supplied a I18N languageFilename then it is accessed
* via the shared toolActMessageService. If neither are supplied or the key is not found, then any "." in the name
* are converted to space and this is used as the return value.
*
* This is normally used to get the description for a definition, in whic case the key should be in the format
* output.desc.[definition name], key = definition name and addPrefix = true. For example a definition name of
* "learner.mark" becomes output.desc.learner.mark.
*
* If you want to use this to get an arbitrary string from the I18N files, then set addPrefix = false and the
* output.desc will not be added to the beginning.
*/
protected String getI18NText(String key, boolean addPrefix) {
String translatedText = null;
MessageSource tmpMsgSource = getMsgSource();
if (tmpMsgSource != null) {
if (addPrefix) {
key = KEY_PREFIX + key;
}
Locale locale = LocaleContextHolder.getLocale();
try {
translatedText = tmpMsgSource.getMessage(key, null, locale);
} catch (NoSuchMessageException e) {
log.warn("Unable to internationalise the text for key " + key
+ " as no matching key found in the msgSource");
}
} else {
log.warn("Unable to internationalise the text for key " + key
+ " as no matching key found in the msgSource. The tool's OutputDefinition factory needs to set either (a) messageSource or (b) loadedMessageSourceService and languageFilename.");
}
if (translatedText == null || translatedText.length() == 0) {
translatedText = key.replace('.', ' ');
}
return translatedText;
}
示例9: internationaliseActivityTitle
import org.springframework.context.MessageSource; //导入方法依赖的package包/类
@Override
public String internationaliseActivityTitle(Long learningLibraryID) {
ToolActivity templateActivity = (ToolActivity) activityDAO.getTemplateActivityByLibraryID(learningLibraryID);
if (templateActivity != null) {
Locale locale = LocaleContextHolder.getLocale();
String languageFilename = templateActivity.getLanguageFile();
if (languageFilename != null) {
MessageSource toolMessageSource = toolActMessageService.getMessageService(languageFilename);
if (toolMessageSource != null) {
String title = toolMessageSource.getMessage(Activity.I18N_TITLE, null, templateActivity.getTitle(),
locale);
if (title != null && title.trim().length() > 0) {
return title;
}
} else {
log.warn("Unable to internationalise the library activity " + templateActivity.getTitle()
+ " message file " + templateActivity.getLanguageFile()
+ ". Activity Message source not available");
}
}
}
if (templateActivity.getTitle() != null && templateActivity.getTitle().trim().length() > 0) {
return templateActivity.getTitle();
} else {
return "Untitled"; // should never get here - just return something in case there is a bug. A blank title affect the layout of the main page
}
}
示例10: getI18nMessage
import org.springframework.context.MessageSource; //导入方法依赖的package包/类
private String getI18nMessage(Connection conn) throws MigrationException {
// get spring bean
ApplicationContext context = new ClassPathXmlApplicationContext("org/lamsfoundation/lams/messageContext.xml");
MessageService messageService = (MessageService) context.getBean("commonMessageService");
// get server locale
String defaultLocale = "en_AU";
String getDefaultLocaleStmt = "select config_value from lams_configuration where config_key='ServerLanguage'";
try {
PreparedStatement query = conn.prepareStatement(getDefaultLocaleStmt);
ResultSet results = query.executeQuery();
while (results.next()) {
defaultLocale = results.getString("config_value");
}
} catch (Exception e) {
throw new MigrationException("Problem running update; ", e);
}
String[] tokenisedLocale = defaultLocale.split("_");
Locale locale = new Locale(tokenisedLocale[0], tokenisedLocale[1]);
// get i18n'd message for text 'run sequences'
MessageSource messageSource = messageService.getMessageSource();
String i18nMessage = messageSource.getMessage("runsequences.folder.name", new Object[] { "" }, locale);
if (i18nMessage != null && i18nMessage.startsWith("???")) {
// default to English if not present
return " Run Sequences";
}
return i18nMessage;
}
示例11: getI18nMessage
import org.springframework.context.MessageSource; //导入方法依赖的package包/类
private String getI18nMessage(Connection conn) throws MigrationException {
// get spring bean
ApplicationContext context = new ClassPathXmlApplicationContext("org/lamsfoundation/lams/messageContext.xml");
MessageService messageService = (MessageService) context.getBean("commonMessageService");
// get server locale
String defaultLocale = "en_AU";
String getDefaultLocaleStmt = "select config_value from lams_configuration where config_key='ServerLanguage'";
try {
PreparedStatement query = conn.prepareStatement(getDefaultLocaleStmt);
ResultSet results = query.executeQuery();
while (results.next()) {
defaultLocale = results.getString("config_value");
}
} catch (Exception e) {
throw new MigrationException("Problem running update; ", e);
}
String[] tokenisedLocale = defaultLocale.split("_");
Locale locale = new Locale(tokenisedLocale[0], tokenisedLocale[1]);
// get i18n'd message for text 'run sequences'
MessageSource messageSource = messageService.getMessageSource();
String i18nMessage = messageSource.getMessage("public.folder.name", null, locale);
if (i18nMessage != null && i18nMessage.startsWith("???")) {
// default to English if not present
return "Public Folder";
}
return i18nMessage;
}
示例12: getMessage
import org.springframework.context.MessageSource; //导入方法依赖的package包/类
/**
* Finds the messageText.
*/
public static String getMessage(MessageSource messageSource, Locale locale, MessageInterface message){
return messageSource.getMessage(new Message(message), locale);
}