Java Code Examples for org.apache.commons.validator.GenericValidator#isBlankOrNull()
The following examples show how to use
org.apache.commons.validator.GenericValidator#isBlankOrNull() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValidateTwoFields.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, ServletContext application) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); String sProperty2 = field.getVarValue("secondProperty"); String value2 = ValidatorUtils.getValueAsString(bean, sProperty2); if (!GenericValidator.isBlankOrNull(value)) { try { if (!value.equals(value2)) { errors.add(field.getKey(), new ActionMessage("errors.different.passwords")); return false; } } catch (Exception e) { errors.add(field.getKey(), new ActionMessage("errors.different.passwords")); return false; } } return true; }
Example 2
Source File: IntegerValidator.java From hop with Apache License 2.0 | 6 votes |
public boolean validate( ICheckResultSource source, String propertyName, List<ICheckResult> remarks, ValidatorContext context ) { Object result = null; String value = null; value = ValidatorUtils.getValueAsString( source, propertyName ); if ( GenericValidator.isBlankOrNull( value ) ) { return true; } result = GenericTypeValidator.formatInt( value ); if ( result == null ) { ActionValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, ActionValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) ); return false; } return true; }
Example 3
Source File: LongValidator.java From hop with Apache License 2.0 | 6 votes |
public boolean validate( ICheckResultSource source, String propertyName, List<ICheckResult> remarks, ValidatorContext context ) { Object result = null; String value = null; value = ValidatorUtils.getValueAsString( source, propertyName ); if ( GenericValidator.isBlankOrNull( value ) ) { return Boolean.TRUE; } result = GenericTypeValidator.formatLong( value ); if ( result == null ) { ActionValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, ActionValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) ); return false; } return true; }
Example 4
Source File: ValidateCompareTwoFields.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
/** * Compares the two fields using the given comparator * * @param bean * @param va * @param field * @param errors * @param request * @param comparator * @return */ private static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, Comparator comparator) { String greaterInputString = ValidatorUtils.getValueAsString(bean, field.getProperty()); String secondProperty = field.getVarValue("secondProperty"); String lowerInputString = ValidatorUtils.getValueAsString(bean, secondProperty); if (!GenericValidator.isBlankOrNull(lowerInputString) && !GenericValidator.isBlankOrNull(greaterInputString)) { try { Double lowerInput = new Double(lowerInputString); Double greaterInput = new Double(greaterInputString); // if comparator result != VALUE then the condition is false if (comparator.compare(lowerInput, greaterInput) != VALUE) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } return true; } catch (NumberFormatException e) { errors.add(field.getKey(), new ActionMessage(va.getMsg())); return false; } } return true; }
Example 5
Source File: DataSetsSDKServiceImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 6 votes |
private void checkParameterValues(String[] values, DataSetParameterItem dataSetParameterItem) throws InvalidParameterValue { logger.debug("IN"); try { String parameterType = dataSetParameterItem.getType(); if (parameterType.equalsIgnoreCase("Number")) { for (int i = 0; i < values.length; i++) { String value = values[i]; if (GenericValidator.isBlankOrNull(value) || (!(GenericValidator.isInt(value) || GenericValidator.isFloat(value) || GenericValidator.isDouble(value) || GenericValidator.isShort(value) || GenericValidator.isLong(value)))) { InvalidParameterValue error = new InvalidParameterValue(); error.setParameterName(dataSetParameterItem.getName()); error.setParameterType(parameterType); error.setWrongParameterValue(value); error.setParameterFormat(""); throw error; } } } } finally { logger.debug("OUT"); } }
Example 6
Source File: IntegerValidator.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public boolean validate( CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context ) { Object result = null; String value = null; value = ValidatorUtils.getValueAsString( source, propertyName ); if ( GenericValidator.isBlankOrNull( value ) ) { return true; } result = GenericTypeValidator.formatInt( value ); if ( result == null ) { JobEntryValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) ); return false; } return true; }
Example 7
Source File: ADMValidator.java From development with Apache License 2.0 | 6 votes |
@Override protected boolean isValidAuthority(String authority) { if (relative && authority == null) { return true; } boolean isValid = super.isValidAuthority(authority); if (!isValid && !GenericValidator.isBlankOrNull(authority)) { if (isValidAuthorityHostNoDot(authority)) { return true; } else if (isValidAuthorityHostNoTld(authority)) { return true; } else { return isValidAuthorityIPV6Host(authority); } } else { return isValid; } }
Example 8
Source File: ADMValidator.java From development with Apache License 2.0 | 6 votes |
/** * Check if the authority contains a valid hostname without "." * characters and an optional port number * * @param authority * @return <code>true</code> if the authority is valid */ private boolean isValidAuthorityHostNoDot(String authority) { Perl5Util authorityMatcher = new Perl5Util(); if (authority != null && authorityMatcher.match( "/^([a-zA-Z\\d\\-\\.]*)(:\\d*)?(.*)?/", authority)) { String hostIP = authorityMatcher.group(1); if (hostIP.indexOf('.') < 0) { // the hostname contains no dot, add domain validation to check invalid hostname like "g08fnstd110825-" DomainValidator domainValidator = DomainValidator.getInstance(true); if(!domainValidator.isValid(hostIP)) { return false; } String port = authorityMatcher.group(2); if (!isValidPort(port)) { return false; } String extra = authorityMatcher.group(3); return GenericValidator.isBlankOrNull(extra); } else { return false; } } else { return false; } }
Example 9
Source File: BLValidator.java From development with Apache License 2.0 | 6 votes |
/** * Either question and answer are not set or both must be set. * * @param question * the security question. * @param answer * the security answer. */ public static void isSecurityInfo(String question, String answer) throws ValidationException { BLValidator.isDescription("securityQuestion", question, false); BLValidator.isDescription("securityAnswer", answer, false); if (!GenericValidator.isBlankOrNull(question) || !GenericValidator.isBlankOrNull(answer)) { if (GenericValidator.isBlankOrNull(question) || GenericValidator.isBlankOrNull(answer)) { ValidationException vf = new ValidationException( ReasonEnum.SECURITY_INFO, null, null); logValidationFailure(vf); throw vf; } } }
Example 10
Source File: LongValidator.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public boolean validate( CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context ) { Object result = null; String value = null; value = ValidatorUtils.getValueAsString( source, propertyName ); if ( GenericValidator.isBlankOrNull( value ) ) { return Boolean.TRUE; } result = GenericTypeValidator.formatLong( value ); if ( result == null ) { JobEntryValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) ); return false; } return true; }
Example 11
Source File: ADMValidator.java From development with Apache License 2.0 | 5 votes |
/** * Check if the authority contains a hostname without top level domain * and an optional port number * * @param authority * @return <code>true</code> if the authority is valid */ private boolean isValidAuthorityHostNoTld(String authority) { Perl5Util authorityMatcher = new Perl5Util(); if (authority != null && authorityMatcher.match( "/^([a-zA-Z\\d\\-\\.]*)(:\\d*)?(.*)?/", authority)) { String host = authorityMatcher.group(1); if (host.indexOf('.') > 0) { DomainValidator domainValidator = DomainValidator.getInstance(); // Make the host have a valid TLD, so that the "no TLD" host can pass the domain validation. String patchedHost = host + ".com"; if(!domainValidator.isValid(patchedHost)) { return false; } String port = authorityMatcher.group(2); if (!isValidPort(port)) { return false; } String extra = authorityMatcher.group(3); return GenericValidator.isBlankOrNull(extra); } else { return false; } } else { return false; } }
Example 12
Source File: EmailValidator.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public boolean validate( CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context ) { String value = null; value = ValidatorUtils.getValueAsString( source, propertyName ); if ( !GenericValidator.isBlankOrNull( value ) && !GenericValidator.isEmail( value ) ) { JobEntryValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) ); return false; } else { return true; } }
Example 13
Source File: NotBlankValidator.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public boolean validate( CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context ) { String value = ValidatorUtils.getValueAsString( source, propertyName ); if ( GenericValidator.isBlankOrNull( value ) ) { JobEntryValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) ); return false; } else { return true; } }
Example 14
Source File: EmailValidator.java From hop with Apache License 2.0 | 5 votes |
public boolean validate( ICheckResultSource source, String propertyName, List<ICheckResult> remarks, ValidatorContext context ) { String value = null; value = ValidatorUtils.getValueAsString( source, propertyName ); if ( !GenericValidator.isBlankOrNull( value ) && !GenericValidator.isEmail( value ) ) { ActionValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, ActionValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) ); return false; } else { return true; } }
Example 15
Source File: NotBlankValidator.java From hop with Apache License 2.0 | 5 votes |
public boolean validate( ICheckResultSource source, String propertyName, List<ICheckResult> remarks, ValidatorContext context ) { String value = ValidatorUtils.getValueAsString( source, propertyName ); if ( GenericValidator.isBlankOrNull( value ) ) { ActionValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, ActionValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) ); return false; } else { return true; } }
Example 16
Source File: ComAdminForm.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
/** * Validate the properties that have been set from this HTTP request, and * return an <code>ActionMessages</code> object that encapsulates any * validation errors that have been found. If no errors are found, return * <code>null</code> or an <code>ActionMessages</code> object with no * recorded error messages. * * @param mapping * The mapping used to select this instance * @param request * The servlet request we are processing * @return errors */ @Override public ActionErrors formSpecificValidate(ActionMapping mapping, HttpServletRequest request) { ActionErrors actionErrors = new ActionErrors(); boolean doNotDelete = request.getParameter("delete") == null || request.getParameter("delete").isEmpty(); if (doNotDelete && "save".equals(action)) { if (username == null || username.length() < 3) { actionErrors.add("username", new ActionMessage("error.username.tooShort")); } else if(username.length() > 180) { actionErrors.add("username", new ActionMessage("error.username.tooLong")); } if (!StringUtils.equals(password, passwordConfirm)) { actionErrors.add("password", new ActionMessage("error.password.mismatch")); } if (StringUtils.isBlank(fullname) || fullname.length() < 2) { actionErrors.add("fullname", new ActionMessage("error.name.too.short")); } else if (fullname.length() > 100) { actionErrors.add("fullname", new ActionMessage("error.username.tooLong")); } if (StringUtils.isBlank(firstname) || firstname.length() < 2) { actionErrors.add("firstname", new ActionMessage("error.name.too.short")); } else if (firstname.length() > 100) { actionErrors.add("firstname", new ActionMessage("error.username.tooLong")); } if (StringUtils.isBlank(companyName) || companyName.length() < 2) { actionErrors.add("companyName", new ActionMessage("error.company.tooShort")); } else if (companyName.length() > 100) { actionErrors.add("companyName", new ActionMessage("error.company.tooLong")); } if (GenericValidator.isBlankOrNull(this.email) || !AgnitasEmailValidator.getInstance().isValid(email)) { actionErrors.add("mailForReport", new ActionMessage("error.invalid.email")); } } return actionErrors; }
Example 17
Source File: ParameterAssembler.java From development with Apache License 2.0 | 4 votes |
public static void validateParameter(VOParameter parameter, ParameterDefinition paramDef) throws ValidationException { ParameterValueType parameterType = paramDef.getValueType(); String parameterValue = parameter.getValue(); if (!isValueRequired(parameter, paramDef) && GenericValidator.isBlankOrNull(parameter.getValue())) { return; } if (parameterType == ParameterValueType.BOOLEAN) { BLValidator.isBoolean(FIELD_NAME_VALUE, parameterValue); } else if (parameterType == ParameterValueType.STRING) { BLValidator.isNotBlank(FIELD_NAME_VALUE, parameterValue); } else if (parameterType == ParameterValueType.ENUMERATION) { // a value must always be set already from the supplier - that's // the default for the customer if configurable validateEnumeratedParameterValue(parameterValue, paramDef); } else if (parameterType == ParameterValueType.DURATION) { // the value must be non-negative BLValidator.isLong(FIELD_NAME_VALUE, parameterValue); long longValue = Long.parseLong(parameterValue); BLValidator.isNonNegativeNumber(FIELD_NAME_VALUE, longValue); if (longValue % MS_PER_DAY != 0) { ValidationException vf = new ValidationException( ReasonEnum.DURATION, FIELD_NAME_VALUE, new Object[] { parameterValue }); logger.logWarn(Log4jLogger.SYSTEM_LOG, vf, LogMessageIdentifier.WARN_VALIDATION_FAILED); throw vf; } } else { Long minValue = paramDef.getMinimumValue(); Long maxValue = paramDef.getMaximumValue(); if (parameterType == ParameterValueType.INTEGER) { BLValidator.isInteger(FIELD_NAME_VALUE, parameterValue); BLValidator.isInRange(FIELD_NAME_VALUE, Integer.parseInt(parameterValue), minValue, maxValue); } else if (parameterType == ParameterValueType.LONG) { BLValidator.isLong(FIELD_NAME_VALUE, parameterValue); BLValidator.isInRange(FIELD_NAME_VALUE, Long.parseLong(parameterValue), minValue, maxValue); } } }
Example 18
Source File: User.java From development with Apache License 2.0 | 4 votes |
public boolean isEmailDisabled() { return isRemoteLdapAttributeActive(SettingType.LDAP_ATTR_EMAIL) && !GenericValidator.isBlankOrNull(getEMail()); }
Example 19
Source File: User.java From development with Apache License 2.0 | 4 votes |
public boolean isLocaleDisabled() { return isRemoteLdapAttributeActive(SettingType.LDAP_ATTR_LOCALE) && !GenericValidator.isBlankOrNull(getLocale()); }
Example 20
Source File: ValidateUtil.java From primecloud-controller with GNU General Public License v2.0 | 2 votes |
/** * 必須チェック * * @param value 入力チェック対象の値 * @param code 入力チェックエラー時のメッセージコード * @param params 入力チェックエラー時のメッセージパラメータ */ public static void required(String value, String code, Object[] params) { if (GenericValidator.isBlankOrNull(value)) { throw new AutoApplicationException(code, params); } }