mirror of
https://github.com/apache/struts.git
synced 2026-08-07 23:57:03 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5054ff469a | |||
| 0f69b0c3fb | |||
| 09958919ca | |||
| aabc90df6b | |||
| f515def5b8 | |||
| fddc6582e0 | |||
| 8971b50810 | |||
| 6457f002d9 | |||
| 6e1ea61dc6 | |||
| bcea4c9baf | |||
| a1b89842c0 | |||
| 03766980d1 | |||
| 1bf7de8d37 | |||
| ad3a697d93 |
+1
-1
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
<artifactId>struts2-apps</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
@@ -26,12 +26,12 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-apps</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-rest-showcase</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
<name>Struts 2 Rest Showcase Webapp</name>
|
||||
<description>Struts 2 Rest Showcase Example</description>
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-apps</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-showcase</artifactId>
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-assembly</artifactId>
|
||||
|
||||
+3
-3
@@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-bom</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Struts 2 Bill of Materials</name>
|
||||
@@ -25,7 +25,7 @@
|
||||
</licenses>
|
||||
|
||||
<properties>
|
||||
<struts-version.version>2.5.6</struts-version.version>
|
||||
<struts-version.version>2.5.7</struts-version.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
@@ -172,6 +172,6 @@
|
||||
</dependencyManagement>
|
||||
|
||||
<scm>
|
||||
<tag>STRUTS_2_5_6</tag>
|
||||
<tag>STRUTS_2_5_7</tag>
|
||||
</scm>
|
||||
</project>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-osgi-bundles</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-osgi-admin-bundle</artifactId>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-osgi-bundles</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-osgi-demo-bundle</artifactId>
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-osgi-bundles</artifactId>
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
<artifactId>struts2-core</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -18,7 +18,9 @@ package com.opensymphony.xwork2.config.impl;
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.config.*;
|
||||
import com.opensymphony.xwork2.config.entities.*;
|
||||
import com.opensymphony.xwork2.config.providers.EnvsValueSubstitutor;
|
||||
import com.opensymphony.xwork2.config.providers.InterceptorBuilder;
|
||||
import com.opensymphony.xwork2.config.providers.ValueSubstitutor;
|
||||
import com.opensymphony.xwork2.conversion.*;
|
||||
import com.opensymphony.xwork2.conversion.impl.*;
|
||||
import com.opensymphony.xwork2.factory.*;
|
||||
@@ -265,6 +267,8 @@ public class DefaultConfiguration implements Configuration {
|
||||
builder.factory(PropertyAccessor.class, CompoundRoot.class.getName(), CompoundRootAccessor.class, Scope.SINGLETON);
|
||||
builder.factory(OgnlUtil.class, Scope.SINGLETON);
|
||||
|
||||
builder.factory(ValueSubstitutor.class, EnvsValueSubstitutor.class, Scope.SINGLETON);
|
||||
|
||||
builder.constant(XWorkConstants.DEV_MODE, "false");
|
||||
builder.constant(XWorkConstants.LOG_MISSING_PROPERTIES, "false");
|
||||
builder.constant(XWorkConstants.ENABLE_OGNL_EVAL_EXPRESSION, "false");
|
||||
|
||||
+2
-2
@@ -27,14 +27,14 @@ public class EnvsValueSubstitutor implements ValueSubstitutor {
|
||||
|
||||
public EnvsValueSubstitutor() {
|
||||
strSubstitutor = new StrSubstitutor(System.getenv());
|
||||
strSubstitutor.setVariablePrefix("${ENV.");
|
||||
strSubstitutor.setVariablePrefix("${env.");
|
||||
strSubstitutor.setVariableSuffix('}');
|
||||
strSubstitutor.setValueDelimiter(":");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String substitute(String value) {
|
||||
LOG.debug("Substituting value {} with proper ENV value", value);
|
||||
LOG.debug("Substituting value {} with proper System variable or environment variable", value);
|
||||
|
||||
String substituted = StrSubstitutor.replaceSystemProperties(value);
|
||||
return strSubstitutor.replace(substituted);
|
||||
|
||||
@@ -152,6 +152,11 @@ public class HttpParameters implements Map<String, Parameter>, Cloneable {
|
||||
return Collections.unmodifiableSet(parameters.entrySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return parameters.toString();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private Map<String, Object> requestParameterMap;
|
||||
private HttpParameters parent;
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
*/
|
||||
package org.apache.struts2.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.LocaleProvider;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
@@ -28,14 +27,13 @@ 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;
|
||||
import org.apache.struts2.dispatcher.Parameter;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -76,6 +74,9 @@ import java.util.Map;
|
||||
* <li>attributeName (optional) - the name of the session key to store the selected locale. By default this is
|
||||
* <b>WW_TRANS_I18N_LOCALE</b></li>
|
||||
*
|
||||
* <li>storage (optional) - the name of storage location, it can be <b>none</b>, <b>session</b> or <b>cookie</b>.
|
||||
* By default this is <b>session</b></li>
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
* <!-- END SNIPPET: parameters -->
|
||||
@@ -96,25 +97,29 @@ public class I18nInterceptor extends AbstractInterceptor {
|
||||
|
||||
public static final String DEFAULT_SESSION_ATTRIBUTE = "WW_TRANS_I18N_LOCALE";
|
||||
public static final String DEFAULT_PARAMETER = "request_locale";
|
||||
public static final String DEFAULT_REQUESTONLY_PARAMETER = "request_only_locale";
|
||||
public static final String DEFAULT_REQUEST_ONLY_PARAMETER = "request_only_locale";
|
||||
public static final String DEFAULT_COOKIE_ATTRIBUTE = DEFAULT_SESSION_ATTRIBUTE;
|
||||
public static final String DEFAULT_COOKIE_PARAMETER = "request_cookie_locale";
|
||||
|
||||
protected String parameterName = DEFAULT_PARAMETER;
|
||||
protected String requestOnlyParameterName = DEFAULT_REQUESTONLY_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;
|
||||
}
|
||||
|
||||
public void setAttributeName(String attributeName) {
|
||||
this.attributeName = attributeName;
|
||||
}
|
||||
|
||||
public void setRequestOnlyParameterName(String requestOnlyParameterName) {
|
||||
this.requestOnlyParameterName = requestOnlyParameterName;
|
||||
}
|
||||
@@ -123,8 +128,17 @@ public class I18nInterceptor extends AbstractInterceptor {
|
||||
this.requestCookieParameterName = requestCookieParameterName;
|
||||
}
|
||||
|
||||
public void setAttributeName(String attributeName) {
|
||||
this.attributeName = attributeName;
|
||||
public void setLocaleStorage(String storageName) {
|
||||
if (storageName == null || "".equals(storageName)) {
|
||||
this.storage = Storage.NONE;
|
||||
} else {
|
||||
try {
|
||||
this.storage = Storage.valueOf(storageName.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOG.warn(new ParameterizedMessage("Wrong storage name [{{}] was defined, falling back to {}", storageName, Storage.SESSION), e);
|
||||
this.storage = Storage.SESSION;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
@@ -134,67 +148,83 @@ public class I18nInterceptor extends AbstractInterceptor {
|
||||
|
||||
@Override
|
||||
public String intercept(ActionInvocation invocation) throws Exception {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("intercept '{}/{}' {",
|
||||
invocation.getProxy().getNamespace(), invocation.getProxy().getActionName());
|
||||
}
|
||||
LOG.debug("Intercept '{}/{}'",
|
||||
invocation.getProxy().getNamespace(), invocation.getProxy().getActionName());
|
||||
|
||||
LocaleFinder localeFinder = new CookieLocaleFinder(invocation);
|
||||
Locale locale = getLocaleFromParam(localeFinder.getRequestedLocale());
|
||||
locale = storeLocale(invocation, locale, localeFinder.getStorage());
|
||||
saveLocale(invocation, locale);
|
||||
RequestOnlyLocaleFinder localeFinder = getLocaleFinder(invocation);
|
||||
Locale locale = getLocaleFromParam(localeFinder.find());
|
||||
locale = storeLocale(invocation, locale);
|
||||
useLocale(invocation, locale);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("before Locale={}", invocation.getStack().findValue("locale"));
|
||||
LOG.debug("Before action invocation Locale={}", invocation.getStack().findValue("locale"));
|
||||
}
|
||||
|
||||
final String result = invocation.invoke();
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("after Locale={}", invocation.getStack().findValue("locale"));
|
||||
LOG.debug("intercept } ");
|
||||
LOG.debug("After action invocation Locale={}", invocation.getStack().findValue("locale"));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected RequestOnlyLocaleFinder getLocaleFinder(ActionInvocation invocation) {
|
||||
RequestOnlyLocaleFinder localeFinder;
|
||||
if (this.storage == Storage.COOKIE) {
|
||||
localeFinder = new CookieLocaleFinder(invocation);
|
||||
} else if (this.storage == Storage.SESSION) {
|
||||
localeFinder = new SessionLocaleFinder(invocation);
|
||||
} else {
|
||||
localeFinder = new RequestOnlyLocaleFinder(invocation);
|
||||
}
|
||||
|
||||
LOG.debug("Using LocaleFinder implementation {}", localeFinder.getClass().getName());
|
||||
return localeFinder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the locale to the chosen storage, like f. e. the session
|
||||
*
|
||||
* @param invocation the action invocation
|
||||
* @param locale the locale to store
|
||||
* @param storage the place to store this locale (like Storage.SESSSION)
|
||||
*
|
||||
* @return the locale
|
||||
*/
|
||||
protected Locale storeLocale(ActionInvocation invocation, Locale locale, Storage storage) {
|
||||
if (storage == Storage.COOKIE) {
|
||||
ActionContext ac = invocation.getInvocationContext();
|
||||
HttpServletResponse response = (HttpServletResponse) ac.get(StrutsStatics.HTTP_RESPONSE);
|
||||
|
||||
Cookie cookie = new Cookie(DEFAULT_COOKIE_ATTRIBUTE, locale.toString());
|
||||
cookie.setMaxAge(1209600); // two weeks
|
||||
response.addCookie(cookie);
|
||||
|
||||
storage = Storage.SESSION;
|
||||
protected Locale storeLocale(ActionInvocation invocation, Locale locale) {
|
||||
if (locale == null) {
|
||||
storage = Storage.NONE;
|
||||
locale = readStoredLocale(invocation);
|
||||
}
|
||||
|
||||
if (storage == Storage.COOKIE) {
|
||||
storeLocaleInCookie(invocation, locale);
|
||||
}
|
||||
|
||||
if (Storage.SESSION == storage) {
|
||||
storeLocaleInSession(invocation, locale);
|
||||
}
|
||||
|
||||
return locale;
|
||||
}
|
||||
|
||||
protected void storeLocaleInCookie(ActionInvocation ignore, Locale locale) {
|
||||
HttpServletResponse response = ServletActionContext.getResponse();
|
||||
|
||||
Cookie cookie = new Cookie(DEFAULT_COOKIE_ATTRIBUTE, locale.toString());
|
||||
cookie.setMaxAge(1209600); // two weeks
|
||||
response.addCookie(cookie);
|
||||
}
|
||||
|
||||
protected void storeLocaleInSession(ActionInvocation invocation, Locale locale) {
|
||||
//save it in session
|
||||
Map<String, Object> session = invocation.getInvocationContext().getSession();
|
||||
|
||||
if (session != null) {
|
||||
synchronized (session) {
|
||||
if (locale == null) {
|
||||
storage = Storage.NONE;
|
||||
locale = readStoredLocale(invocation, session);
|
||||
}
|
||||
|
||||
if (Storage.SESSION == storage) {
|
||||
session.put(attributeName, locale);
|
||||
}
|
||||
session.put(attributeName, locale);
|
||||
}
|
||||
}
|
||||
return locale;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,26 +232,23 @@ public class I18nInterceptor extends AbstractInterceptor {
|
||||
* current invocation (=browser)
|
||||
*
|
||||
* @param invocation the current invocation
|
||||
* @param session the current session
|
||||
* @return the read locale
|
||||
*/
|
||||
protected Locale readStoredLocale(ActionInvocation invocation, Map<String, Object> session) {
|
||||
Locale locale = this.readStoredLocalFromSession(invocation, session);
|
||||
|
||||
protected Locale readStoredLocale(ActionInvocation invocation) {
|
||||
Locale locale = readStoredLocalFromSession(invocation);
|
||||
if (locale != null) {
|
||||
LOG.debug("Found stored Locale {} in session, using it!", locale);
|
||||
return locale;
|
||||
}
|
||||
|
||||
Cookie[] cookies = ServletActionContext.getRequest().getCookies();
|
||||
if (cookies != null) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if (DEFAULT_COOKIE_ATTRIBUTE.equals(cookie.getName())) {
|
||||
return getLocaleFromParam(cookie.getValue());
|
||||
}
|
||||
}
|
||||
Locale cookie = readStoredLocaleFromCookie(invocation);
|
||||
if (cookie != null) {
|
||||
LOG.debug("Found stored Locale {} in cookies, using it!", locale);
|
||||
return cookie;
|
||||
}
|
||||
|
||||
return this.readStoredLocalFromCurrentInvocation(invocation);
|
||||
LOG.debug("Neither locale was in session nor in cookies, searching current Invocation context");
|
||||
return readStoredLocalFromCurrentInvocation(invocation);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,13 +283,31 @@ public class I18nInterceptor extends AbstractInterceptor {
|
||||
return locale;
|
||||
}
|
||||
|
||||
protected Locale readStoredLocalFromSession(ActionInvocation invocation, Map<String, Object> session) {
|
||||
protected Locale readStoredLocalFromSession(ActionInvocation invocation) {
|
||||
// check session for saved locale
|
||||
Object sessionLocale = session.get(attributeName);
|
||||
if (sessionLocale != null && sessionLocale instanceof Locale) {
|
||||
Locale locale = (Locale) sessionLocale;
|
||||
LOG.debug("Applied session locale: {}", locale);
|
||||
return locale;
|
||||
Map<String, Object> session = invocation.getInvocationContext().getSession();
|
||||
|
||||
if (session != null) {
|
||||
synchronized (session) {
|
||||
Object sessionLocale = session.get(attributeName);
|
||||
if (sessionLocale != null && sessionLocale instanceof Locale) {
|
||||
Locale locale = (Locale) sessionLocale;
|
||||
LOG.debug("Applied session locale: {}", locale);
|
||||
return locale;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Locale readStoredLocaleFromCookie(ActionInvocation ignore) {
|
||||
Cookie[] cookies = ServletActionContext.getRequest().getCookies();
|
||||
if (cookies != null) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if (DEFAULT_COOKIE_ATTRIBUTE.equals(cookie.getName())) {
|
||||
return getLocaleFromParam(cookie.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -291,75 +336,78 @@ public class I18nInterceptor extends AbstractInterceptor {
|
||||
* @param invocation The ActionInvocation.
|
||||
* @param locale The locale to save.
|
||||
*/
|
||||
protected void saveLocale(ActionInvocation invocation, Locale locale) {
|
||||
protected void useLocale(ActionInvocation invocation, Locale locale) {
|
||||
invocation.getInvocationContext().setLocale(locale);
|
||||
}
|
||||
|
||||
protected class LocaleFinder {
|
||||
protected Storage storage = Storage.SESSION;
|
||||
protected Parameter requestedLocale = null;
|
||||
protected class RequestOnlyLocaleFinder {
|
||||
|
||||
protected ActionInvocation actionInvocation = null;
|
||||
|
||||
protected LocaleFinder(ActionInvocation invocation) {
|
||||
protected RequestOnlyLocaleFinder(ActionInvocation invocation) {
|
||||
actionInvocation = invocation;
|
||||
find();
|
||||
}
|
||||
|
||||
protected void find() {
|
||||
//get requested locale
|
||||
public String find() {
|
||||
HttpParameters params = actionInvocation.getInvocationContext().getParameters();
|
||||
|
||||
storage = Storage.SESSION;
|
||||
|
||||
requestedLocale = findLocaleParameter(params, parameterName);
|
||||
if (requestedLocale.isDefined()) {
|
||||
return;
|
||||
}
|
||||
|
||||
requestedLocale = findLocaleParameter(params, requestOnlyParameterName);
|
||||
Parameter requestedLocale = findLocaleParameter(params, requestOnlyParameterName);
|
||||
if (requestedLocale.isDefined()) {
|
||||
storage = Storage.NONE;
|
||||
return requestedLocale.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
public Storage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public String getRequestedLocale() {
|
||||
return requestedLocale.getValue();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected class CookieLocaleFinder extends LocaleFinder {
|
||||
protected class SessionLocaleFinder extends RequestOnlyLocaleFinder {
|
||||
|
||||
protected SessionLocaleFinder(ActionInvocation invocation) {
|
||||
super(invocation);
|
||||
}
|
||||
|
||||
public String find() {
|
||||
String requestOnlyLocale = super.find();
|
||||
|
||||
if (requestOnlyLocale != null) {
|
||||
return requestOnlyLocale;
|
||||
}
|
||||
|
||||
HttpParameters params = actionInvocation.getInvocationContext().getParameters();
|
||||
|
||||
Parameter requestedLocale = findLocaleParameter(params, parameterName);
|
||||
if (requestedLocale.isDefined()) {
|
||||
return requestedLocale.getValue();
|
||||
}
|
||||
|
||||
return requestedLocale.getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected class CookieLocaleFinder extends RequestOnlyLocaleFinder {
|
||||
protected CookieLocaleFinder(ActionInvocation invocation) {
|
||||
super(invocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void find() {
|
||||
//get requested locale
|
||||
HttpParameters params = actionInvocation.getInvocationContext().getParameters();
|
||||
storage = Storage.SESSION;
|
||||
public String find() {
|
||||
String requestOnlySessionLocale = super.find();
|
||||
|
||||
requestedLocale = findLocaleParameter(params, parameterName);
|
||||
|
||||
if (requestedLocale.isDefined()) {
|
||||
return;
|
||||
if (requestOnlySessionLocale != null) {
|
||||
return requestOnlySessionLocale;
|
||||
}
|
||||
|
||||
requestedLocale = findLocaleParameter(params, requestCookieParameterName);
|
||||
HttpParameters params = actionInvocation.getInvocationContext().getParameters();
|
||||
|
||||
Parameter requestedLocale = findLocaleParameter(params, requestCookieParameterName);
|
||||
if (requestedLocale.isDefined()) {
|
||||
storage = Storage.COOKIE;
|
||||
return;
|
||||
}
|
||||
|
||||
requestedLocale = findLocaleParameter(params, requestOnlyParameterName);
|
||||
if (requestedLocale.isDefined()) {
|
||||
storage = Storage.NONE;
|
||||
return requestedLocale.getValue();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ public class EnvsValueSubstitutorTest extends StrutsInternalTestCase {
|
||||
ValueSubstitutor substitutor = new EnvsValueSubstitutor();
|
||||
|
||||
// when
|
||||
String actual = substitutor.substitute("${ENV.USER}");
|
||||
String actual = substitutor.substitute("${env.USER}");
|
||||
|
||||
// then
|
||||
assertEquals(expected, actual);
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.DefaultLocaleProvider;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import com.opensymphony.xwork2.mock.MockActionProxy;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
@@ -78,7 +79,7 @@ public class I18nInterceptorTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testDenmarkLocaleRequestOnly() throws Exception {
|
||||
prepare(I18nInterceptor.DEFAULT_REQUESTONLY_PARAMETER, "da_DK");
|
||||
prepare(I18nInterceptor.DEFAULT_REQUEST_ONLY_PARAMETER, "da_DK");
|
||||
interceptor.intercept(mai);
|
||||
|
||||
assertFalse(mai.getInvocationContext().getParameters().get(I18nInterceptor.DEFAULT_PARAMETER).isDefined()); // should have been removed
|
||||
@@ -124,7 +125,7 @@ public class I18nInterceptorTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testWithVariantRequestOnly() throws Exception {
|
||||
prepare(I18nInterceptor.DEFAULT_REQUESTONLY_PARAMETER, "ja_JP_JP");
|
||||
prepare(I18nInterceptor.DEFAULT_REQUEST_ONLY_PARAMETER, "ja_JP_JP");
|
||||
interceptor.intercept(mai);
|
||||
|
||||
assertFalse(mai.getInvocationContext().getParameters().get(I18nInterceptor.DEFAULT_PARAMETER).isDefined()); // should have been removed
|
||||
@@ -187,6 +188,26 @@ public class I18nInterceptorTest extends TestCase {
|
||||
assertEquals(locale1, locale);
|
||||
}
|
||||
|
||||
public void testCookieCreation() throws Exception {
|
||||
|
||||
prepare(I18nInterceptor.DEFAULT_COOKIE_PARAMETER, "da_DK");
|
||||
|
||||
final Cookie cookie = new Cookie(I18nInterceptor.DEFAULT_COOKIE_ATTRIBUTE, "da_DK");
|
||||
|
||||
HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
|
||||
response.addCookie(CookieMatcher.eqCookie(cookie));
|
||||
EasyMock.replay(response);
|
||||
|
||||
ac.put(StrutsStatics.HTTP_RESPONSE, response);
|
||||
interceptor.setLocaleStorage(I18nInterceptor.Storage.COOKIE.name());
|
||||
interceptor.intercept(mai);
|
||||
|
||||
EasyMock.verify(response);
|
||||
|
||||
assertNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should not be stored here
|
||||
assertNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should not create a locale object
|
||||
}
|
||||
|
||||
private void prepare(String key, Serializable value) {
|
||||
Map<String, Serializable> params = new HashMap<>();
|
||||
params.put(key, value);
|
||||
@@ -214,9 +235,16 @@ public class I18nInterceptorTest extends TestCase {
|
||||
return SUCCESS;
|
||||
}
|
||||
};
|
||||
|
||||
MockActionProxy proxy = new MockActionProxy();
|
||||
proxy.setAction(action);
|
||||
proxy.setNamespace("i18n");
|
||||
proxy.setActionName("anAction");
|
||||
|
||||
mai = new MockActionInvocation();
|
||||
((MockActionInvocation) mai).setAction(action);
|
||||
((MockActionInvocation) mai).setInvocationContext(ac);
|
||||
((MockActionInvocation) mai).setProxy(proxy);
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
@@ -255,23 +283,4 @@ public class I18nInterceptorTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testCookieCreation() throws Exception {
|
||||
|
||||
prepare(I18nInterceptor.DEFAULT_COOKIE_PARAMETER, "da_DK");
|
||||
|
||||
final Cookie cookie = new Cookie(I18nInterceptor.DEFAULT_COOKIE_ATTRIBUTE, "da_DK");
|
||||
|
||||
HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
|
||||
response.addCookie(CookieMatcher.eqCookie(cookie));
|
||||
EasyMock.replay(response);
|
||||
|
||||
ac.put(StrutsStatics.HTTP_RESPONSE, response);
|
||||
interceptor.intercept(mai);
|
||||
|
||||
EasyMock.verify(response);
|
||||
|
||||
Locale denmark = new Locale("da", "DK");
|
||||
assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should be stored here
|
||||
assertEquals(denmark, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should create a locale object
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -7,11 +7,11 @@
|
||||
|
||||
<constant name="foo" value="bar"/>
|
||||
|
||||
<constant name="user" value="${ENV.USER}"/>
|
||||
<constant name="home" value="Current HOME = ${ENV.HOME}"/>
|
||||
<constant name="user" value="${env.USER}"/>
|
||||
<constant name="home" value="Current HOME = ${env.HOME}"/>
|
||||
<constant name="os" value="Current OS = ${os.name}"/>
|
||||
<constant name="unknown" value="Unknown = ${ENV.UNKNOWN:default}"/>
|
||||
<constant name="unknown" value="Unknown = ${env.UNKNOWN:default}"/>
|
||||
|
||||
<constant name="struts.devMode" value="${ENV.STRUTS_DEV_MODE:false}"/>
|
||||
<constant name="struts.devMode" value="${env.STRUTS_DEV_MODE:false}"/>
|
||||
|
||||
</xwork>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-cdi-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-config-browser-plugin</artifactId>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-convention-plugin</artifactId>
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-dwr-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-embeddedjsp-plugin</artifactId>
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-gxp-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-jasperreports-plugin</artifactId>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-javatemplates-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-jfreechart-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-json-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-junit-plugin</artifactId>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-osgi-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-oval-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-pell-multipart-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-plexus-plugin</artifactId>
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-portlet-tiles-plugin</artifactId>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-portlet-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-rest-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-sitegraph-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-sitemesh-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-spring-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-testng-plugin</artifactId>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-tiles-plugin</artifactId>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<version>2.5.7</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Struts 2</name>
|
||||
<url>http://struts.apache.org/</url>
|
||||
@@ -31,7 +31,7 @@
|
||||
<connection>scm:git:git://git.apache.org/struts.git</connection>
|
||||
<developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/struts.git</developerConnection>
|
||||
<url>http://git.apache.org/struts.git</url>
|
||||
<tag>STRUTS_2_5_6</tag>
|
||||
<tag>STRUTS_2_5_7</tag>
|
||||
</scm>
|
||||
|
||||
<issueManagement>
|
||||
|
||||
Reference in New Issue
Block a user