001
014
015 package com.liferay.portlet.currencyconverter;
016
017 import com.liferay.portlet.currencyconverter.model.Currency;
018 import com.liferay.portlet.currencyconverter.util.CurrencyUtil;
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 CurrencyPreferencesValidator implements PreferencesValidator {
031
032 public void validate(PortletPreferences preferences)
033 throws ValidatorException {
034
035 List<String> badSymbols = new ArrayList<String>();
036
037 String[] symbols = preferences.getValues("symbols", new String[0]);
038
039 for (int i = 0; i < symbols.length; i++) {
040 Currency currency = CurrencyUtil.getCurrency(symbols[i]);
041
042 if (currency == null) {
043 badSymbols.add(symbols[i]);
044 }
045 }
046
047 if (badSymbols.size() > 0) {
048 throw new ValidatorException(
049 "Failed to retrieve symbols", badSymbols);
050 }
051 }
052
053 }