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


Java LocalizationUtility.getLocalizedFieldName方法代码示例

本文整理汇总了Java中net.sourceforge.stripes.localization.LocalizationUtility.getLocalizedFieldName方法的典型用法代码示例。如果您正苦于以下问题:Java LocalizationUtility.getLocalizedFieldName方法的具体用法?Java LocalizationUtility.getLocalizedFieldName怎么用?Java LocalizationUtility.getLocalizedFieldName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sourceforge.stripes.localization.LocalizationUtility的用法示例。


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

示例1: resolveFieldName

import net.sourceforge.stripes.localization.LocalizationUtility; //导入方法依赖的package包/类
/**
 * Takes the form field name supplied and tries first to resolve a String in the locale
 * specific bundle for the field name, and if that fails, will try to make a semi-friendly
 * name by parsing the form field name.  The result is stored in replacementParameters[0]
 * for message template parameter replacement.
 */
protected void resolveFieldName(Locale locale) {
    log.debug("Looking up localized field name with messageKey: ", this.fieldNameKey);

    if (this.fieldNameKey == null) {
        getReplacementParameters()[0] = "FIELD NAME NOT SUPPLIED IN CODE";
    }
    else {
        getReplacementParameters()[0] =
                LocalizationUtility.getLocalizedFieldName(this.fieldNameKey,
                                                          this.actionPath,
                                                          this.beanclass,
                                                          locale);

        if (getReplacementParameters()[0] == null) {
            getReplacementParameters()[0] =
                    LocalizationUtility.makePseudoFriendlyName(this.fieldNameKey);
        }
    }
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:26,代码来源:SimpleError.java

示例2: getLocalizedFieldName

import net.sourceforge.stripes.localization.LocalizationUtility; //导入方法依赖的package包/类
/**
 * Attempts to fetch a "field name" resource from the localization bundle. Delegates
 * to {@link LocalizationUtility#getLocalizedFieldName(String, String, Class, java.util.Locale)}
 *
 * @param name the field name or resource to look up
 * @return the localized String corresponding to the name provided
 * @throws StripesJspException
 */
protected String getLocalizedFieldName(final String name) throws StripesJspException {
    Locale locale = getPageContext().getRequest().getLocale();
    FormTag form = null;

    try { form = getParentFormTag(); }
    catch (StripesJspException sje) { /* Do nothing. */}

    String actionPath = null;
    Class<? extends ActionBean> beanClass = null;

    if (form != null) {
        actionPath = form.getAction();
        beanClass = form.getActionBeanClass();
    }
    else {
        ActionBean mainBean = (ActionBean) getPageContext().getRequest().getAttribute(StripesConstants.REQ_ATTR_ACTION_BEAN);
        if (mainBean != null) {
            beanClass = mainBean.getClass();
        }
    }
    return LocalizationUtility.getLocalizedFieldName(name, actionPath, beanClass, locale);
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:31,代码来源:InputTagSupport.java

示例3: doStartTag

import net.sourceforge.stripes.localization.LocalizationUtility; //导入方法依赖的package包/类
/**
 * Iterates through the collection and generates the list of Entry objects that can then
 * be sorted and rendered into options. It is assumed that each element in the collection
 * has non-null values for the properties specified for generating the label and value.
 *
 * @return SKIP_BODY in all cases
 * @throws JspException if either the label or value attributes specify properties that are
 *         not present on the beans in the collection
 */
@Override
public int doStartTag() throws JspException {
  if (this.collection == null)
    return SKIP_BODY;

    String labelProperty = getLabel();
    String valueProperty = getValue();
    String groupProperty = getGroup();


    try {
        Locale locale = getPageContext().getRequest().getLocale();
        boolean attemptToLocalizeLabels = isAttemptToLocalizeLabels();

        for (Object item : this.collection) {
            Class<? extends Object> clazz = item.getClass();

            // Lookup the bean properties for the label, value and group
            Object label = (labelProperty == null) ? item : BeanUtil.getPropertyValue(labelProperty, item);
            Object value = (valueProperty == null) ? item : BeanUtil.getPropertyValue(valueProperty, item);
            Object group = (groupProperty == null) ? null : BeanUtil.getPropertyValue(groupProperty, item);

            if (attemptToLocalizeLabels) {
                // Try to localize the label
                String packageName = clazz.getPackage() == null ? "" : clazz.getPackage().getName();
                String simpleName = LocalizationUtility.getSimpleName(clazz);
                String localizedLabel = null;
                if (label != null) {
                    localizedLabel = LocalizationUtility.getLocalizedFieldName
                        (simpleName + "."  + label, packageName, null, locale);
                }
                if (localizedLabel == null && value != null) {
                    localizedLabel = LocalizationUtility.getLocalizedFieldName
                        (simpleName + "."  + value, packageName, null, locale);
                }
                if (localizedLabel != null) label = localizedLabel;

                // Try to localize the group
                if (group != null) {
                    String localizedGroup = LocalizationUtility.getLocalizedFieldName(
                        simpleName + "." + group, packageName, null, locale);
                    if (localizedGroup != null) group = localizedGroup;
                }
            }
            addEntry(item, label, value, group);
        }
    }
    catch (ExpressionException ee) {
        throw new StripesJspException("A problem occurred generating an options-collection. " +
            "Most likely either [" + labelProperty + "] or ["+ valueProperty + "] is not a " +
            "valid property of the beans in the collection: " + this.collection, ee);
    }

    return SKIP_BODY;
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:65,代码来源:InputOptionsCollectionTag.java


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