package de.ivu.elect;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import de.ivu.elect.jee.faces.FacesMessageUtil;

public class EmlHashValidator implements Validator {

  private final String expected;

  public EmlHashValidator(String expected) {
    this.expected = expected;
  }

  @Override
  public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    if (value==null || !expected.equalsIgnoreCase(value.toString())){
      throw new ValidatorException(
          FacesMessageUtil.createErrorMessage(context, "eml.hash.code.falsch", "eml.hash.code.falsch"));

    }
  }
}
