Skip to content

Commit

Permalink
WW-5482 Moves locale related code into org.apache.struts2.locale
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Nov 2, 2024
1 parent 026c992 commit f7b6bc2
Show file tree
Hide file tree
Showing 29 changed files with 333 additions and 140 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/org/apache/struts2/ActionSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.apache.struts2.inject.Container;
import org.apache.struts2.inject.Inject;
import org.apache.struts2.interceptor.ValidationAware;
import org.apache.struts2.locale.LocaleProvider;
import org.apache.struts2.locale.LocaleProviderFactory;
import org.apache.struts2.text.TextProvider;
import org.apache.struts2.text.TextProviderFactory;
import org.apache.struts2.util.ValueStack;
Expand Down
383 changes: 286 additions & 97 deletions core/src/main/java/org/apache/struts2/StrutsConstants.java

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions core/src/main/java/org/apache/struts2/components/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import java.io.Writer;
import java.util.ResourceBundle;

import org.apache.struts2.LocaleProviderFactory;
import org.apache.struts2.locale.LocaleProviderFactory;
import org.apache.struts2.text.LocalizedTextProvider;
import org.apache.struts2.text.TextProviderFactory;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.StrutsException;

import org.apache.struts2.LocaleProvider;
import org.apache.struts2.locale.LocaleProvider;
import org.apache.struts2.text.TextProvider;
import org.apache.struts2.inject.Inject;
import org.apache.struts2.util.ValueStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.struts2.ActionProxyFactory;
import org.apache.struts2.FileManager;
import org.apache.struts2.FileManagerFactory;
import org.apache.struts2.LocaleProviderFactory;
import org.apache.struts2.locale.LocaleProviderFactory;
import org.apache.struts2.text.LocalizedTextProvider;
import org.apache.struts2.ObjectFactory;
import org.apache.struts2.StrutsConstants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
package org.apache.struts2.config.impl;

import org.apache.struts2.ActionContext;
import org.apache.struts2.DefaultLocaleProviderFactory;
import org.apache.struts2.locale.DefaultLocaleProviderFactory;
import org.apache.struts2.text.DefaultTextProvider;
import org.apache.struts2.FileManager;
import org.apache.struts2.FileManagerFactory;
import org.apache.struts2.LocaleProviderFactory;
import org.apache.struts2.locale.LocaleProviderFactory;
import org.apache.struts2.text.LocalizedTextProvider;
import org.apache.struts2.ObjectFactory;
import org.apache.struts2.text.StrutsTextProviderFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.struts2.conversion.impl;

import org.apache.struts2.ActionContext;
import org.apache.struts2.LocaleProviderFactory;
import org.apache.struts2.locale.LocaleProviderFactory;
import org.apache.struts2.conversion.TypeConverter;
import org.apache.struts2.inject.Container;
import org.apache.struts2.inject.Inject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.apache.struts2.ActionProxyFactory;
import org.apache.struts2.FileManager;
import org.apache.struts2.FileManagerFactory;
import org.apache.struts2.LocaleProviderFactory;
import org.apache.struts2.locale.LocaleProviderFactory;
import org.apache.struts2.ObjectFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsConstants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.struts2.dispatcher.multipart;

import org.apache.struts2.LocaleProvider;
import org.apache.struts2.locale.LocaleProvider;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.dispatcher.LocalizedMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package org.apache.struts2.interceptor;

import org.apache.struts2.LocaleProvider;
import org.apache.struts2.LocaleProviderFactory;
import org.apache.struts2.locale.LocaleProvider;
import org.apache.struts2.locale.LocaleProviderFactory;
import org.apache.struts2.text.TextProvider;
import org.apache.struts2.text.TextProviderFactory;
import org.apache.struts2.inject.Container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
package org.apache.struts2.interceptor;

import org.apache.struts2.ActionInvocation;
import org.apache.struts2.LocaleProvider;
import org.apache.struts2.LocaleProviderFactory;
import org.apache.struts2.locale.LocaleProvider;
import org.apache.struts2.locale.LocaleProviderFactory;
import org.apache.struts2.inject.Inject;
import org.apache.struts2.interceptor.AbstractInterceptor;
import org.apache.struts2.util.TextParseUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2;
package org.apache.struts2.locale;

