1 5 package org.exoplatform.services.portletcontainer.pci.model; 6 7 import java.io.Serializable ; 8 import java.util.*; 9 import javax.portlet.* ; 10 import org.exoplatform.commons.utils.ExoEnumeration; 11 12 18 public class ExoPortletPreferences extends HashMap implements PortletPreferences, Serializable { 19 private String preferencesValidator ; 20 21 public Map getMap() { return this ; } 22 23 public boolean isReadOnly(String key) { 24 if(key == null) throw new IllegalArgumentException ("preference name is null") ; 25 Preference preference = (Preference) get(key) ; 26 if(preference == null) return false ; 27 return preference.isReadOnly() ; 28 } 29 30 public java.lang.String getValue(String key, String def) { 31 if(key == null) throw new IllegalArgumentException ("preference name is null") ; 32 Preference preference = (Preference) get(key) ; 33 return preference.getValue(def) ; 34 } 35 36 public String [] getValues(String key, String [] def) { 37 if(key == null) throw new IllegalArgumentException ("preference name is null") ; 38 Preference preference = (Preference) get(key) ; 39 if(preference == null) return def ; 40 return preference.getValues(key, def) ; 41 } 42 43 public void setValue(String key, String value) throws ReadOnlyException { 44 if(key == null) throw new IllegalArgumentException ("preference name is null") ; 45 Preference preference = (Preference) get(key) ; 46 if(preference == null) { 47 preference = new Preference() ; 48 preference.setName(key) ; 49 put(key, preference) ; 50 } 51 if(preference.isReadOnly()) throw new ReadOnlyException("This preference is readonly") ; 52 if(value == null) return ; 53 preference.addValue(value) ; 54 } 55 56 public void setValues(String key, String [] value) throws ReadOnlyException { 57 if(key == null) throw new IllegalArgumentException ("preference name is null") ; 58 Preference preference = (Preference) get(key) ; 59 if(preference == null) { 60 preference = new Preference() ; 61 preference.setName(key) ; 62 put(key, preference) ; 63 } 64 if(preference.isReadOnly()) throw new ReadOnlyException("This preference is readonly") ; 65 if(value == null) return ; 66 ArrayList list = new ArrayList() ; 67 for(int i = 0; i < value.length; i++) { 68 list.add(value[i]) ; 69 } 70 preference.setValues(list) ; 71 } 72 73 public Enumeration getNames() { 74 return new ExoEnumeration(keySet().iterator()) ; 75 } 76 77 public void reset(java.lang.String key) throws ReadOnlyException { 78 if(key == null) throw new IllegalArgumentException ("preference name is null") ; 79 Preference preference = (Preference) get(key) ; 80 if(preference == null) return ; 81 if(preference.isReadOnly()) throw new ReadOnlyException("This preference is readonly") ; 82 preference.clear() ; 83 } 84 85 public void store() throws java.io.IOException , ValidatorException { 86 throw new Error ("NOT SUPPORT") ; 87 } 88 89 public void addPreference(Preference pref) { 90 put(pref.getName(), pref) ; 91 } 92 93 public String getPreferencesValidator() { 94 return preferencesValidator; 95 } 96 97 public void setPreferencesValidator(String preferencesValidator) { 98 this.preferencesValidator = preferencesValidator; 99 } 100 } | Popular Tags |