Interface PortletPreferences
-
public interface PortletPreferencesThePortletPreferencesinterface allows the portlet to store configuration data. It is not the purpose of this interface to replace general purpose databases.There are two different types of preferences:
- modifiable preferences - these preferences can be changed by the
portlet in any standard portlet mode (
EDIT, HELP, VIEW). Per default every preference is modifiable. - read-only preferences - these preferences cannot be changed by the
portlet in any standard portlet mode, but may be changed by administrative modes.
Preferences are read-only, if the are defined in the
deployment descriptor with
read-onlyset totrue, or if the portlet container restricts write access.
Changes are persisted when the
storemethod is called. Thestoremethod can only be invoked within the scope of aprocessActioncall. Changes that are not persisted are discarded when theprocessActionorrendermethod ends. - modifiable preferences - these preferences can be changed by the
portlet in any standard portlet mode (
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Map<String,String[]>getMap()Returns aMapof the preferences.Enumeration<String>getNames()Returns all of the keys that have an associated value, or an emptyEnumerationif no keys are available.StringgetValue(String key, String def)Returns the first String value associated with the specified key of this preference.String[]getValues(String key, String[] def)Returns the String array value associated with the specified key in this preference.booleanisReadOnly(String key)Returns true, if the value of this key is defined as read-only and thus cannot be modified by the user.voidreset(String key)Resets or removes the value associated with the specified key.voidsetValue(String key, String value)Associates the specified String value with the specified key in this preference.voidsetValues(String key, String... values)Sets a multi-valued String preference for the specified key.voidstore()Commits all changes made to the preferences via thesetmethods in the persistent store.
-
-
-
Method Detail
-
isReadOnly
boolean isReadOnly(String key)
Returns true, if the value of this key is defined as read-only and thus cannot be modified by the user.Modifiable preferences can be changed by the portlet in any standard portlet mode (
EDIT, HELP, VIEW). Per default every preference is modifiable.Read-only preferences cannot be changed by the portlet in any standard portlet mode, but inside of custom modes, like the
CONFIGmode, it may be allowed changing them.Preferences are read-only, if they are defined in the deployment descriptor with
read-onlyset totrue, or if the portlet container restricts write access.Note that even if this call returns
falseand the preference key is modifiable in general it does not mean that it is modifiable in the scope of the current request, e.g. if this request is a render request.- Parameters:
key- the key name- Returns:
- false, if the value of this key can be changed, or if the key is not known
- Throws:
IllegalArgumentException- ifkeyisnull.
-
getValue
String getValue(String key, String def)
Returns the first String value associated with the specified key of this preference. If there is one or more preference values associated with the given key it returns the first associated value. If there are no preference values associated with the given key, or the backing preference database is unavailable, it returns the given default value. Anullvalue is treated as a non-existent value.- Parameters:
key- key for which the associated value is to be returneddef- the value to be returned in the event that there is no value available associated with thiskey.- Returns:
- the value associated with
key, ordefif no value is associated withkey, or the backing store is inaccessible. - Throws:
IllegalArgumentException- ifkeyisnull. (Anullvalue fordefis permitted.)- See Also:
getValues(String, String[])
-
getValues
String[] getValues(String key, String[] def)
Returns the String array value associated with the specified key in this preference.Returns the specified default if there is no value associated with the key, or if the backing store is inaccessible. A
nullvalue is treated as a non-existent value.If the implementation supports stored defaults and such a default exists and is accessible, it is used in favor of the specified default.
- Parameters:
key- key for which associated value is to be returned.def- the value to be returned in the event that this preference node has no value associated withkeyor the associated value cannot be interpreted as a String array, or the backing store is inaccessible.- Returns:
- the String array value associated with
key, ordefif the associated value does not exist. - Throws:
IllegalArgumentException- ifkeyisnull. (Anullvalue fordefis permitted.)- See Also:
getValue(String,String)
-
setValue
void setValue(String key, String value) throws ReadOnlyException
Associates the specified String value with the specified key in this preference.The key cannot be
null, butnullvalues for the value parameter are allowed.If the same key contained already a
StringorString[]value it must be replaced by the new value.- Parameters:
key- key with which the specified value is to be associated.value- value to be associated with the specified key.- Throws:
ReadOnlyException- if this preference cannot be modified for this requestIllegalArgumentException- if key isnull, orkey.length()orvalue.lengthare to long. The maximum length for key and value are implementation specific.- See Also:
setValues(String, String[])
-
setValues
void setValues(String key, String... values) throws ReadOnlyException
Sets a multi-valued String preference for the specified key.The key cannot be
null, butnullvalues in the values parameter are allowed.If the same key contained already a
StringorString[]value it must be replaced by the new value.- Parameters:
key- key with which the value is to be associatedvalues- values to be associated with key- Throws:
IllegalArgumentException- if key isnull, orkey.length()is to long orvalue.sizeis to large. The maximum length for key and maximum size for value are implementation specific.ReadOnlyException- if this preference cannot be modified for this request- See Also:
setValue(String,String)
-
getNames
Enumeration<String> getNames()
Returns all of the keys that have an associated value, or an emptyEnumerationif no keys are available.- Returns:
- an Enumeration of the keys that have an associated value,
or an empty
Enumerationif no keys are available.
-
getMap
Map<String,String[]> getMap()
Returns aMapof the preferences.The values in the returned
Mapare from type String array (String[]).If no preferences exist this method returns an empty
Map.- Returns:
- an immutable
Mapcontaining preference names as keys and preference values as map values, or an emptyMapif no preference exist. The keys in the preference map are of type String. The values in the preference map are of type String array (String[]).
-
reset
void reset(String key) throws ReadOnlyException
Resets or removes the value associated with the specified key.If this implementation supports stored defaults, and there is such a default for the specified preference, the given key will be reset to the stored default.
If there is no default available the key will be removed.
- Parameters:
key- to reset- Throws:
IllegalArgumentException- if key isnull.ReadOnlyException- if this preference cannot be modified for this request
-
store
void store() throws IOException, ValidatorExceptionCommits all changes made to the preferences via thesetmethods in the persistent store.If this call returns successful, all changes are made persistent. If this call fails, no changes are made in the persistent store. This call is an atomic operation regardless of how many preference attributes have been modified.
All changes made to preferences not followed by a call to the
storemethod are discarded when the portlet finishes theprocessActionmethod.If a validator is defined for this preferences in the deployment descriptor, this validator is called before the actual store is performed to check whether the given preferences are valid. If this check fails a
ValidatorExceptionis thrown.- Throws:
IOException- if changes cannot be written into the backend storeValidatorException- if the validation performed by the associated validator failsIllegalStateException- if this method is called inside a render call- See Also:
PreferencesValidator
-
-