This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-web. See https://gitlab.nuiton.org/nuiton/nuiton-web.git commit bc2ff0455f8545d7f7056553c5a84a212f3ee736 Author: Brendan Le Ny <bleny@codelutin.com> Date: Wed Dec 20 11:18:42 2017 +0100 Update to ToPIA 3.3, Struts 2.5.14 and other dependencies Resolves #124 --- .../org/nuiton/web/struts2/I18nTextProvider.java | 37 +++++++++++---------- .../web/struts2/I18nTextProviderFactory.java | 15 +++++++-- .../web/struts2/converters/JsonConverter.java | 4 +-- .../nuiton/web/struts2/I18nTextProviderTest.java | 38 ++++++++-------------- pom.xml | 20 ++++++------ 5 files changed, 57 insertions(+), 57 deletions(-) diff --git a/nuiton-struts2/src/main/java/org/nuiton/web/struts2/I18nTextProvider.java b/nuiton-struts2/src/main/java/org/nuiton/web/struts2/I18nTextProvider.java index f7e2001..ee02fb9 100644 --- a/nuiton-struts2/src/main/java/org/nuiton/web/struts2/I18nTextProvider.java +++ b/nuiton-struts2/src/main/java/org/nuiton/web/struts2/I18nTextProvider.java @@ -21,10 +21,9 @@ */ package org.nuiton.web.struts2; -import com.opensymphony.xwork2.LocaleProvider; -import com.opensymphony.xwork2.LocalizedTextProvider; -import com.opensymphony.xwork2.ResourceBundleTextProvider; -import com.opensymphony.xwork2.TextProviderSupport; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.DefaultTextProvider; +import com.opensymphony.xwork2.TextProvider; import com.opensymphony.xwork2.util.ValueStack; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -39,28 +38,23 @@ import java.util.ResourceBundle; * Struts2's TextProvider implementation using nuiton's i18n. * * To use this text provider add the two following lines in your struts.xml : + * * <pre> - * <bean class="org.nuiton.web.struts2.I18nTextProvider" name="i18nTextProvider" type="com.opensymphony.xwork2.TextProvider" /> - <constant name="struts.xworkTextProvider" value="i18nTextProvider" /> + * <bean class="org.nuiton.web.struts2.I18nTextProvider" name="i18nTextProvider" type="com.opensymphony.xwork2.TextProvider" /> + * <constant name="struts.textProvider" value="i18nTextProvider" /> * </pre> * + * Before struts 2.5, you may use "struts.xworkTextProvider" instead of {@link org.apache.struts2.StrutsConstants#STRUTS_TEXT_PROVIDER} + * * @author Arnaud Thimel<thimel@codelutin.com> * @since 1.3 */ -public class I18nTextProvider extends TextProviderSupport implements ResourceBundleTextProvider { +public class I18nTextProvider implements TextProvider { private static final Log log = LogFactory.getLog(I18nTextProvider.class); public static final String UNTRANSLATED_MARKER = "???"; - public I18nTextProvider(Class clazz, LocaleProvider provider, LocalizedTextProvider localizedTextProvider) { - super(clazz, provider, localizedTextProvider); - } - - public I18nTextProvider(ResourceBundle bundle, LocaleProvider provider, LocalizedTextProvider localizedTextProvider) { - super(bundle, provider, localizedTextProvider); - } - protected String getSafeText(String key, String value) { if (StringUtils.isEmpty(value)) { if (log.isWarnEnabled()) { @@ -73,13 +67,20 @@ public class I18nTextProvider extends TextProviderSupport implements ResourceBun @Override public boolean hasKey(String key) { - Locale locale = localeProvider.getLocale(); + Locale locale = getLocale(); boolean result = I18n.hasKey(locale, key); return result; } + /** + * Implementation copied from {@link DefaultTextProvider#getText(java.lang.String)} + */ + protected Locale getLocale() { + return ActionContext.getContext().getLocale(); + } + protected String getTextFromLocale(String key, String defaultValue) { - Locale locale = localeProvider.getLocale(); + Locale locale = getLocale(); String result = I18n.l(locale, key); if (result == null) { result = defaultValue; @@ -89,7 +90,7 @@ public class I18nTextProvider extends TextProviderSupport implements ResourceBun } protected String getTextFromLocale(String key, String defaultValue, Object ... args) { - Locale locale = localeProvider.getLocale(); + Locale locale = getLocale(); String result = I18n.l(locale, key, args); if (result == null) { result = defaultValue; diff --git a/nuiton-struts2/src/main/java/org/nuiton/web/struts2/I18nTextProviderFactory.java b/nuiton-struts2/src/main/java/org/nuiton/web/struts2/I18nTextProviderFactory.java index 84587c5..fbfde8d 100644 --- a/nuiton-struts2/src/main/java/org/nuiton/web/struts2/I18nTextProviderFactory.java +++ b/nuiton-struts2/src/main/java/org/nuiton/web/struts2/I18nTextProviderFactory.java @@ -24,20 +24,31 @@ package org.nuiton.web.struts2; import com.opensymphony.xwork2.StrutsTextProviderFactory; import com.opensymphony.xwork2.TextProvider; +import org.apache.struts2.StrutsConstants; import java.util.ResourceBundle; /** + * May be declared as {@link StrutsConstants#STRUTS_TEXT_PROVIDER_FACTORY} with + * + * <pre> + * <bean class="org.nuiton.web.struts2.I18nTextProviderFactory" name="i18nTextProviderFactory" type="com.opensymphony.xwork2.TextProviderFactory" /> + * <constant name="struts.textProviderFactory" value="i18nTextProviderFactory" /> + * </pre> + * * @since 1.20 + * @deprecated since struts 2.5.14.1 a {@link TextProvider} can be provided using default factory. See https://issues.apache.org/jira/browse/WW-4884 */ +@Deprecated public class I18nTextProviderFactory extends StrutsTextProviderFactory { + @Override protected TextProvider getTextProvider(Class clazz) { - return new I18nTextProvider(clazz, localeProviderFactory.createLocaleProvider(), localizedTextProvider); + return new I18nTextProvider(); } @Override protected TextProvider getTextProvider(ResourceBundle bundle) { - return new I18nTextProvider(bundle, localeProviderFactory.createLocaleProvider(), localizedTextProvider); + return new I18nTextProvider(); } } diff --git a/nuiton-struts2/src/main/java/org/nuiton/web/struts2/converters/JsonConverter.java b/nuiton-struts2/src/main/java/org/nuiton/web/struts2/converters/JsonConverter.java index e52879a..c055745 100644 --- a/nuiton-struts2/src/main/java/org/nuiton/web/struts2/converters/JsonConverter.java +++ b/nuiton-struts2/src/main/java/org/nuiton/web/struts2/converters/JsonConverter.java @@ -24,6 +24,7 @@ package org.nuiton.web.struts2.converters; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.struts2.json.DefaultJSONWriter; import org.apache.struts2.json.JSONException; import org.apache.struts2.json.JSONPopulator; import org.apache.struts2.json.JSONUtil; @@ -98,8 +99,7 @@ public class JsonConverter extends StrutsTypeConverter { json = "null"; } else { try { - JSONWriter writer = new JSONWriter(); - writer.setCacheBeanInfo(false); + JSONWriter writer = new DefaultJSONWriter(); json = writer.write(object); } catch (JSONException e) { if (log.isErrorEnabled()) { diff --git a/nuiton-struts2/src/test/java/org/nuiton/web/struts2/I18nTextProviderTest.java b/nuiton-struts2/src/test/java/org/nuiton/web/struts2/I18nTextProviderTest.java index d7cc509..10912a2 100644 --- a/nuiton-struts2/src/test/java/org/nuiton/web/struts2/I18nTextProviderTest.java +++ b/nuiton-struts2/src/test/java/org/nuiton/web/struts2/I18nTextProviderTest.java @@ -21,11 +21,6 @@ */ package org.nuiton.web.struts2; -import java.util.Arrays; -import java.util.Locale; - -import com.opensymphony.xwork2.DefaultLocaleProvider; -import com.opensymphony.xwork2.LocaleProvider; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -33,66 +28,59 @@ import org.junit.Test; import org.nuiton.i18n.I18n; import org.nuiton.i18n.init.DefaultI18nInitializer; +import java.util.Arrays; +import java.util.Locale; + public class I18nTextProviderTest { protected I18nTextProvider provider; + @After - public void after() throws Exception { + public void after() { I18n.close(); } @Before - public void init() throws Exception { + public void init() { DefaultI18nInitializer initializer = new DefaultI18nInitializer("toto"); initializer.setMissingKeyReturnNull(true); I18n.init(initializer, Locale.FRENCH); - LocaleProvider localeProvider = new LocaleProvider() { + provider = new I18nTextProvider() { @Override - public Locale getLocale() { + protected Locale getLocale() { return Locale.FRENCH; } - - @Override - public boolean isValidLocaleString(String localeStr) { - return false; - } - - @Override - public boolean isValidLocale(Locale locale) { - return false; - } }; - provider = new I18nTextProvider((Class)null, localeProvider, null); } @Test - public void testHasKey() throws Exception { + public void testHasKey() { Assert.assertFalse(provider.hasKey("missing")); Assert.assertTrue(provider.hasKey("present")); } @Test - public void testGetTextSimple() throws Exception { + public void testGetTextSimple() { Assert.assertEquals("yes", provider.getText("present")); Assert.assertEquals(I18nTextProvider.UNTRANSLATED_MARKER + "missing" + I18nTextProvider.UNTRANSLATED_MARKER, provider.getText("missing")); } @Test - public void testGetTextDefaultValue() throws Exception { + public void testGetTextDefaultValue() { Assert.assertEquals("yes", provider.getText("present", "toto")); Assert.assertEquals("toto", provider.getText("missing", "toto")); } @Test - public void testGetTextArg() throws Exception { + public void testGetTextArg() { Assert.assertEquals("Hello Arno !", provider.getText("hello", null, "Arno")); } @Test - public void testGetTextArgs() throws Exception { + public void testGetTextArgs() { Assert.assertEquals("Hello Arno, ça biche ?", provider.getText("hello_plus", new String[] {"Arno", "ça biche"})); Assert.assertEquals("Hello Moto, ça gaze ?", provider.getText("hello_plus", Arrays.asList("Moto", "ça gaze"))); diff --git a/pom.xml b/pom.xml index 3305681..5598853 100644 --- a/pom.xml +++ b/pom.xml @@ -114,19 +114,19 @@ <signatureArtifactId>java17</signatureArtifactId> <signatureVersion>1.0</signatureVersion> - <eugeneVersion>3.0-alpha-9</eugeneVersion> + <eugeneVersion>3.0-alpha-10</eugeneVersion> - <nuitonConfigVersion>3.2</nuitonConfigVersion> + <nuitonConfigVersion>3.3</nuitonConfigVersion> <nuitonI18nVersion>3.6.3</nuitonI18nVersion> - <nuitonUtilsVersion>3.0-rc-18</nuitonUtilsVersion> + <nuitonUtilsVersion>3.0</nuitonUtilsVersion> <nuitonI18nPluginVersion>${nuitonI18nVersion}</nuitonI18nPluginVersion> - <topiaVersion>3.2.1</topiaVersion> + <topiaVersion>3.3.1</topiaVersion> <slf4jVersion>1.7.25</slf4jVersion> - <!-- Strust 2 --> - <struts2Version>2.5.12</struts2Version> + <!-- Struts 2 --> + <struts2Version>2.5.14.1</struts2Version> <shiroVersion>1.4.0</shiroVersion> <servletApiVersion>3.0.1</servletApiVersion> @@ -149,13 +149,13 @@ <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> - <version>3.6</version> + <version>3.7</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> - <version>2.5</version> + <version>2.6</version> </dependency> <dependency> @@ -179,7 +179,7 @@ <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> - <version>19.0</version> + <version>23.5-jre</version> </dependency> <!-- WarLaunchers --> @@ -274,7 +274,7 @@ <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> - <version>4.3.11.Final</version> + <version>5.2.12.Final</version> <scope>provided</scope> </dependency> -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.