You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2012/07/21 13:15:35 UTC
svn commit: r1364066 - in /struts/struts2/trunk:
core/src/main/java/org/apache/struts2/
core/src/main/java/org/apache/struts2/config/
core/src/main/java/org/apache/struts2/interceptor/ core/src/main/resources/
core/src/main/resources/org/apache/struts2...
Author: lukaszlenart
Date: Sat Jul 21 11:15:34 2012
New Revision: 1364066
URL: http://svn.apache.org/viewvc?rev=1364066&view=rev
Log:
WW-3552 adds usage of TextProvider to allow provide user's implementation
Added:
struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java
Removed:
struts/struts2/trunk/core/src/test/resources/org/apache/struts2/interceptor/
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/TokenInterceptor.java
struts/struts2/trunk/core/src/main/resources/org/apache/struts2/struts-messages.properties
struts/struts2/trunk/core/src/main/resources/struts-default.xml
struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java
struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/TextProviderFactory.java
struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/TextProviderSupport.java
struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java?rev=1364066&r1=1364065&r2=1364066&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java Sat Jul 21 11:15:34 2012
@@ -194,6 +194,9 @@ public final class StrutsConstants {
/** XWork default text provider */
public static final String STRUTS_XWORKTEXTPROVIDER = "struts.xworkTextProvider";
+ /** The {@link com.opensymphony.xwork2.LocaleProvider} implementation class */
+ public static final String STRUTS_LOCALE_PROVIDER = "struts.localeProvider";
+
/** The name of the parameter to create when mapping an id (used by some action mappers) */
public static final String STRUTS_ID_PARAMETER_NAME = "struts.mapper.idParameterName";
@@ -239,4 +242,5 @@ public final class StrutsConstants {
public static final String STRUTS_CONVERTER_DATE = "struts.converter.date";
public static final String STRUTS_CONVERTER_NUMBER = "struts.converter.number";
public static final String STRUTS_CONVERTER_STRING = "struts.converter.string";
+
}
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java?rev=1364066&r1=1364065&r2=1364066&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java Sat Jul 21 11:15:34 2012
@@ -24,6 +24,7 @@ package org.apache.struts2.config;
import com.opensymphony.xwork2.ActionProxyFactory;
import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.FileManagerFactory;
+import com.opensymphony.xwork2.LocaleProvider;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.TextProvider;
import com.opensymphony.xwork2.UnknownHandlerManager;
@@ -180,6 +181,12 @@ import java.util.StringTokenizer;
* <td>Allows provide custom TextProvider for whole application</td>
* </tr>
* <tr>
+ * <td>com.opensymphony.xwork2.LocaleProvider</td>
+ * <td>struts.localeProvider</td>
+ * <td>singleton</td>
+ * <td>Allows provide custom TextProvider for whole application</td>
+ * </tr>
+ * <tr>
* <td>org.apache.struts2.components.UrlRenderer</td>
* <td>struts.urlRenderer</td>
* <td>singleton</td>
@@ -282,6 +289,7 @@ public class BeanSelectionProvider imple
alias(FileManagerFactory.class, StrutsConstants.STRUTS_FILE_MANAGER_FACTORY, builder, props);
alias(XWorkConverter.class, StrutsConstants.STRUTS_XWORKCONVERTER, builder, props);
alias(TextProvider.class, StrutsConstants.STRUTS_XWORKTEXTPROVIDER, builder, props, Scope.DEFAULT);
+ alias(LocaleProvider.class, StrutsConstants.STRUTS_LOCALE_PROVIDER, builder, props);
alias(ActionProxyFactory.class, StrutsConstants.STRUTS_ACTIONPROXYFACTORY, builder, props);
alias(ObjectTypeDeterminer.class, StrutsConstants.STRUTS_OBJECTTYPEDETERMINER, builder, props);
alias(ActionMapper.class, StrutsConstants.STRUTS_MAPPER_CLASS, builder, props);
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java?rev=1364066&r1=1364065&r2=1364066&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java Sat Jul 21 11:15:34 2012
@@ -24,10 +24,13 @@ package org.apache.struts2.interceptor;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
+import com.opensymphony.xwork2.LocaleProvider;
+import com.opensymphony.xwork2.TextProvider;
+import com.opensymphony.xwork2.TextProviderFactory;
import com.opensymphony.xwork2.ValidationAware;
+import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
-import com.opensymphony.xwork2.util.LocalizedTextUtil;
import com.opensymphony.xwork2.util.PatternMatcher;
import com.opensymphony.xwork2.util.TextParseUtil;
import com.opensymphony.xwork2.util.logging.Logger;
@@ -37,7 +40,14 @@ import org.apache.struts2.dispatcher.mul
import javax.servlet.http.HttpServletRequest;
import java.io.File;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* <!-- START SNIPPET: description -->
@@ -145,27 +155,27 @@ import java.util.*;
* <pre>
* <!-- START SNIPPET: example-action -->
* package com.example;
- * <p/>
+ *
* import java.io.File;
* import com.opensymphony.xwork2.ActionSupport;
- * <p/>
+ *
* public UploadAction extends ActionSupport {
* private File file;
* private String contentType;
* private String filename;
- * <p/>
+ *
* public void setUpload(File file) {
* this.file = file;
* }
- * <p/>
+ *
* public void setUploadContentType(String contentType) {
* this.contentType = contentType;
* }
- * <p/>
+ *
* public void setUploadFileName(String filename) {
* this.filename = filename;
* }
- * <p/>
+ *
* public String execute() {
* //...
* return SUCCESS;
@@ -179,23 +189,22 @@ public class FileUploadInterceptor exten
private static final long serialVersionUID = -4764627478894962478L;
protected static final Logger LOG = LoggerFactory.getLogger(FileUploadInterceptor.class);
- private static final String DEFAULT_MESSAGE = "no.message.found";
-
- protected boolean useActionMessageBundle;
protected Long maximumSize;
protected Set<String> allowedTypesSet = Collections.emptySet();
protected Set<String> allowedExtensionsSet = Collections.emptySet();
private PatternMatcher matcher;
+ private Container container;
@Inject
public void setMatcher(PatternMatcher matcher) {
this.matcher = matcher;
}
- public void setUseActionMessageBundle(String value) {
- this.useActionMessageBundle = Boolean.valueOf(value);
+ @Inject
+ public void setContainer(Container container) {
+ this.container = container;
}
/**
@@ -237,7 +246,7 @@ public class FileUploadInterceptor exten
if (!(request instanceof MultiPartRequestWrapper)) {
if (LOG.isDebugEnabled()) {
ActionProxy proxy = invocation.getProxy();
- LOG.debug(getTextMessage("struts.messages.bypass.request", new Object[]{proxy.getNamespace(), proxy.getActionName()}, ac.getLocale()));
+ LOG.debug(getTextMessage("struts.messages.bypass.request", new String[]{proxy.getNamespace(), proxy.getActionName()}));
}
return invocation.invoke();
@@ -289,7 +298,7 @@ public class FileUploadInterceptor exten
String fileNameName = inputName + "FileName";
for (int index = 0; index < files.length; index++) {
- if (acceptFile(action, files[index], fileName[index], contentType[index], inputName, validation, ac.getLocale())) {
+ if (acceptFile(action, files[index], fileName[index], contentType[index], inputName, validation)) {
acceptedFiles.add(files[index]);
acceptedContentTypes.add(contentType[index]);
acceptedFileNames.add(fileName[index]);
@@ -306,12 +315,12 @@ public class FileUploadInterceptor exten
}
} else {
if (LOG.isWarnEnabled()) {
- LOG.warn(getTextMessage(action, "struts.messages.invalid.file", new Object[]{inputName}, ac.getLocale()));
+ LOG.warn(getTextMessage(action, "struts.messages.invalid.file", new String[]{inputName}));
}
}
} else {
if (LOG.isWarnEnabled()) {
- LOG.warn(getTextMessage(action, "struts.messages.invalid.content.type", new Object[]{inputName}, ac.getLocale()));
+ LOG.warn(getTextMessage(action, "struts.messages.invalid.content.type", new String[]{inputName}));
}
}
}
@@ -329,48 +338,47 @@ public class FileUploadInterceptor exten
* @param inputName - inputName of the file.
* @param validation - Non-null ValidationAware if the action implements ValidationAware, allowing for better
* logging.
- * @param locale
* @return true if the proposed file is acceptable by contentType and size.
*/
- protected boolean acceptFile(Object action, File file, String filename, String contentType, String inputName, ValidationAware validation, Locale locale) {
+ protected boolean acceptFile(Object action, File file, String filename, String contentType, String inputName, ValidationAware validation) {
boolean fileIsAcceptable = false;
// If it's null the upload failed
if (file == null) {
- String errMsg = getTextMessage(action, "struts.messages.error.uploading", new Object[]{inputName}, locale);
+ String errMsg = getTextMessage(action, "struts.messages.error.uploading", new String[]{inputName});
if (validation != null) {
validation.addFieldError(inputName, errMsg);
}
if (LOG.isWarnEnabled()) {
- LOG.warn(errMsg);
+ LOG.warn(errMsg);
}
} else if (maximumSize != null && maximumSize < file.length()) {
- String errMsg = getTextMessage(action, "struts.messages.error.file.too.large", new Object[]{inputName, filename, file.getName(), "" + file.length()}, locale);
+ String errMsg = getTextMessage(action, "struts.messages.error.file.too.large", new String[]{inputName, filename, file.getName(), "" + file.length()});
if (validation != null) {
validation.addFieldError(inputName, errMsg);
}
if (LOG.isWarnEnabled()) {
- LOG.warn(errMsg);
+ LOG.warn(errMsg);
}
} else if ((!allowedTypesSet.isEmpty()) && (!containsItem(allowedTypesSet, contentType))) {
- String errMsg = getTextMessage(action, "struts.messages.error.content.type.not.allowed", new Object[]{inputName, filename, file.getName(), contentType}, locale);
+ String errMsg = getTextMessage(action, "struts.messages.error.content.type.not.allowed", new String[]{inputName, filename, file.getName(), contentType});
if (validation != null) {
validation.addFieldError(inputName, errMsg);
}
if (LOG.isWarnEnabled()) {
- LOG.warn(errMsg);
+ LOG.warn(errMsg);
}
} else if ((!allowedExtensionsSet.isEmpty()) && (!hasAllowedExtension(allowedExtensionsSet, filename))) {
- String errMsg = getTextMessage(action, "struts.messages.error.file.extension.not.allowed", new Object[]{inputName, filename, file.getName(), contentType}, locale);
+ String errMsg = getTextMessage(action, "struts.messages.error.file.extension.not.allowed", new String[]{inputName, filename, file.getName(), contentType});
if (validation != null) {
validation.addFieldError(inputName, errMsg);
}
if (LOG.isWarnEnabled()) {
- LOG.warn(errMsg);
+ LOG.warn(errMsg);
}
} else {
fileIsAcceptable = true;
@@ -426,21 +434,34 @@ public class FileUploadInterceptor exten
return result;
}
- private String getTextMessage(String messageKey, Object[] args, Locale locale) {
- return getTextMessage(null, messageKey, args, locale);
+ protected String getTextMessage(String messageKey, String[] args) {
+ return getTextMessage(this, messageKey, args);
}
- private String getTextMessage(Object action, String messageKey, Object[] args, Locale locale) {
- if (args == null || args.length == 0) {
- if (action != null && useActionMessageBundle) {
- return LocalizedTextUtil.findText(action.getClass(), messageKey, locale);
- }
- return LocalizedTextUtil.findText(this.getClass(), messageKey, locale);
+ protected String getTextMessage(Object action, String messageKey, String[] args) {
+ if (action instanceof TextProvider) {
+ return ((TextProvider) action).getText(messageKey, args);
+ }
+ return getTextProvider(action).getText(messageKey, args);
+ }
+
+ private TextProvider getTextProvider(Object action) {
+ TextProviderFactory tpf = new TextProviderFactory();
+ if (container != null) {
+ container.inject(tpf);
+ }
+ LocaleProvider localeProvider = getLocaleProvider(action);
+ return tpf.createInstance(action.getClass(), localeProvider);
+ }
+
+ private LocaleProvider getLocaleProvider(Object action) {
+ LocaleProvider localeProvider;
+ if (action instanceof LocaleProvider) {
+ localeProvider = (LocaleProvider) action;
} else {
- if (action != null && useActionMessageBundle) {
- return LocalizedTextUtil.findText(action.getClass(), messageKey, locale, DEFAULT_MESSAGE, args);
- }
- return LocalizedTextUtil.findText(this.getClass(), messageKey, locale, DEFAULT_MESSAGE, args);
+ localeProvider = container.getInstance(LocaleProvider.class);
}
+ return localeProvider;
}
+
}
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/TokenInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/TokenInterceptor.java?rev=1364066&r1=1364065&r2=1364066&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/TokenInterceptor.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/TokenInterceptor.java Sat Jul 21 11:15:34 2012
@@ -22,9 +22,10 @@
package org.apache.struts2.interceptor;
import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.TextProvider;
import com.opensymphony.xwork2.ValidationAware;
+import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
-import com.opensymphony.xwork2.util.LocalizedTextUtil;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.util.TokenHelper;
@@ -120,6 +121,16 @@ public class TokenInterceptor extends Me
public static final String INVALID_TOKEN_CODE = "invalid.token";
+ private static final String INVALID_TOKEN_MESSAGE_KEY = "struts.messages.invalid.token";
+ private static final String DEFAULT_ERROR_MESSAGE = "The form has already been processed or no token was supplied, please try again.";
+
+ private TextProvider textProvider;
+
+ @Inject
+ public void setTextProvider(TextProvider textProvider) {
+ this.textProvider = textProvider;
+ }
+
/**
* @see com.opensymphony.xwork2.interceptor.MethodFilterInterceptor#doIntercept(com.opensymphony.xwork2.ActionInvocation)
*/
@@ -149,9 +160,7 @@ public class TokenInterceptor extends Me
*/
protected String handleInvalidToken(ActionInvocation invocation) throws Exception {
Object action = invocation.getAction();
- String errorMessage = LocalizedTextUtil.findText(this.getClass(), "struts.messages.invalid.token",
- invocation.getInvocationContext().getLocale(),
- "The form has already been processed or no token was supplied, please try again.", new Object[0]);
+ String errorMessage = getErrorMessage(invocation);
if (action instanceof ValidationAware) {
((ValidationAware) action).addActionError(errorMessage);
@@ -162,6 +171,14 @@ public class TokenInterceptor extends Me
return INVALID_TOKEN_CODE;
}
+ protected String getErrorMessage(ActionInvocation invocation) {
+ Object action = invocation.getAction();
+ if (action instanceof TextProvider) {
+ return ((TextProvider) action).getText(INVALID_TOKEN_MESSAGE_KEY, DEFAULT_ERROR_MESSAGE);
+ }
+ return textProvider.getText(INVALID_TOKEN_MESSAGE_KEY, DEFAULT_ERROR_MESSAGE);
+ }
+
/**
* Called when a valid token is found. This method invokes the action by can be changed to do something more
* interesting.
Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/struts-messages.properties
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/struts-messages.properties?rev=1364066&r1=1364065&r2=1364066&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/struts-messages.properties (original)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/struts-messages.properties Sat Jul 21 11:15:34 2012
@@ -27,7 +27,7 @@ struts.messages.invalid.file=Could not f
struts.messages.invalid.content.type=Could not find a Content-Type for {0}. Verify that a valid file was submitted.
struts.messages.removing.file=Removing file {0} {1}
struts.messages.error.uploading=Error uploading: {0}
-struts.messages.error.file.too.large=File too large: {0} "{1}" "{2}" {3}
+struts.messages.error.file.too.large=The file is to large to be uploaded: {0} "{1}" "{2}" {3}
struts.messages.error.content.type.not.allowed=Content-Type not allowed: {0} "{1}" "{2}" {3}
struts.messages.error.file.extension.not.allowed=File extension not allowed: {0} "{1}" "{2}" {3}
Modified: struts/struts2/trunk/core/src/main/resources/struts-default.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/struts-default.xml?rev=1364066&r1=1364065&r2=1364066&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/struts-default.xml (original)
+++ struts/struts2/trunk/core/src/main/resources/struts-default.xml Sat Jul 21 11:15:34 2012
@@ -74,6 +74,7 @@
<bean type="com.opensymphony.xwork2.conversion.impl.StringConverter" name="struts" class="com.opensymphony.xwork2.conversion.impl.StringConverter" scope="singleton"/>
<bean type="com.opensymphony.xwork2.TextProvider" name="struts" class="com.opensymphony.xwork2.TextProviderSupport" scope="default" />
+ <bean type="com.opensymphony.xwork2.LocaleProvider" name="struts" class="com.opensymphony.xwork2.DefaultLocaleProvider" scope="singleton" />
<bean type="org.apache.struts2.components.UrlRenderer" name="struts" class="org.apache.struts2.components.ServletUrlRenderer"/>
<bean type="org.apache.struts2.views.util.UrlHelper" name="struts" class="org.apache.struts2.views.util.DefaultUrlHelper"/>
Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java?rev=1364066&r1=1364065&r2=1364066&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java (original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java Sat Jul 21 11:15:34 2012
@@ -29,6 +29,7 @@ import com.opensymphony.xwork2.util.Clas
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsTestCase;
+import org.apache.struts2.TestAction;
import org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest;
import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -40,7 +41,6 @@ import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
@@ -51,11 +51,12 @@ public class FileUploadInterceptorTest e
private FileUploadInterceptor interceptor;
private File tempDir;
+ private TestAction action;
public void testAcceptFileWithEmptyAllowedTypesAndExtensions() throws Exception {
// when allowed type is empty
ValidationAwareSupport validation = new ValidationAwareSupport();
- boolean ok = interceptor.acceptFile(null, new File(""), "filename", "text/plain", "inputName", validation, Locale.getDefault());
+ boolean ok = interceptor.acceptFile(action, new File(""), "filename", "text/plain", "inputName", validation);
assertTrue(ok);
assertTrue(validation.getFieldErrors().isEmpty());
@@ -67,7 +68,7 @@ public class FileUploadInterceptorTest e
// when file is of allowed types
ValidationAwareSupport validation = new ValidationAwareSupport();
- boolean ok = interceptor.acceptFile(null, new File(""), "filename.txt", "text/plain", "inputName", validation, Locale.getDefault());
+ boolean ok = interceptor.acceptFile(action, new File(""), "filename.txt", "text/plain", "inputName", validation);
assertTrue(ok);
assertTrue(validation.getFieldErrors().isEmpty());
@@ -75,7 +76,7 @@ public class FileUploadInterceptorTest e
// when file is not of allowed types
validation = new ValidationAwareSupport();
- boolean notOk = interceptor.acceptFile(null, new File(""), "filename.html", "text/html", "inputName", validation, Locale.getDefault());
+ boolean notOk = interceptor.acceptFile(action, new File(""), "filename.html", "text/html", "inputName", validation);
assertFalse(notOk);
assertFalse(validation.getFieldErrors().isEmpty());
@@ -87,7 +88,7 @@ public class FileUploadInterceptorTest e
interceptor.setAllowedTypes("text/*");
ValidationAwareSupport validation = new ValidationAwareSupport();
- boolean ok = interceptor.acceptFile(null, new File(""), "filename.txt", "text/plain", "inputName", validation, Locale.getDefault());
+ boolean ok = interceptor.acceptFile(action, new File(""), "filename.txt", "text/plain", "inputName", validation);
assertTrue(ok);
assertTrue(validation.getFieldErrors().isEmpty());
@@ -95,7 +96,7 @@ public class FileUploadInterceptorTest e
interceptor.setAllowedTypes("text/h*");
validation = new ValidationAwareSupport();
- boolean notOk = interceptor.acceptFile(null, new File(""), "filename.html", "text/plain", "inputName", validation, Locale.getDefault());
+ boolean notOk = interceptor.acceptFile(action, new File(""), "filename.html", "text/plain", "inputName", validation);
assertFalse(notOk);
assertFalse(validation.getFieldErrors().isEmpty());
@@ -107,7 +108,7 @@ public class FileUploadInterceptorTest e
// when file is of allowed extensions
ValidationAwareSupport validation = new ValidationAwareSupport();
- boolean ok = interceptor.acceptFile(null, new File(""), "filename.txt", "text/plain", "inputName", validation, Locale.getDefault());
+ boolean ok = interceptor.acceptFile(action, new File(""), "filename.txt", "text/plain", "inputName", validation);
assertTrue(ok);
assertTrue(validation.getFieldErrors().isEmpty());
@@ -115,7 +116,7 @@ public class FileUploadInterceptorTest e
// when file is not of allowed extensions
validation = new ValidationAwareSupport();
- boolean notOk = interceptor.acceptFile(null, new File(""), "filename.html", "text/html", "inputName", validation, Locale.getDefault());
+ boolean notOk = interceptor.acceptFile(action, new File(""), "filename.html", "text/html", "inputName", validation);
assertFalse(notOk);
assertFalse(validation.getFieldErrors().isEmpty());
@@ -124,7 +125,7 @@ public class FileUploadInterceptorTest e
//test with multiple extensions
interceptor.setAllowedExtensions(".txt,.lol");
validation = new ValidationAwareSupport();
- ok = interceptor.acceptFile(null, new File(""), "filename.lol", "text/plain", "inputName", validation, Locale.getDefault());
+ ok = interceptor.acceptFile(action, new File(""), "filename.lol", "text/plain", "inputName", validation);
assertTrue(ok);
assertTrue(validation.getFieldErrors().isEmpty());
@@ -137,7 +138,7 @@ public class FileUploadInterceptorTest e
// when file is not of allowed types
ValidationAwareSupport validation = new ValidationAwareSupport();
- boolean notOk = interceptor.acceptFile(null, null, "filename.html", "text/html", "inputName", validation, Locale.getDefault());
+ boolean notOk = interceptor.acceptFile(action, null, "filename.html", "text/html", "inputName", validation);
assertFalse(notOk);
assertFalse(validation.getFieldErrors().isEmpty());
@@ -159,7 +160,7 @@ public class FileUploadInterceptorTest e
URL url = ClassLoaderUtil.getResource("log4j.properties", FileUploadInterceptorTest.class);
File file = new File(new URI(url.toString()));
assertTrue("log4j.properties should be in src/test folder", file.exists());
- boolean notOk = interceptor.acceptFile(null, file, "filename", "text/html", "inputName", validation, Locale.getDefault());
+ boolean notOk = interceptor.acceptFile(action, file, "filename", "text/html", "inputName", validation);
assertFalse(notOk);
assertFalse(validation.getFieldErrors().isEmpty());
@@ -361,6 +362,7 @@ public class FileUploadInterceptorTest e
protected void setUp() throws Exception {
super.setUp();
+ action = new TestAction();
interceptor = new FileUploadInterceptor();
container.inject(interceptor);
tempDir = File.createTempFile("struts", "fileupload");
Added: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java?rev=1364066&view=auto
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java (added)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java Sat Jul 21 11:15:34 2012
@@ -0,0 +1,27 @@
+package com.opensymphony.xwork2;
+
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+
+import java.util.Locale;
+
+/**
+ * Default implementation of {@link LocaleProvider}
+ */
+public class DefaultLocaleProvider implements LocaleProvider {
+
+ private final static Logger LOG = LoggerFactory.getLogger(DefaultLocaleProvider.class);
+
+ public Locale getLocale() {
+ ActionContext ctx = ActionContext.getContext();
+ if (ctx != null) {
+ return ctx.getLocale();
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Action context not initialized");
+ }
+ return null;
+ }
+ }
+
+}
Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/TextProviderFactory.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/TextProviderFactory.java?rev=1364066&r1=1364065&r2=1364066&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/TextProviderFactory.java (original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/TextProviderFactory.java Sat Jul 21 11:15:34 2012
@@ -34,16 +34,8 @@ public class TextProviderFactory {
this.textProvider = textProvider;
}
- protected TextProvider getTextProvider() {
- if (this.textProvider == null) {
- return new TextProviderSupport();
- } else {
- return textProvider;
- }
- }
-
public TextProvider createInstance(Class clazz, LocaleProvider provider) {
- TextProvider instance = getTextProvider();
+ TextProvider instance = getTextProvider(clazz, provider);
if (instance instanceof ResourceBundleTextProvider) {
((ResourceBundleTextProvider) instance).setClazz(clazz);
((ResourceBundleTextProvider) instance).setLocaleProvider(provider);
@@ -52,11 +44,28 @@ public class TextProviderFactory {
}
public TextProvider createInstance(ResourceBundle bundle, LocaleProvider provider) {
- TextProvider instance = getTextProvider();
+ TextProvider instance = getTextProvider(bundle, provider);
if (instance instanceof ResourceBundleTextProvider) {
((ResourceBundleTextProvider) instance).setBundle(bundle);
((ResourceBundleTextProvider) instance).setLocaleProvider(provider);
}
return instance;
}
+
+ protected TextProvider getTextProvider(Class clazz, LocaleProvider provider) {
+ if (this.textProvider == null) {
+ return new TextProviderSupport(clazz, provider);
+ } else {
+ return textProvider;
+ }
+ }
+
+ private TextProvider getTextProvider(ResourceBundle bundle, LocaleProvider provider) {
+ if (this.textProvider == null) {
+ return new TextProviderSupport(bundle, provider);
+ } else {
+ return textProvider;
+ }
+ }
+
}
Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/TextProviderSupport.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/TextProviderSupport.java?rev=1364066&r1=1364065&r2=1364066&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/TextProviderSupport.java (original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/TextProviderSupport.java Sat Jul 21 11:15:34 2012
@@ -15,10 +15,15 @@
*/
package com.opensymphony.xwork2;
+import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.LocalizedTextUtil;
import com.opensymphony.xwork2.util.ValueStack;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
/**
@@ -79,6 +84,7 @@ public class TextProviderSupport impleme
/**
* @param localeProvider a locale provider.
*/
+ @Inject
public void setLocaleProvider(LocaleProvider localeProvider) {
this.localeProvider = localeProvider;
}
Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java?rev=1364066&r1=1364065&r2=1364066&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java (original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java Sat Jul 21 11:15:34 2012
@@ -2,10 +2,12 @@ package com.opensymphony.xwork2.config.p
import com.opensymphony.xwork2.ActionProxyFactory;
import com.opensymphony.xwork2.DefaultActionProxyFactory;
+import com.opensymphony.xwork2.DefaultLocaleProvider;
import com.opensymphony.xwork2.DefaultTextProvider;
import com.opensymphony.xwork2.DefaultUnknownHandlerManager;
import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.FileManagerFactory;
+import com.opensymphony.xwork2.LocaleProvider;
import com.opensymphony.xwork2.TextProvider;
import com.opensymphony.xwork2.TextProviderSupport;
import com.opensymphony.xwork2.UnknownHandlerManager;
@@ -122,6 +124,7 @@ public class XWorkConfigurationProvider
.factory(ActionValidatorManager.class, "no-annotations", DefaultActionValidatorManager.class, Scope.SINGLETON)
.factory(TextProvider.class, "system", DefaultTextProvider.class, Scope.SINGLETON)
.factory(TextProvider.class, TextProviderSupport.class, Scope.SINGLETON)
+ .factory(LocaleProvider.class, DefaultLocaleProvider.class, Scope.SINGLETON)
.factory(OgnlUtil.class, Scope.SINGLETON)
.factory(XWorkBasicConverter.class, Scope.SINGLETON)
.factory(CollectionConverter.class, Scope.SINGLETON)