001
014
015 package com.liferay.portlet.amazonrankings;
016
017 import com.liferay.portlet.amazonrankings.model.AmazonRankings;
018 import com.liferay.portlet.amazonrankings.util.AmazonRankingsUtil;
019
020 import java.util.ArrayList;
021 import java.util.List;
022
023 import javax.portlet.PortletPreferences;
024 import javax.portlet.PreferencesValidator;
025 import javax.portlet.ValidatorException;
026
027
030 public class AmazonRankingsPreferencesValidator
031 implements PreferencesValidator {
032
033 public void validate(PortletPreferences preferences)
034 throws ValidatorException {
035
036 List<String> badIsbns = new ArrayList<String>();
037
038 String[] isbns = preferences.getValues("isbns", new String[0]);
039
040 for (int i = 0; i < isbns.length; i++) {
041 AmazonRankings amazonRankings =
042 AmazonRankingsUtil.getAmazonRankings(isbns[i]);
043
044 if (amazonRankings == null) {
045 badIsbns.add(isbns[i]);
046 }
047 }
048
049 if (badIsbns.size() > 0) {
050 throw new ValidatorException(
051 "Failed to retrieve ISBNs", badIsbns);
052 }
053 }
054
055 }