Search in sources :

Example 11 with Action

use of com.opensymphony.xwork2.Action in project dhis2-core by dhis2.

the class I18nInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    Action action = (Action) invocation.getAction();
    I18n i18n = i18nManager.getI18n(action.getClass());
    I18nFormat i18nFormat = i18nManager.getI18nFormat();
    Locale locale = localeManager.getCurrentLocale();
    // ---------------------------------------------------------------------
    // Make the objects available for web templates
    // ---------------------------------------------------------------------
    Map<String, Object> i18nMap = new HashMap<>(3);
    i18nMap.put(KEY_I18N, i18n);
    i18nMap.put(KEY_I18N_FORMAT, i18nFormat);
    i18nMap.put(KEY_LOCALE, locale);
    invocation.getStack().push(i18nMap);
    // ---------------------------------------------------------------------
    // Set the objects in the action class if the properties exist
    // ---------------------------------------------------------------------
    Map<?, ?> contextMap = invocation.getInvocationContext().getContextMap();
    try {
        Ognl.setValue(KEY_I18N, contextMap, action, i18n);
    } catch (NoSuchPropertyException ignored) {
    }
    try {
        Ognl.setValue(KEY_I18N_FORMAT, contextMap, action, i18nFormat);
    } catch (NoSuchPropertyException ignored) {
    }
    try {
        Ognl.setValue(KEY_LOCALE, contextMap, action, locale);
    } catch (NoSuchPropertyException ignored) {
    }
    return invocation.invoke();
}
Also used : Locale(java.util.Locale) Action(com.opensymphony.xwork2.Action) HashMap(java.util.HashMap) NoSuchPropertyException(ognl.NoSuchPropertyException) I18nFormat(org.hisp.dhis.i18n.I18nFormat) I18n(org.hisp.dhis.i18n.I18n)

Aggregations

PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)4 HashMap (java.util.HashMap)4 Action (com.opensymphony.xwork2.Action)3 Map (java.util.Map)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 I18n (org.hisp.dhis.i18n.I18n)3 ActionContext (com.opensymphony.xwork2.ActionContext)2 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)2 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)2 ValueStack (com.opensymphony.xwork2.util.ValueStack)2 org.apache.struts2.config (org.apache.struts2.config)2 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)1 ValidationAware (com.opensymphony.xwork2.ValidationAware)1 Configuration (com.opensymphony.xwork2.config.Configuration)1 ResultTypeConfig (com.opensymphony.xwork2.config.entities.ResultTypeConfig)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Annotation (java.lang.annotation.Annotation)1