Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.opensymphony.xwork2.interceptor
Class I18nInterceptor

    java.lang.Object
      com.opensymphony.xwork2.interceptor.AbstractInterceptor
          com.opensymphony.xwork2.interceptor.I18nInterceptor

All Implemented Interfaces:
  Interceptor, Serializable

    public class I18nInterceptor

extends AbstractInterceptor

An interceptor that handles setting the locale specified in a session as the locale for the current action request. In addition, this interceptor will look for a specific HTTP request parameter and set the locale to whatever value is provided. This means that this interceptor can be used to allow for your application to dynamically change the locale for the user's session or, alternatively, only for the current request (since XWork 2.1.3). This is very useful for applications that require multi-lingual support and want the user to be able to set his or her language preference at any point. The locale parameter is removed during the execution of this interceptor, ensuring that properties aren't set on an action (such as request_locale) that have no typical corresponding setter in your action.

For example, using the default parameter name, a request to foo.action?request_locale=en_US, then the locale for US English is saved in the user's session and will be used for all future requests.

if there is no locale set (for example with the first visit), the interceptor uses the browser locale.

Interceptor parameters:

- parameterName (optional) - the name of the HTTP request parameter that dictates the locale to switch to and save in the session. By default this is request_locale

- requestOnlyParameterName (optional) - the name of the HTTP request parameter that dictates the locale to switch to for the current request only, without saving it in the session. By default this is request_only_locale

- attributeName (optional) - the name of the session key to store the selected locale. By default this is WW_TRANS_I18N_LOCALE

Extending the interceptor:

There are no known extensions points for this interceptor.

Example code:

     <action name="someAction" class="com.examples.SomeAction">
         <interceptor-ref name="i18n"/>
         <interceptor-ref name="basicStack"/>
         <result name="success">good_result.ftl</result>
     </action>

Author:
  Aleksei Gopachenko
See Also:
  Serialized Form

Nested Class Summary
`protected class` | `I18nInterceptor.LocaleFinder`
`protected static class` | `I18nInterceptor.Storage`

Field Summary
`protected String` | `attributeName`
`static String` | `DEFAULT_PARAMETER`
`static String` | `DEFAULT_REQUESTONLY_PARAMETER`
`static String` | `DEFAULT_SESSION_ATTRIBUTE`
`protected static Logger` | `LOG`
`protected String` | `parameterName`
`protected String` | `requestOnlyParameterName`

Constructor Summary
`I18nInterceptor()`

Method Summary
`protected Object` | `findLocaleParameter(Map<String,Object> params, String parameterName)`
`protected Locale` | `getLocaleFromParam(Object requestedLocale)` Creates a Locale object from the request param, which might be already a Local or a String
`String` | `intercept(ActionInvocation invocation)` Override to handle interception
`protected Locale` | `readStoredLocale(ActionInvocation invocation, Map<String,Object> session)` Reads the locale from the session, and if not found from the current invocation (=browser)
`protected Locale` | `readStoredLocalFromCurrentInvocation(ActionInvocation invocation)`
`protected Locale` | `readStoredLocalFromSession(ActionInvocation invocation, Map<String,Object> session)`
`protected void` | `saveLocale(ActionInvocation invocation, Locale locale)` Save the given locale to the ActionInvocation.
`void` | `setAttributeName(String attributeName)`
`void` | `setParameterName(String parameterName)`
`void` | `setRequestOnlyParameterName(String requestOnlyParameterName)`
`protected Locale` | `storeLocale(ActionInvocation invocation, Locale locale, String storage)` Store the locale to the chosen storage, like f.

Methods inherited from class com.opensymphony.xwork2.interceptor.AbstractInterceptor
`destroy, init`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### LOG

    protected static final Logger LOG

### DEFAULT_SESSION_ATTRIBUTE

    public static final String DEFAULT_SESSION_ATTRIBUTE

See Also:
  Constant Field Values

### DEFAULT_PARAMETER

    public static final String DEFAULT_PARAMETER

See Also:
  Constant Field Values

### DEFAULT_REQUESTONLY_PARAMETER

    public static final String DEFAULT_REQUESTONLY_PARAMETER

See Also:
  Constant Field Values

### parameterName

    protected String parameterName

### requestOnlyParameterName

    protected String requestOnlyParameterName

### attributeName

    protected String attributeName

Constructor Detail

### I18nInterceptor

    public I18nInterceptor()

Method Detail

### setParameterName

    public void setParameterName(String parameterName)

### setRequestOnlyParameterName

    public void setRequestOnlyParameterName(String requestOnlyParameterName)

### setAttributeName

    public void setAttributeName(String attributeName)

### 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()`.

### storeLocale

    protected Locale storeLocale(ActionInvocation invocation,
                                 Locale locale,
                                 String storage)

  Store the locale to the chosen storage, like f. e. the session

  Parameters:
    `invocation` - the action invocation
    `locale` - the locale to store
    `storage` - the place to store this locale (like Storage.SESSSION.toString())

### getLocaleFromParam

    protected Locale getLocaleFromParam(Object requestedLocale)

  Creates a Locale object from the request param, which might be already a Local or a String

  Parameters:
    `requestedLocale` - the parameter from the request
  Returns:
    the Locale

### readStoredLocale

    protected Locale readStoredLocale(ActionInvocation invocation,
                                      Map<String,Object> session)

  Reads the locale from the session, and if not found from the current invocation (=browser)

  Parameters:
    `invocation` - the current invocation
    `session` - the current session
  Returns:
    the read locale

### readStoredLocalFromSession

    protected Locale readStoredLocalFromSession(ActionInvocation invocation,
                                                Map<String,Object> session)

### readStoredLocalFromCurrentInvocation

    protected Locale readStoredLocalFromCurrentInvocation(ActionInvocation invocation)

### findLocaleParameter

    protected Object findLocaleParameter(Map<String,Object> params,
                                         String parameterName)

### saveLocale

    protected void saveLocale(ActionInvocation invocation,
                              Locale locale)

  Save the given locale to the ActionInvocation.

  Parameters:
    `invocation` - The ActionInvocation.
    `locale` - The locale to save.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000–2017 Apache Software Foundation. All rights reserved.