@Override
public void validate(PortletPreferences prefs) throws ValidatorException {
//get prefs as strings
String max_items = prefs.getValue("max_items", Integer.toString(Constants.MAX_ITEMS));
String feed_url = prefs.getValue(PREF_FEED_URL, null);
//check readonly
boolean feedUrlIsLocked = prefs.isReadOnly(PREF_FEED_URL);
/**
* max_items
*/
IntegerValidator integerValidator = IntegerValidator.getInstance();
Integer maxItems = integerValidator.validate(max_items);
//check it's a number
if(maxItems == null) {
throw new ValidatorException("Invalid value, must be a number", Collections.singleton("max_items"));
}
//check greater than or equal to a minimum of 1
if(!integerValidator.minValue(maxItems, Constants.MIN_ITEMS)) {
throw new ValidatorException("Invalid number, must be greater than 0", Collections.singleton("max_items"));
}
/**
* feed_url
*/
//only validate if it's not readonly
if(!feedUrlIsLocked) {
String[] schemes = {"http","https"};
DetailedUrlValidator urlValidator = new DetailedUrlValidator(schemes);
//check not null
if(StringUtils.isBlank(feed_url)){
throw new ValidatorException("You must specify a URL for the RSS feed", Collections.singleton(PREF_FEED_URL));
}
//check valid scheme
if(!urlValidator.isValidScheme(feed_url)){
throw new ValidatorException("Invalid feed scheme. Must be one of: " + Arrays.toString(schemes), Collections.singleton(PREF_FEED_URL));
}
//check valid URL
if(!urlValidator.isValid(feed_url)){
throw new ValidatorException("Invalid feed URL", Collections.singleton(PREF_FEED_URL));
}
}
/**
* portlet_title not validated here as it is reasonable to allow blank entry. We deal with this later
*/
}
SimpleRSSPreferencesValidator.java 文件源码
java
阅读 19
收藏 0
点赞 0
评论 0
项目:sakai
作者:
评论列表
文章目录