package com.zhiqiyun.open.utils.validation.constraints;

import com.zhiqiyun.open.utils.PatternUtils;
import com.zhiqiyun.open.utils.validation.DomainName;
import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


/**
 * @author jtoms.shen
 * @version 1.0
 * @date 2018/12/20 13:40
 */
public class DomainNameValidate implements ConstraintValidator<DomainName, String> {
    @Override
    public void initialize(DomainName domainName) {
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return StringUtils.isBlank(value) || PatternUtils.validExpression(value, PatternUtils.DOMAIN_NAME_EXPRESSION);
    }
}