Package org.apache.wiki.preferences

# Class Preferences

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<String,String>
org.apache.wiki.preferences.Preferences

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Map<String,String>`

public class Preferences extends HashMap<String,String>
Represents an object which is used to store user preferences.

See Also:
  - Serialized Form

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum`
`Preferences.TimeFormat`
Is used to choose between the different date formats that JSPWiki supports.

## Nested classes/interfaces inherited from class java.util.AbstractMap

`AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>`

## Nested classes/interfaces inherited from interface java.util.Map

`Map.Entry<K extends Object,V extends Object>`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`COOKIE_USER_PREFS_NAME`
`static final String`
`SESSIONPREFS`
The name under which a Preferences object is stored in the HttpSession.

## Constructor Summary

Constructors
Constructor
Description
`Preferences()`

## Method Summary

Modifier and Type
Method
Description
`static ResourceBundle`
`getBundle(org.apache.wiki.api.core.Context context, String bundle)`
Locates the i18n ResourceBundle given.
`static SimpleDateFormat`
`getDateFormat(org.apache.wiki.api.core.Context context, Preferences.TimeFormat tf)`
Get SimpleTimeFormat according to user browser locale and preferred time formats.
`static Locale`
`getLocale(org.apache.wiki.api.core.Context context)`
Get Locale according to user-preference settings or the user browser locale
`static String`
`getPreference(jakarta.servlet.jsp.PageContext pageContext, String name)`
Returns a preference value programmatically.
`static String`
`getPreference(org.apache.wiki.api.core.Context wikiContext, String name)`
Returns a preference value programmatically.
`static void`
`reloadPreferences(jakarta.servlet.jsp.PageContext pageContext)`
Reloads the preferences from the PageContext into the WikiContext.
`static String`
`renderDate(org.apache.wiki.api.core.Context context, Date date, Preferences.TimeFormat tf)`
A simple helper function to render a date based on the user preferences.
`static void`
`setupPreferences(jakarta.servlet.jsp.PageContext pageContext)`
This is an utility method which is called to make sure that the JSP pages do have proper access to any user preferences.

### Methods inherited from class java.util.HashMap

`clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values`

### Methods inherited from class java.util.AbstractMap

`equals, hashCode, toString`

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.util.Map

`equals, hashCode`

## Field Details

### SESSIONPREFS

public static final String SESSIONPREFS
The name under which a Preferences object is stored in the HttpSession. Its value is "prefs".

See Also:
  - Constant Field Values

### COOKIE_USER_PREFS_NAME

public static final String COOKIE_USER_PREFS_NAME

See Also:
  - Constant Field Values

## Constructor Details

### Preferences

public Preferences()

## Method Details

### setupPreferences

public static void setupPreferences(jakarta.servlet.jsp.PageContext pageContext)
This is an utility method which is called to make sure that the JSP pages do have proper access to any user preferences. It should be called from the commonheader.jsp.

This method reads user cookie preferences and mixes them up with any default preferences (and in the future, any user-specific preferences) and puts them all in the session, so that they do not have to be rewritten again.

This method will remember if the user has already changed his prefs.

Parameters:
  `pageContext` - The JSP PageContext.

### reloadPreferences

public static void reloadPreferences(jakarta.servlet.jsp.PageContext pageContext)
Reloads the preferences from the PageContext into the WikiContext.

Parameters:
  `pageContext` - The page context.

### getPreference

public static String getPreference(org.apache.wiki.api.core.Context wikiContext, String name)
Returns a preference value programmatically. FIXME

Parameters:
  `wikiContext` -
  `name` -
Returns:
  the preference value

### getPreference

public static String getPreference(jakarta.servlet.jsp.PageContext pageContext, String name)
Returns a preference value programmatically.

Parameters:
  `pageContext` -
  `name` -
Returns:
  the preference value

### getLocale

public static Locale getLocale(org.apache.wiki.api.core.Context context)
Get Locale according to user-preference settings or the user browser locale

Parameters:
  `context` - The context to examine.
Returns:
  a Locale object.
Since:
  2.8

### getBundle

public static ResourceBundle getBundle(org.apache.wiki.api.core.Context context, String bundle) throws MissingResourceException
Locates the i18n ResourceBundle given. This method interprets the request locale, and uses that to figure out which language the user wants.

Parameters:
  `context` - `Context` holding the user's locale
  `bundle` - The name of the bundle you are looking for.
Returns:
  A localized string (or from the default language, if not found)
Throws:
  `MissingResourceException` - If the bundle cannot be found
See Also:
  - `InternationalizationManager`

### getDateFormat

public static SimpleDateFormat getDateFormat(org.apache.wiki.api.core.Context context, Preferences.TimeFormat tf)
Get SimpleTimeFormat according to user browser locale and preferred time formats. If not found, it will revert to whichever format is set for the default.

Parameters:
  `context` - WikiContext to use for rendering.
  `tf` - Which version of the dateformat you are looking for?
Returns:
  A SimpleTimeFormat object which you can use to render
Since:
  2.8

### renderDate

public static String renderDate(org.apache.wiki.api.core.Context context, Date date, Preferences.TimeFormat tf)
A simple helper function to render a date based on the user preferences. This is useful for example for all plugins.

Parameters:
  `context` - The context which is used to get the preferences
  `date` - The date to render.
  `tf` - In which format the date should be rendered.
Returns:
  A ready-rendered date.
Since:
  2.8