com.opensymphony.xwork.interceptor
Class I18nInterceptor
java.lang.Object
com.opensymphony.xwork.interceptor.I18nInterceptor
- All Implemented Interfaces:
- Interceptor, Serializable
public class I18nInterceptor - extends Object
- implements Interceptor
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. 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.
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
- 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
|
Method Summary |
void |
destroy()
Called to let an interceptor clean up any resources it has allocated. |
void |
init()
Called after an interceptor is created, but before any requests are processed using
intercept , giving
the Interceptor a chance to initialize any needed resources. |
String |
intercept(ActionInvocation invocation)
Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the
request by the ActionInvocation or to short-circuit the processing and just return a String return code. |
protected void |
saveLocale(ActionInvocation invocation,
Locale locale)
Save the given locale to the ActionInvocation. |
void |
setAttributeName(String attributeName)
|
void |
setParameterName(String parameterName)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
log
protected static final org.apache.commons.logging.Log 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
parameterName
protected String parameterName
attributeName
protected String attributeName
I18nInterceptor
public I18nInterceptor()
setParameterName
public void setParameterName(String parameterName)
setAttributeName
public void setAttributeName(String attributeName)
init
public void init()
- Description copied from interface:
Interceptor
- Called after an interceptor is created, but before any requests are processed using
intercept , giving
the Interceptor a chance to initialize any needed resources.
- Specified by:
init in interface Interceptor
destroy
public void destroy()
- Description copied from interface:
Interceptor
- Called to let an interceptor clean up any resources it has allocated.
- Specified by:
destroy in interface Interceptor
intercept
public String intercept(ActionInvocation invocation)
throws Exception
- Description copied from interface:
Interceptor
- Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the
request by the
ActionInvocation or to short-circuit the processing and just return a String return code.
- Specified by:
intercept in interface Interceptor
- 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().
saveLocale
protected void saveLocale(ActionInvocation invocation,
Locale locale)
- Save the given locale to the ActionInvocation.
- Parameters:
invocation - The ActionInvocation.locale - The locale to save.
|