class RelayStateValidator {

    public void validate(String relayState) {
        if (relayState == null){
            return;
        }

        if (relayState.length() > MAXIMUM_NUMBER_OF_CHARACTERS) {
            SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.invalidRelayState(relayState);
            throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel());
        }

        for (String invalidCharacter : INVALID_CHARACTERS) {
            if (relayState.contains(invalidCharacter)) {
                SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.relayStateContainsInvalidCharacter(invalidCharacter, relayState);
                throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel());
            }
        }
    }

}