PreferencesValidatorImpl.java 文件源码

java
阅读 115 收藏 0 点赞 0 评论 0

项目:portals-pluto 作者:
public void validate(PortletPreferences preferences)
throws ValidatorException {
    validateInvoked++;
    String value = preferences.getValue(CHECK_VALIDATOR_COUNT, null);
    if (value != null && value.equalsIgnoreCase("true")) {
        checkValidatorCount();
    }

    //
    // TODO: Determine why we use this - I seem to remember it's a
    //   spec requirement, and fix it so that we don't have issues
    //   anymore.  When enabled, all preferences fail in testsuite.
    //
    final String[] DEFAULT_VALUES = new String[] { "no values" };
    Collection<String> failedNames = new ArrayList<String>();
    for (Enumeration<String> en = preferences.getNames(); 
            en.hasMoreElements(); ) {
        String name = (String) en.nextElement();
        String[] values = preferences.getValues(name, DEFAULT_VALUES);
        if (values != null) { // null values are allowed
            for (int i = 0; i < values.length; i++) {
                if (values[i] != null) { // null values are allowed
                    // Validate that the preferences do not
                    //   start or end with white spaces.
                    if (!values[i].equals(values[i].trim())) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Validation failed: "
                                    + "value has white spaces: "
                                    + "name=" + name
                                    + "; value=|" + values[i] + "|");
                        }
                        failedNames.add(name);
                    }
                }
            }
        }
    }

    if (!failedNames.isEmpty()) {
        throw new ValidatorException(
                "One or more preferences do not pass the validation.",
                failedNames);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号