WW-4722 Allows predefine default store location
Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/6e1ea61d Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/6e1ea61d Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/6e1ea61d Branch: refs/heads/master Commit: 6e1ea61dc664c4a4e41a8a094030f2edf0088f6c Parents: bcea4c9 Author: Lukasz Lenart <lukaszlen...@apache.org> Authored: Thu Dec 1 16:55:42 2016 +0100 Committer: Lukasz Lenart <lukaszlen...@apache.org> Committed: Thu Dec 1 16:55:42 2016 +0100 ---------------------------------------------------------------------- .../struts2/interceptor/I18nInterceptor.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts/blob/6e1ea61d/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java index 62ac412..b1f8e8e 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java @@ -28,6 +28,7 @@ import com.opensymphony.xwork2.interceptor.AbstractInterceptor; import com.opensymphony.xwork2.util.LocalizedTextUtil; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsStatics; import org.apache.struts2.dispatcher.HttpParameters; @@ -102,14 +103,14 @@ public class I18nInterceptor extends AbstractInterceptor { protected String parameterName = DEFAULT_PARAMETER; protected String requestOnlyParameterName = DEFAULT_REQUEST_ONLY_PARAMETER; protected String attributeName = DEFAULT_SESSION_ATTRIBUTE; + protected String requestCookieParameterName = DEFAULT_COOKIE_PARAMETER; + protected Storage storage = Storage.SESSION; protected LocaleProvider localeProvider; // Request-Only = None protected enum Storage { COOKIE, SESSION, NONE } - protected String requestCookieParameterName = DEFAULT_COOKIE_PARAMETER; - public void setParameterName(String parameterName) { this.parameterName = parameterName; } @@ -126,6 +127,19 @@ public class I18nInterceptor extends AbstractInterceptor { this.attributeName = attributeName; } + public void setLocaleStorage(String storageName) { + if (storageName == null || "".equals(storageName)) { + this.storage = Storage.NONE; + } else { + try { + this.storage = Storage.valueOf(storageName); + } catch (IllegalArgumentException e) { + LOG.warn(new ParameterizedMessage("Wrong storage name [{{}] was defined, falling back to {}", storageName, Storage.SESSION), e); + this.storage = Storage.SESSION; + } + } + } + @Inject public void setLocaleProvider(LocaleProvider localeProvider) { this.localeProvider = localeProvider;