Java Code Examples for org.apache.commons.validator.routines.DateValidator#getInstance()

The following examples show how to use org.apache.commons.validator.routines.DateValidator#getInstance() . 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: HIPAAMatcherAttributeValue.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * @param value Cell content
 * @return True if input is a date
 */
private boolean isDate(String value) {
    DateValidator validator = DateValidator.getInstance();
    for (String format : DataType.DATE.getDescription().getExampleFormats()) {
        if (validator.isValid(value, format)) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: ComOptimizationScheduleForm.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {

	
	String method = mapping.getParameter() ; // struts-config.xml <action ... parameter ="method">
	String action =	request.getParameter(method);
	
	if("showSchedule".equals(action)) {
		return super.validate(mapping, request);
	}
	
	ActionErrors errors = new ActionErrors();

	DateValidator dateValidator = DateValidator.getInstance();

	if (!dateValidator.isValid(resultSendDateAsString, DATE_PATTERN_FULL)) {
		errors.add( ActionMessages.GLOBAL_MESSAGE,  new ActionMessage("mailing.autooptimization.errors.resultsenddate" , Constants.DATE_PATTERN_FULL));
	}

	if (!dateValidator.isValid(testMailingsSendDateAsString, DATE_PATTERN_FULL)) {
		errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("mailing.autooptimization.errors.resultsenddate" ,Constants.DATE_PATTERN_FULL));
	}

	if (!errors.isEmpty()) { // something is wrong with the supplied 'dates' , it doesn't make sense to parse dates from them.
		return errors;
	}

	Date testmailingsSenddate = null;
	Date resultSenddate = null;
	try {
		testmailingsSenddate = DateUtil.parseFullDate(testMailingsSendDateAsString);
		resultSenddate = DateUtil.parseFullDate(resultSendDateAsString);
	} catch (ParseException e) {
		logger.error("Error occured: " + e.getMessage(), e);
	}
		
	Date now = new Date();

	if (resultSenddate == null) {
		throw new RuntimeException("resultSenddate was null");
	}
	
	if (!resultSenddate.after(testmailingsSenddate)) {
		errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
				"mailing.autooptimization.errors.result_is_not_after_test"));
	}

	if (now.after(resultSenddate)) {
		errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
				"mailing.autooptimization.errors.resultsenddate_is_not_in_future"));
	}

	if (now.after(testmailingsSenddate)) {
		errors
				.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
				"mailing.autooptimization.errors.testmailingssenddate_is_not_infuture"));
	}
	return errors;
}
 
Example 3
Source File: AtlasClassificationType.java    From atlas with Apache License 2.0 4 votes vote down vote up
private boolean validateTimeBoundry(TimeBoundary timeBoundary, List<String> messages) {
    boolean        ret           = true;
    DateValidator  dateValidator = DateValidator.getInstance();
    Date           startDate     = null;
    Date           endDate       = null;
    final TimeZone timezone;

    if (StringUtils.isNotEmpty(timeBoundary.getTimeZone())) {
        if (!isValidTimeZone(timeBoundary.getTimeZone())) {
            addValidationMessageIfNotPresent(new AtlasBaseException(AtlasErrorCode.INVALID_TIMEBOUNDRY_TIMEZONE, timeBoundary.getTimeZone()), messages);

            ret = false;
        }

        timezone = TimeZone.getTimeZone(timeBoundary.getTimeZone());
    } else {
        timezone = TimeZone.getDefault();
    }

    if (StringUtils.isNotEmpty(timeBoundary.getStartTime())) {
        startDate = dateValidator.validate(timeBoundary.getStartTime(), TimeBoundary.TIME_FORMAT, timezone);

        if (startDate == null) {
            addValidationMessageIfNotPresent(new AtlasBaseException(AtlasErrorCode.INVALID_TIMEBOUNDRY_START_TIME, timeBoundary.getStartTime()), messages);

            ret = false;
        }
    }

    if (StringUtils.isNotEmpty(timeBoundary.getEndTime())) {
        endDate = dateValidator.validate(timeBoundary.getEndTime(), TimeBoundary.TIME_FORMAT, timezone);

        if (endDate == null) {
            addValidationMessageIfNotPresent(new AtlasBaseException(AtlasErrorCode.INVALID_TIMEBOUNDRY_END_TIME, timeBoundary.getEndTime()), messages);

            ret = false;
        }
    }

    if (startDate != null && endDate != null) {
        if (endDate.before(startDate)) {
            addValidationMessageIfNotPresent(new AtlasBaseException(AtlasErrorCode.INVALID_TIMEBOUNDRY_DATERANGE, timeBoundary.getStartTime(), timeBoundary.getEndTime()), messages);

            ret = false;
        }
    }

    return ret;
}