weaver 2003/08/01 13:01:50 Modified: commons/src/java/org/apache/jetspeed/om/api PortletPreferencesImpl.java Log: Concrete Impl for user preferences Revision Changes Path 1.2 +105 -18 jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/om/api/PortletPreferencesImpl.java Index: PortletPreferencesImpl.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/om/api/PortletPreferencesImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PortletPreferencesImpl.java 30 Jul 2003 18:30:15 -0000 1.1 +++ PortletPreferencesImpl.java 1 Aug 2003 20:01:50 -0000 1.2 @@ -54,16 +54,19 @@ package org.apache.jetspeed.om.api; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; import java.util.Enumeration; +import java.util.Set; import javax.portlet.PortletPreferences; import javax.portlet.UnmodifiableException; import javax.portlet.ValidatorException; +import org.apache.jetspeed.om.common.PreferenceComposite; import org.apache.jetspeed.om.common.PreferenceSetImpl; import org.apache.jetspeed.om.common.PreferenceSetComposite; import org.apache.pluto.om.common.Preference; -import org.apache.pluto.om.common.PreferenceSet; /** * PortletPreferencesImpl @@ -82,7 +85,8 @@ { private static final String NULL_KEY_MSG = "The preference \"key\" argument cannot be null"; - private PreferenceSet registryPreferences; + private PreferenceSetComposite defaultPreferences; + private PreferenceSetComposite originalPreferences; /** * Creates an instance of PortletPreferencesImpl using the @@ -94,10 +98,24 @@ * @param prefSet PreferenceSet from the registry that will be used as a * base for the PortletPreferenceImpl. */ - public PortletPreferencesImpl(PreferenceSet prefSet) + public PortletPreferencesImpl(PreferenceSetComposite defaultPreferences) + { + this(); + this.defaultPreferences = defaultPreferences; + } + + public PortletPreferencesImpl() { super(); - registryPreferences = prefSet; + } + + /** + * + * @param defaultPreferences + */ + public void setDefaultPreferences(PreferenceSetComposite defaultPreferences) + { + this.defaultPreferences = defaultPreferences; } /** @@ -129,7 +147,7 @@ throw new IllegalArgumentException(NULL_KEY_MSG); } - Preference pref = registryPreferences.get(key); + Preference pref = defaultPreferences.get(key); if (pref == null || pref.isModifiable()) { return true; @@ -168,16 +186,21 @@ throw new IllegalArgumentException(NULL_KEY_MSG); } - Preference pref = registryPreferences.get(key); - if (pref != null) + PreferenceComposite pref = (PreferenceComposite) get(key); + + if ((pref == null || pref.getValueAt(0) == null) + && defaultPreferences.get(key) != null + && defaultPreferences.get(key).getValues() != null) { - return def; + pref = (PreferenceComposite) defaultPreferences.get(key); } - else if (pref.getValues().hasNext()) + + if (pref != null) { + return pref.getValueAt(0); } - return null; + return def; } /** @@ -187,8 +210,24 @@ */ public String[] getValues(String key, String[] def) { - // TODO Auto-generated method stub - return null; + if (key == null) + { + throw new IllegalArgumentException(NULL_KEY_MSG); + } + + PreferenceComposite pref = (PreferenceComposite) get(key); + + if (pref == null) + { + pref = (PreferenceComposite) defaultPreferences.get(key); + } + + if (pref != null) + { + return pref.getValueArray(); + } + + return def; } /** @@ -196,7 +235,24 @@ */ public void setValue(String key, String value) throws UnmodifiableException { - // TODO Auto-generated method stub + if (key == null) + { + throw new IllegalArgumentException(NULL_KEY_MSG); + } + + if (!isModifiable(key)) + { + throw new UnmodifiableException("Preference \"" + key + "\" is not a modifiable preference attribute."); + } + + PreferenceComposite pref = (PreferenceComposite) get(key); + + if (pref == null) + { + pref = new PortletPreference(); + } + + pref.setValueAt(0, value); } @@ -205,7 +261,24 @@ */ public void setValues(String key, String[] values) throws UnmodifiableException { - // TODO Auto-generated method stub + if (key == null) + { + throw new IllegalArgumentException(NULL_KEY_MSG); + } + + if (!isModifiable(key)) + { + throw new UnmodifiableException("Preference \"" + key + "\" is not a modifiable preference attribute."); + } + + PreferenceComposite pref = (PreferenceComposite) get(key); + + if (pref == null) + { + pref = new PortletPreference(); + } + + pref.setValues(Arrays.asList(values)); } @@ -214,8 +287,11 @@ */ public Enumeration getNames() { - // TODO Auto-generated method stub - return null; + Set dftNames = defaultPreferences.getPreferenceNames(); + Set prefNames = super.getPreferenceNames(); + prefNames.addAll(dftNames); + + return Collections.enumeration(prefNames); } /** @@ -223,7 +299,18 @@ */ public void reset(String key) throws UnmodifiableException { - // TODO Auto-generated method stub + if (key == null) + { + throw new IllegalArgumentException(NULL_KEY_MSG); + } + + if (!isModifiable(key)) + { + throw new UnmodifiableException("Preference \"" + key + "\" is not a modifiable preference attribute."); + } + + // This will automatically cause a fall back to stored defaults + remove(key); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]