package com.qianwen.core.i18n.advice;
|
|
import java.lang.annotation.Annotation;
|
import java.lang.reflect.Method;
|
import java.util.Locale;
|
import javax.validation.MessageInterpolator;
|
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
|
import org.hibernate.validator.spi.resourceloading.ResourceBundleLocator;
|
|
/* loaded from: blade-starter-i18n-9.3.0.0-SNAPSHOT.jar:org/springblade/core/i18n/advice/EmptyCurlyToDefaultMessageInterpolator.class */
|
public class EmptyCurlyToDefaultMessageInterpolator extends ResourceBundleMessageInterpolator {
|
private static final String EMPTY_CURLY_BRACES = "{}";
|
private static final String LEFT_CURLY_BRACES = "{";
|
private static final String RIGHT_CURLY_BRACES = "}";
|
|
public EmptyCurlyToDefaultMessageInterpolator() {
|
}
|
|
public EmptyCurlyToDefaultMessageInterpolator(ResourceBundleLocator userResourceBundleLocator) {
|
super(userResourceBundleLocator);
|
}
|
|
public String interpolate(String message, MessageInterpolator.Context context, Locale locale) {
|
if (message.contains(EMPTY_CURLY_BRACES)) {
|
Class<? extends Annotation> annotationType = context.getConstraintDescriptor().getAnnotation().annotationType();
|
try {
|
Method messageMethod = annotationType.getDeclaredMethod("message", new Class[0]);
|
if (messageMethod.getDefaultValue() != null) {
|
Object defaultValue = messageMethod.getDefaultValue();
|
if (defaultValue instanceof String) {
|
String defaultMessage = (String) defaultValue;
|
if (defaultMessage.startsWith(LEFT_CURLY_BRACES) && defaultMessage.endsWith(RIGHT_CURLY_BRACES)) {
|
message = message.replace(EMPTY_CURLY_BRACES, defaultMessage);
|
}
|
}
|
}
|
} catch (NoSuchMethodException e) {
|
return super.interpolate(message, context, locale);
|
}
|
}
|
return super.interpolate(message, context, locale);
|
}
|
}
|