final Map<String, IPortletPreference> targetPortletPreferences = this.getTargetPortletPreferences();
//Check if there is a base preference for the key
final Map<String, IPortletPreference> basePortletPreferences = this.getBasePortletPreferences();
final IPortletPreference basePreference = basePortletPreferences.get(key);
if (basePreference != null) {
if (this.isReadOnly(basePreference)) {
throw new ReadOnlyException("Preference '" + key + "' is read only");
}
//if the set value matches base value, delete any target pref
if (Arrays.equals(values, basePreference.getValues())) {
this.reset(key);
return;
}
}
IPortletPreference portletPreference = targetPortletPreferences.get(key);
//No target preference exists yet, create it and then update the composite map
if (portletPreference == null) {
portletPreference = new PortletPreferenceImpl(key, false, values != null ? values.clone() : null);
targetPortletPreferences.put(key, portletPreference);
final Map<String, IPortletPreference> compositePortletPreferences = this.getCompositePortletPreferences();
compositePortletPreferences.put(key, portletPreference);
this.modified = true;
}
//Update the existing preference if the values array is different
else if (!Arrays.equals(values, portletPreference.getValues())) {
portletPreference.setValues(values != null ? values.clone() : null);
this.modified = true;
}
}