當前位置: 首頁>>代碼示例>>Java>>正文


Java MessageSource.getMessage方法代碼示例

本文整理匯總了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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:AbstractMessageSource.java

示例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);
    }
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:27,代碼來源:MessageSourceUtil.java

示例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);
    }
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:34,代碼來源:MessageSourceUtil.java

示例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);
    }
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:28,代碼來源:MessageSourceUtil.java

示例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);
    }
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:35,代碼來源:MessageSourceUtil.java

示例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;
}
 
開發者ID:fier-liu,項目名稱:FCat,代碼行數:18,代碼來源:MessageSourceUtil.java

示例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;
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:37,代碼來源:MessageUtils.java

示例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;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:40,代碼來源:OutputFactory.java

示例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
}
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:31,代碼來源:LearningDesignService.java

示例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;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:Patch0012FixWorkspaceNames.java

示例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;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:Patch0016FixWorkspacePublicFolder.java

示例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);
}
 
開發者ID:nortal,項目名稱:cas-modules,代碼行數:7,代碼來源:Message.java


注:本文中的org.springframework.context.MessageSource.getMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。