1 16 19 20 package org.apache.pluto.core.impl; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Enumeration ; 25 26 import javax.portlet.PortletPreferences; 27 import javax.portlet.PreferencesValidator; 28 import javax.portlet.ValidatorException; 29 30 public class PreferencesValidatorImpl implements PreferencesValidator 31 { 32 33 public PreferencesValidatorImpl() 34 { 35 } 36 37 public void validate(PortletPreferences preferences) 38 throws ValidatorException 39 { 40 Collection failedKeys = new ArrayList (); 41 Enumeration names = preferences.getNames(); 42 43 String [] defValues = {"no values"}; 44 String [] values = null; 45 String key = null; 46 47 while (names.hasMoreElements()) 48 { 49 key = names.nextElement().toString(); 50 values = preferences.getValues(key, defValues); 51 52 if (values != null) { 54 for (int i=0; i<values.length;i++) 55 { 56 if (values[i] != null) { 58 if (!values[i].equalsIgnoreCase(values[i].trim())) 60 { 61 failedKeys.add(key); 62 i=values.length; 63 } 64 } 65 } 66 } 67 } 68 69 if (!failedKeys.isEmpty()) 70 { 71 throw new ValidatorException("One or more preferences do not comply with the validation criteria",failedKeys); 72 } 73 } 74 } 75 | Popular Tags |