package info.bukova.isspst.validators;

import org.zkoss.bind.ValidationContext;

public class AddressValidator extends BaseValidator {
	
	private static final String EMAIL_PATTERN = 
		"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
		+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
	private static final String URL_PATTERN = "^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
 
	@Override
	public void validate(ValidationContext ctx) {
		if (!validateIsNotNullOrNotEmpty(ctx, "company", "CompanyIsEmpty", "company")) {
			return;
		}
		
		if (!validateIsNotNullOrNotEmpty(ctx, "city", "CityIsEmpty", "city")) {
			return;
		}
		
		if (!validateRegExp(ctx, "email", "EmailFormatIncorrect", "email", EMAIL_PATTERN)) {
			return;
		}
		
		if (!validateRegExp(ctx, "web", "WebUrlFormatIncorrect", "web", URL_PATTERN)) {
			return;
		}
		
	}

}
