WW-3714 Fix replacement ValidationAware marker not recognised

This commit is contained in:
Kusal Kithul-Godage
2024-10-22 16:48:49 +11:00
parent ebedd7391f
commit 2757c23572
5 changed files with 96 additions and 7 deletions
@@ -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<String> errorMessages) {
adaptee.setActionErrors(errorMessages);
}
@Override
public Collection<String> getActionErrors() {
return adaptee.getActionErrors();
}
@Override
public void setActionMessages(Collection<String> messages) {
adaptee.setActionMessages(messages);
}
@Override
public Collection<String> getActionMessages() {
return adaptee.getActionMessages();
}
@Override
public void setFieldErrors(Map<String, List<String>> errorMap) {
adaptee.setFieldErrors(errorMap);
}
@Override
public Map<String, List<String>> 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();
}
}
}
@@ -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
@@ -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 @@ public class DelegatingValidatorContext implements ValidatorContext {
}
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);
}
@@ -21,7 +21,6 @@ package org.apache.struts2.interceptor;
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;
@@ -22,7 +22,6 @@ import com.opensymphony.xwork2.ActionContext;
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.Dispatcher;
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;