diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ValidationAware.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ValidationAware.java index c959f19d77..aa9e6f5ff4 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ValidationAware.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ValidationAware.java @@ -18,9 +18,89 @@ */ package com.opensymphony.xwork2.interceptor; +import java.util.Collection; +import java.util.List; +import java.util.Map; + /** * @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.ValidationAware} instead. */ @Deprecated public interface ValidationAware extends org.apache.struts2.interceptor.ValidationAware { + + static ValidationAware adapt(org.apache.struts2.interceptor.ValidationAware actualValidation) { + if (actualValidation instanceof ValidationAware) { + return (ValidationAware) actualValidation; + } + return actualValidation != null ? new LegacyAdapter(actualValidation) : null; + } + + class LegacyAdapter implements ValidationAware { + + private final org.apache.struts2.interceptor.ValidationAware adaptee; + + private LegacyAdapter(org.apache.struts2.interceptor.ValidationAware adaptee) { + this.adaptee = adaptee; + } + + @Override + public void setActionErrors(Collection errorMessages) { + adaptee.setActionErrors(errorMessages); + } + + @Override + public Collection getActionErrors() { + return adaptee.getActionErrors(); + } + + @Override + public void setActionMessages(Collection messages) { + adaptee.setActionMessages(messages); + } + + @Override + public Collection getActionMessages() { + return adaptee.getActionMessages(); + } + + @Override + public void setFieldErrors(Map> errorMap) { + adaptee.setFieldErrors(errorMap); + } + + @Override + public Map> getFieldErrors() { + return adaptee.getFieldErrors(); + } + + @Override + public void addActionError(String anErrorMessage) { + adaptee.addActionError(anErrorMessage); + } + + @Override + public void addActionMessage(String aMessage) { + adaptee.addActionMessage(aMessage); + } + + @Override + public void addFieldError(String fieldName, String errorMessage) { + adaptee.addFieldError(fieldName, errorMessage); + } + + @Override + public boolean hasActionErrors() { + return adaptee.hasActionErrors(); + } + + @Override + public boolean hasActionMessages() { + return adaptee.hasActionMessages(); + } + + @Override + public boolean hasFieldErrors() { + return adaptee.hasFieldErrors(); + } + } } diff --git a/core/src/main/java/com/opensymphony/xwork2/util/DebugUtils.java b/core/src/main/java/com/opensymphony/xwork2/util/DebugUtils.java index 3fdf8b0a70..ff7042b596 100644 --- a/core/src/main/java/com/opensymphony/xwork2/util/DebugUtils.java +++ b/core/src/main/java/com/opensymphony/xwork2/util/DebugUtils.java @@ -19,8 +19,8 @@ package com.opensymphony.xwork2.util; import com.opensymphony.xwork2.TextProvider; -import com.opensymphony.xwork2.interceptor.ValidationAware; import org.apache.logging.log4j.Logger; +import org.apache.struts2.interceptor.ValidationAware; /** * @since 6.5.0 diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java b/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java index bc8c88875c..b0b41e7196 100644 --- a/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java +++ b/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java @@ -18,13 +18,23 @@ */ package com.opensymphony.xwork2.validator; -import com.opensymphony.xwork2.*; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.CompositeTextProvider; +import com.opensymphony.xwork2.LocaleProvider; +import com.opensymphony.xwork2.LocaleProviderFactory; +import com.opensymphony.xwork2.StrutsTextProviderFactory; +import com.opensymphony.xwork2.TextProvider; +import com.opensymphony.xwork2.TextProviderFactory; import com.opensymphony.xwork2.interceptor.ValidationAware; import com.opensymphony.xwork2.util.ValueStack; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; /** * A default implementation of the {@link ValidatorContext} interface. @@ -233,8 +243,8 @@ protected static LocaleProvider makeLocaleProvider(Object object) { } protected static ValidationAware makeValidationAware(Object object) { - if (object instanceof ValidationAware) { - return (ValidationAware) object; + if (object instanceof org.apache.struts2.interceptor.ValidationAware) { + return ValidationAware.adapt((org.apache.struts2.interceptor.ValidationAware) object); } else { return new LoggingValidationAware(object); } diff --git a/core/src/main/java/org/apache/struts2/interceptor/TokenInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/TokenInterceptor.java index c6859d05ba..b67ef6422d 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/TokenInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/TokenInterceptor.java @@ -21,7 +21,6 @@ import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.TextProvider; import com.opensymphony.xwork2.TextProviderFactory; -import com.opensymphony.xwork2.interceptor.ValidationAware; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor; import org.apache.logging.log4j.LogManager; diff --git a/plugins/junit/src/main/java/org/apache/struts2/junit/StrutsJUnit4TestCase.java b/plugins/junit/src/main/java/org/apache/struts2/junit/StrutsJUnit4TestCase.java index ee486d6cc9..93a08e3996 100644 --- a/plugins/junit/src/main/java/org/apache/struts2/junit/StrutsJUnit4TestCase.java +++ b/plugins/junit/src/main/java/org/apache/struts2/junit/StrutsJUnit4TestCase.java @@ -22,7 +22,6 @@ import com.opensymphony.xwork2.ActionProxy; import com.opensymphony.xwork2.ActionProxyFactory; import com.opensymphony.xwork2.config.Configuration; -import com.opensymphony.xwork2.interceptor.ValidationAware; import com.opensymphony.xwork2.interceptor.annotations.After; import com.opensymphony.xwork2.interceptor.annotations.Before; import org.apache.commons.lang3.StringUtils; @@ -31,6 +30,7 @@ import org.apache.struts2.dispatcher.HttpParameters; import org.apache.struts2.dispatcher.mapper.ActionMapper; import org.apache.struts2.dispatcher.mapper.ActionMapping; +import org.apache.struts2.interceptor.ValidationAware; import org.apache.struts2.util.StrutsTestCaseHelper; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.mock.web.MockHttpServletRequest;