1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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)
53 {
54 for (int i=0; i<values.length;i++)
55 {
56 if (values[i] != null)
57 {
58
59 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 }