Skip to content

Commit

Permalink
WW-3714 Fix replacement ValidationAware marker not recognised
Browse files Browse the repository at this point in the history
  • Loading branch information
kusalk committed Oct 22, 2024
1 parent ebedd73 commit 08174b5
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 08174b5

Please sign in to comment.