org.norther.tammi.spray.terminal
Class DefaultLocaleFilter

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.spray.filter.DefaultFilter
          extended by org.norther.tammi.spray.filter.DefaultKeyFilter
              extended by org.norther.tammi.spray.terminal.DefaultLocaleFilter
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Filter, Manageable, MBeanDelegate, KeyFilter, LocaleFilter

public class DefaultLocaleFilter
extends DefaultKeyFilter
implements LocaleFilter

A default implementation of LocaleFilter.

Version:
$Id: DefaultLocaleFilter.java,v 1.11 2010-03-30 16:01:28 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
static String LOCALE_KEY
          The default key for the locale.
 
Fields inherited from class org.norther.tammi.spray.filter.DefaultKeyFilter
DEFAULT_KEY
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Constructor Summary
DefaultLocaleFilter()
          Constructs a new filter.
DefaultLocaleFilter(String key)
          Constructs a new filter with a key.
 
Method Summary
 void addSupportedLocale(Locale locale)
          Adds a supported locale.
 void clearNativeCountries()
          Clears all native countries.
 void clearSupportedLocales()
          Clears all supported locales.
 void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
           
 Locale getDefaultLocale()
          Gets the default locale for the response.
protected  Locale getKeyLocale(ServletRequest request, ServletResponse response, FilterChain chain)
          Gets the key value as locale.
 String getNativeCountry(String lang)
          Gets the native country for the specified language.
 Locale[] getSupportedLocales()
          Gets supported locales.
 boolean isForcedLocale()
          Checks whether a cached locale should be ignored and apply either the request specific locale or the default locale.
 Set<String> languageSet()
          Returns a read-only set of languages with native countries.
 void removeNativeCountry(String lang)
          Removes the native country for the specified language.
 void removeSupportedLocale(Locale locale)
          Removes a supported locale.
 void setDefaultLocale(Locale locale)
          Sets the default locale for the response.
 void setForcedLocale(boolean flag)
          Sets the forced locale option determining whether a cached locale should be ignored or not.
 void setNativeCountry(String lang, String country)
          Sets the native country for the specified language.
 void setSupportedLocales(Locale[] locales)
          Sets supported locales.
 
Methods inherited from class org.norther.tammi.spray.filter.DefaultKeyFilter
getKey, getKeyValue, getKeyValues, isLinkedKey, setKey, setLinkedKey
 
Methods inherited from class org.norther.tammi.spray.filter.DefaultFilter
destroy, getFilterConfig, getRequestMap, getSessionMap, init
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unmanaged, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.spray.filter.KeyFilter
getKey, getKeyValue, getKeyValues, isLinkedKey, setKey, setLinkedKey
 
Methods inherited from interface javax.servlet.Filter
destroy, init
 

Field Detail

LOCALE_KEY

public static final String LOCALE_KEY
The default key for the locale.

See Also:
Constant Field Values
Constructor Detail

DefaultLocaleFilter

public DefaultLocaleFilter()
Constructs a new filter.


DefaultLocaleFilter

public DefaultLocaleFilter(String key)
Constructs a new filter with a key.

Parameters:
key - the filter key.
Method Detail

getDefaultLocale

public Locale getDefaultLocale()
Description copied from interface: LocaleFilter
Gets the default locale for the response.

Specified by:
getDefaultLocale in interface LocaleFilter
Returns:
the default locale.

setDefaultLocale

public void setDefaultLocale(Locale locale)
Description copied from interface: LocaleFilter
Sets the default locale for the response. The locale also specifies the character encoding, if it is not given separately.

Specified by:
setDefaultLocale in interface LocaleFilter
Parameters:
locale - the default locale.

isForcedLocale

public boolean isForcedLocale()
Description copied from interface: LocaleFilter
Checks whether a cached locale should be ignored and apply either the request specific locale or the default locale.

Specified by:
isForcedLocale in interface LocaleFilter
Returns:
the forced locale option.

setForcedLocale

public void setForcedLocale(boolean flag)
Description copied from interface: LocaleFilter
Sets the forced locale option determining whether a cached locale should be ignored or not.

Specified by:
setForcedLocale in interface LocaleFilter
Parameters:
flag - the forced locale option.

getSupportedLocales

public Locale[] getSupportedLocales()
Description copied from interface: LocaleFilter
Gets supported locales.

Specified by:
getSupportedLocales in interface LocaleFilter
Returns:
an array of supported locales.

setSupportedLocales

public void setSupportedLocales(Locale[] locales)
Description copied from interface: LocaleFilter
Sets supported locales.

Specified by:
setSupportedLocales in interface LocaleFilter
Parameters:
locales - an array of supported locales.

addSupportedLocale

public void addSupportedLocale(Locale locale)
Description copied from interface: LocaleFilter
Adds a supported locale.

Specified by:
addSupportedLocale in interface LocaleFilter
Parameters:
locale - the supported locale.

removeSupportedLocale

public void removeSupportedLocale(Locale locale)
Description copied from interface: LocaleFilter
Removes a supported locale.

Specified by:
removeSupportedLocale in interface LocaleFilter
Parameters:
locale - the supported locale.

clearSupportedLocales

public void clearSupportedLocales()
Description copied from interface: LocaleFilter
Clears all supported locales.

Specified by:
clearSupportedLocales in interface LocaleFilter

getNativeCountry

public String getNativeCountry(String lang)
Description copied from interface: LocaleFilter
Gets the native country for the specified language.

Specified by:
getNativeCountry in interface LocaleFilter
Parameters:
lang - the language.
Returns:
the country.

setNativeCountry

public void setNativeCountry(String lang,
                             String country)
Description copied from interface: LocaleFilter
Sets the native country for the specified language. A native country can be specified for a locale that contains only language information. Default country is the language in uppercase. An empty setting denotes that no default country is applied for the given language.

Specified by:
setNativeCountry in interface LocaleFilter
Parameters:
lang - the language.
country - the country.

removeNativeCountry

public void removeNativeCountry(String lang)
Description copied from interface: LocaleFilter
Removes the native country for the specified language.

Specified by:
removeNativeCountry in interface LocaleFilter
Parameters:
lang - the language.

clearNativeCountries

public void clearNativeCountries()
Description copied from interface: LocaleFilter
Clears all native countries.

Specified by:
clearNativeCountries in interface LocaleFilter

languageSet

public Set<String> languageSet()
Description copied from interface: LocaleFilter
Returns a read-only set of languages with native countries.

Specified by:
languageSet in interface LocaleFilter
Returns:
a set of languages.

doFilter

public void doFilter(ServletRequest request,
                     ServletResponse response,
                     FilterChain chain)
              throws ServletException,
                     IOException
Specified by:
doFilter in interface Filter
Overrides:
doFilter in class DefaultFilter
Throws:
ServletException
IOException

getKeyLocale

protected Locale getKeyLocale(ServletRequest request,
                              ServletResponse response,
                              FilterChain chain)
Gets the key value as locale.

Parameters:
request - the request.
response - the response.
chain - the filter chain.
Returns:
the locale or null.


Copyright © 2004 The Norther Organization. All rights reserved.