|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.opensymphony.xwork2.interceptor.AbstractInterceptor
com.opensymphony.xwork2.interceptor.I18nInterceptor
public class I18nInterceptor
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:
<action name="someAction" class="com.examples.SomeAction"> <interceptor-ref name="i18n"/> <interceptor-ref name="basicStack"/> <result name="success">good_result.ftl</result> </action>
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 |
---|
protected static final Logger LOG
public static final String DEFAULT_SESSION_ATTRIBUTE
public static final String DEFAULT_PARAMETER
public static final String DEFAULT_REQUESTONLY_PARAMETER
protected String parameterName
protected String requestOnlyParameterName
protected String attributeName
Constructor Detail |
---|
public I18nInterceptor()
Method Detail |
---|
public void setParameterName(String parameterName)
public void setRequestOnlyParameterName(String requestOnlyParameterName)
public void setAttributeName(String attributeName)
public String intercept(ActionInvocation invocation) throws Exception
AbstractInterceptor
intercept
in interface Interceptor
intercept
in class AbstractInterceptor
invocation
- the action invocation
ActionInvocation.invoke()
, or from the interceptor itself.
Exception
- any system-level error, as defined in Action.execute()
.protected Locale storeLocale(ActionInvocation invocation, Locale locale, String storage)
invocation
- the action invocationlocale
- the locale to storestorage
- the place to store this locale (like Storage.SESSSION.toString())protected Locale getLocaleFromParam(Object requestedLocale)
requestedLocale
- the parameter from the request
protected Locale readStoredLocale(ActionInvocation invocation, Map<String,Object> session)
invocation
- the current invocationsession
- the current session
protected Locale readStoredLocalFromSession(ActionInvocation invocation, Map<String,Object> session)
protected Locale readStoredLocalFromCurrentInvocation(ActionInvocation invocation)
protected Object findLocaleParameter(Map<String,Object> params, String parameterName)
protected void saveLocale(ActionInvocation invocation, Locale locale)
invocation
- The ActionInvocation.locale
- The locale to save.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |