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 @Override
033 public void validate(PortletPreferences preferences)
034 throws ValidatorException {
035
036 List<String> badSymbols = new ArrayList<String>();
037
038 String[] symbols = preferences.getValues("symbols", new String[0]);
039
040 for (int i = 0; i < symbols.length; i++) {
041 Currency currency = CurrencyUtil.getCurrency(symbols[i]);
042
043 if (currency == null) {
044 badSymbols.add(symbols[i]);
045 }
046 }
047
048 if (badSymbols.size() > 0) {
049 throw new ValidatorException(
050 "Failed to retrieve symbols", badSymbols);
051 }
052 }
053
054 }