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

The following examples show how to use org.apache.commons.validator.routines.DateValidator#isValid() . 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;
}