package info.bukova.isspst.validators;

import info.bukova.isspst.StringUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zkoss.bind.Property;
import org.zkoss.bind.ValidationContext;

public class UserPasswordOrigValidator extends BaseValidator
{
	private final static Logger log = LoggerFactory.getLogger(UserPasswordOrigValidator.class.getName());

	@Override
	protected Logger getLogger()
	{
		return log;
	}

	private boolean recordIsNew;

	public UserPasswordOrigValidator(boolean recordIsNew)
	{
		this.recordIsNew = recordIsNew;
	}

	@Override
	public void validate(ValidationContext ctx)
	{
		return;
	}
	
	public void aaa(ValidationContext ctx)
	{
		Property propertyOrig = ctx.getProperty();
		String passwordOrig = (String) propertyOrig.getValue();

		if (passwordOrig == null)
		{
			passwordOrig = "";
		}

		if (passwordOrig.isEmpty())
		{
			if (this.recordIsNew)
			{
				this.addErrorMsg(ctx, StringUtils.localize("UserPasswordIsEmpty"));
			}
		}
	}
}