import org.apache.commons.lang3.LocaleUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.struts2.ActionContext;

import java.util.Locale;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2;
package org.apache.struts2.locale;

public class DefaultLocaleProviderFactory implements LocaleProviderFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2;
package org.apache.struts2.locale;

import org.apache.commons.lang3.LocaleUtils;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -25,22 +25,18 @@

/**
* Indicates that the implementing class can provide its own {@link Locale}.
*
* <p>
* This is useful for when an action may wish override the default locale. All that is
* needed is to implement this interface and return your own custom locale.
* The {@link org.apache.struts2.text.TextProvider} interface uses this interface
* heavily for retrieving internationalized messages from resource bundles.
* </p>
*
* @author Jason Carreira
*/
public interface LocaleProvider {

/**
* Gets the provided locale.
*
* @return the locale.
* @return the locale.
*/
Locale getLocale();

Expand All @@ -62,6 +58,7 @@ public interface LocaleProvider {

/**
* Tries to convert provided locale string into {@link Locale} or returns null
*
* @param localeStr a String representing locale, e.g.: en_EN
* @return instance of {@link Locale} or null
* @since Struts 6.5.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2;
package org.apache.struts2.locale;

import org.apache.struts2.ActionSupport;

/**
* Allows delegate creation of {@link LocaleProvider} to another implementation provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.struts2.text;

import org.apache.struts2.LocaleProvider;
import org.apache.struts2.locale.LocaleProvider;

import java.util.ResourceBundle;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.struts2.text;

import org.apache.struts2.LocaleProviderFactory;
import org.apache.struts2.locale.LocaleProviderFactory;
import org.apache.struts2.inject.Inject;

import java.util.ResourceBundle;
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/org/apache/struts2/text/TextProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.struts2.text;

import org.apache.struts2.locale.LocaleProvider;
import org.apache.struts2.util.ValueStack;

import java.util.List;
Expand All @@ -33,9 +34,9 @@
* global texts to be defined for an application base class.
*
* <p>
* You can override {@link org.apache.struts2.LocaleProvider#getLocale()} to change the behaviour of how
* You can override {@link LocaleProvider#getLocale()} to change the behaviour of how
* to choose locale for the bundles that are returned. Typically you would
* use the {@link org.apache.struts2.LocaleProvider} interface to get the users configured locale.
* use the {@link LocaleProvider} interface to get the users configured locale.
* </p>
*
* <p>
Expand All @@ -56,7 +57,7 @@
* </p>
* @author Jason Carreira
* @author Rainer Hermanns
* @see org.apache.struts2.LocaleProvider
* @see LocaleProvider
* @see TextProviderSupport
*/
public interface TextProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package org.apache.struts2.text;

import org.apache.struts2.LocaleProvider;
import org.apache.struts2.LocaleProviderFactory;
import org.apache.struts2.locale.LocaleProvider;
import org.apache.struts2.locale.LocaleProviderFactory;
import org.apache.struts2.inject.Inject;
import org.apache.struts2.util.ValueStack;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ActionContext;
import org.apache.struts2.text.CompositeTextProvider;
import org.apache.struts2.LocaleProvider;
import org.apache.struts2.LocaleProviderFactory;
import org.apache.struts2.locale.LocaleProvider;
import org.apache.struts2.locale.LocaleProviderFactory;
import org.apache.struts2.text.TextProvider;
import org.apache.struts2.text.TextProviderFactory;
import org.apache.struts2.interceptor.ValidationAware;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.struts2.validator;

import org.apache.struts2.LocaleProvider;
import org.apache.struts2.locale.LocaleProvider;
import org.apache.struts2.text.TextProvider;
import org.apache.struts2.interceptor.ValidationAware;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.apache.struts2.ActionContext;
import org.apache.struts2.ActionInvocation;
import org.apache.struts2.LocaleProvider;
import org.apache.struts2.locale.LocaleProvider;
import org.apache.struts2.inject.Inject;
import org.apache.struts2.util.ValueStack;
import freemarker.template.Configuration;
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/resources/struts-beans.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@
scope="singleton"/>
<bean type="org.apache.struts2.text.TextProviderFactory" name="struts"
class="org.apache.struts2.text.StrutsTextProviderFactory" scope="singleton"/>
<bean type="org.apache.struts2.LocaleProviderFactory" name="struts"
class="org.apache.struts2.DefaultLocaleProviderFactory" scope="singleton"/>
<bean type="org.apache.struts2.locale.LocaleProviderFactory" name="struts"
class="org.apache.struts2.locale.DefaultLocaleProviderFactory" scope="singleton"/>

<bean type="org.apache.struts2.components.UrlRenderer" name="struts"
class="org.apache.struts2.components.ServletUrlRenderer"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.struts2;

import org.apache.struts2.locale.LocaleProvider;
import org.junit.Test;

import java.util.Locale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void allowList() throws Exception {

assertThat(providerAllowlist.getProviderAllowlist()).containsExactlyInAnyOrder(
Class.forName("org.apache.struts2.interceptor.ValidationAware"),
Class.forName("org.apache.struts2.LocaleProvider"),
Class.forName("org.apache.struts2.locale.LocaleProvider"),
Class.forName("java.io.Serializable"),
Class.forName("org.apache.struts2.mock.MockResult"),
Class.forName("org.apache.struts2.interceptor.ConditionalInterceptor"),
Expand All @@ -72,7 +72,7 @@ public void allowlist_1only() throws Exception {

assertThat(providerAllowlist.getProviderAllowlist()).containsExactlyInAnyOrder(
Class.forName("org.apache.struts2.interceptor.ValidationAware"),
Class.forName("org.apache.struts2.LocaleProvider"),
Class.forName("org.apache.struts2.locale.LocaleProvider"),
Class.forName("java.io.Serializable"),
Class.forName("org.apache.struts2.mock.MockResult"),
Class.forName("org.apache.struts2.interceptor.ConditionalInterceptor"),
Expand All @@ -96,7 +96,7 @@ public void allowlist_2only() throws Exception {

assertThat(providerAllowlist.getProviderAllowlist()).containsExactlyInAnyOrder(
Class.forName("org.apache.struts2.interceptor.ValidationAware"),
Class.forName("org.apache.struts2.LocaleProvider"),
Class.forName("org.apache.struts2.locale.LocaleProvider"),
Class.forName("java.io.Serializable"),
Class.forName("org.apache.struts2.interceptor.ConditionalInterceptor"),
Class.forName("org.apache.struts2.ActionSupport"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.apache.struts2.ActionContext;
import org.apache.struts2.ActionSupport;
import org.apache.struts2.DefaultLocaleProvider;
import org.apache.struts2.locale.DefaultLocaleProvider;
import org.apache.struts2.ValidationAwareSupport;
import org.apache.struts2.mock.MockActionInvocation;
import org.apache.struts2.mock.MockActionProxy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.apache.struts2.action.Action;
import org.apache.struts2.ActionContext;
import org.apache.struts2.ActionInvocation;
import org.apache.struts2.DefaultLocaleProviderFactory;
import org.apache.struts2.locale.DefaultLocaleProviderFactory;
import org.apache.struts2.mock.MockActionInvocation;
import org.apache.struts2.mock.MockActionProxy;
import junit.framework.TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2;
package org.apache.struts2.locale;

import org.apache.struts2.ActionContext;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.struts2.text;

import org.apache.struts2.LocaleProvider;
import org.apache.struts2.locale.LocaleProvider;
import org.apache.struts2.XWorkTestCase;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.struts2.tiles;

import org.apache.struts2.ActionContext;
import org.apache.struts2.LocaleProviderFactory;
import org.apache.struts2.locale.LocaleProviderFactory;
import org.apache.struts2.config.ConfigurationException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down

0 comments on commit f7b6bc2

Please sign in to comment.