Class I18nInterceptor

java.lang.Object
org.apache.struts2.interceptor.AbstractInterceptor
org.apache.struts2.interceptor.I18nInterceptor
All Implemented Interfaces:
Serializable, ConditionalInterceptor, Interceptor

public class I18nInterceptor extends AbstractInterceptor
An interceptor that handles setting the locale specified in a session as the locale for the current action request.
See Also:
  • Field Details

  • Constructor Details

    • I18nInterceptor

      public I18nInterceptor()
  • Method Details

    • setParameterName

      public void setParameterName(String parameterName)
    • setAttributeName

      public void setAttributeName(String attributeName)
    • setRequestOnlyParameterName

      public void setRequestOnlyParameterName(String requestOnlyParameterName)
    • setRequestCookieParameterName

      public void setRequestCookieParameterName(String requestCookieParameterName)
    • setLocaleStorage

      public void setLocaleStorage(String storageName)
    • setSupportedLocale

      public void setSupportedLocale(String supportedLocale)
      Sets supported Locales by the application
      Parameters:
      supportedLocale - a comma separated list of supported Locale
    • setLocaleProviderFactory

      public void setLocaleProviderFactory(LocaleProviderFactory localeProviderFactory)
    • intercept

      public String intercept(ActionInvocation invocation) throws Exception
      Description copied from class: AbstractInterceptor
      Override to handle interception
      Specified by:
      intercept in interface Interceptor
      Specified by:
      intercept in class AbstractInterceptor
      Parameters:
      invocation - the action invocation
      Returns:
      the return code, either returned from ActionInvocation.invoke(), or from the interceptor itself.
      Throws:
      Exception - any system-level error, as defined in Action.execute().
    • getLocaleHandler

      protected I18nInterceptor.LocaleHandler getLocaleHandler(ActionInvocation invocation)
      Override this method to use your own implementation of I18nInterceptor.LocaleHandler
      Parameters:
      invocation - current action invocation context
      Returns:
      instance of I18nInterceptor.LocaleHandler
    • getLocaleFromParam

      protected Locale getLocaleFromParam(String requestedLocale)
      Creates a Locale object from the request param
      Parameters:
      requestedLocale - the parameter from the request
      Returns:
      instance of Locale or null
    • findLocaleParameter

      protected Parameter findLocaleParameter(ActionInvocation invocation, String parameterName)
    • useLocale

      protected void useLocale(ActionInvocation invocation, Locale locale)
      Save the given locale to the ActionInvocation.
      Parameters:
      invocation - The ActionInvocation.
      locale - The locale to save.