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


Java KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX属性代码示例

本文整理汇总了Java中org.kuali.rice.krad.util.KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX属性的典型用法代码示例。如果您正苦于以下问题:Java KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX属性的具体用法?Java KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX怎么用?Java KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.kuali.rice.krad.util.KRADConstants的用法示例。


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

示例1: processMessagePlaceholders

/**
 * Checks a string property value for a message placeholder and if found the message is retrieved and updated
 * in the property value
 *
 * @param propertyValue string value to process for message placeholders
 * @param nestedBeanStack stack of bean definitions that contain the property, used to determine the namespace
 * and component for the message retrieval
 * @return String new value for the property (possibly modified from an external message)
 */
protected String processMessagePlaceholders(String propertyValue, Stack<BeanDefinitionHolder> nestedBeanStack) {
    String trimmedPropertyValue = StringUtils.stripStart(propertyValue, " ");
    if (StringUtils.isBlank(trimmedPropertyValue)) {
        return propertyValue;
    }

    String newPropertyValue = propertyValue;

    // first check for a replacement message key
    if (trimmedPropertyValue.startsWith(KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX) && StringUtils.contains(
            trimmedPropertyValue, KRADConstants.MESSAGE_KEY_PLACEHOLDER_SUFFIX)) {
        String messageKeyStr = StringUtils.substringBetween(trimmedPropertyValue,
                KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX, KRADConstants.MESSAGE_KEY_PLACEHOLDER_SUFFIX);

        // get any default specified value (given after the message key)
        String messageKeyWithPlaceholder = KRADConstants.MESSAGE_KEY_PLACEHOLDER_PREFIX + messageKeyStr +
                KRADConstants.MESSAGE_KEY_PLACEHOLDER_SUFFIX;

        String defaultPropertyValue = StringUtils.substringAfter(trimmedPropertyValue, messageKeyWithPlaceholder);

        // set the new property value to the message text (if found), or the default value if a message was not found
        // note the message text could be an empty string, in which case it will override the default
        String messageText = getMessageTextForKey(messageKeyStr, nestedBeanStack);
        if (messageText != null) {
            // if default value set then we need to merge any expressions
            if (StringUtils.isNotBlank(defaultPropertyValue)) {
                newPropertyValue = getMergedMessageText(messageText, defaultPropertyValue);
            } else {
                newPropertyValue = messageText;
            }
        } else {
            newPropertyValue = defaultPropertyValue;
        }
    }
    // now check for message keys within an expression
    else if (StringUtils.contains(trimmedPropertyValue, KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_PREFIX)) {
        String[] expressionMessageKeys = StringUtils.substringsBetween(newPropertyValue,
                KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_PREFIX,
                KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_SUFFIX);

        for (String expressionMessageKey : expressionMessageKeys) {
            String expressionMessageText = getMessageTextForKey(expressionMessageKey, nestedBeanStack);
            newPropertyValue = StringUtils.replace(newPropertyValue,
                    KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_PREFIX + expressionMessageKey +
                            KRADConstants.EXPRESSION_MESSAGE_PLACEHOLDER_SUFFIX, expressionMessageText);
        }
    }

    return newPropertyValue;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:59,代码来源:MessageBeanProcessor.java


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