1 48 49 package com.caucho.portal.generic; 50 51 import javax.portlet.PortletPreferences; 52 import javax.portlet.PreferencesValidator; 53 import javax.portlet.ReadOnlyException; 54 import javax.portlet.ValidatorException; 55 import java.io.IOException ; 56 import java.util.ArrayList ; 57 import java.util.Collections ; 58 import java.util.Enumeration ; 59 import java.util.LinkedHashMap ; 60 import java.util.Map ; 61 62 public class GenericPortletPreferences implements PortletPreferences 63 { 64 Map <String , PortletPreference> _preferenceMap; 65 ArrayList <PreferencesValidator> _preferencesValidators; 66 67 public void addPreference(PortletPreference preference) 68 { 69 if (_preferenceMap == null) 70 _preferenceMap = new LinkedHashMap <String , PortletPreference>(); 71 72 _preferenceMap.put(preference.getName(), preference); 73 } 74 75 public void addPreferencesValidator(String className) 76 { 77 try { 78 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 79 Class cl = Class.forName(className, false, loader); 80 PreferencesValidator validator = (PreferencesValidator) cl.newInstance(); 81 82 if (_preferencesValidators == null) 83 _preferencesValidators = new ArrayList <PreferencesValidator>(); 84 85 _preferencesValidators.add(validator); 86 } catch (Exception ex) { 87 throw new IllegalArgumentException (ex); 88 } 89 90 } 91 92 public ArrayList <PreferencesValidator> getPreferencesValidators() 93 { 94 return _preferencesValidators; 95 } 96 97 public boolean isReadOnly(String key) 98 { 99 if (_preferenceMap == null) 100 return false; 101 102 PortletPreference preference = _preferenceMap.get(key); 103 104 if (preference == null) 105 return false; 106 107 return preference.isReadOnly(); 108 } 109 110 public String getValue(String key, String def) 111 { 112 if (_preferenceMap == null) 113 return def; 114 115 PortletPreference preference = _preferenceMap.get(key); 116 117 if (preference == null) 118 return def; 119 120 return preference.getValue(); 121 } 122 123 public String [] getValues(String key, String [] def) 124 { 125 if (_preferenceMap == null) 126 return def; 127 128 PortletPreference preference = _preferenceMap.get(key); 129 130 if (preference == null) 131 return def; 132 133 return preference.getValues(); 134 } 135 136 public Enumeration getNames() 137 { 138 if (_preferenceMap == null) 139 return Collections.enumeration(Collections.EMPTY_LIST); 140 else 141 return Collections.enumeration(_preferenceMap.keySet()); 142 } 143 144 public Map getMap() 145 { 146 return _preferenceMap; 147 } 148 149 public void reset(String key) 150 throws ReadOnlyException 151 { 152 throw new UnsupportedOperationException (); 153 } 154 155 public void setValue(String key, String value) 156 throws ReadOnlyException 157 { 158 throw new UnsupportedOperationException (); 159 } 160 161 public void setValues(String key, String [] values) 162 throws ReadOnlyException 163 { 164 throw new UnsupportedOperationException (); 165 } 166 167 public void store() 168 throws IOException , ValidatorException 169 { 170 throw new UnsupportedOperationException (); 171 } 172 } 173 174 175 176 177 | Popular Tags |