Example usage for org.apache.commons.validator DateValidator getInstance

List of usage examples for org.apache.commons.validator DateValidator getInstance

Introduction

In this page you can find the example usage for org.apache.commons.validator DateValidator getInstance.

Prototype

public static DateValidator getInstance() 

Source Link

Document

Returns the Singleton instance of this validator.

Usage

From source file:com.jp.systemdirector.projectzero.zab01.pr.SZAB0111Action.java

protected Date dateFormate(String date) {

    SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyyMMddhhmiss");
    sDateFormat.setLenient(false);/*from w  ww  .jav a  2 s.com*/
    if (DateValidator.getInstance().isValid(date, "yyyyMMddhhmiss", true) == false) {
        return null;
    } else {
        try {
            return sDateFormat.parse(date);
        } catch (ParseException ex) {

            log.error(ex);
            return null;
        }
    }
}

From source file:org.ala.repository.Validator.java

/**
 * Validate a DC file (parsed into list of String[])
 *
 * @param lines //from   w w  w  .  j a va  2  s.c  o  m
 * @throws MalformedURLException
 * @throws IllegalArgumentException
 * @throws NoSuchFieldError
 * @throws Exception
 */
protected void validateDcFile(List<String[]> lines)
        throws MalformedURLException, IllegalArgumentException, NoSuchFieldError, Exception {
    // initialise requiredDcFields
    ArrayList<String> requiredDcFields = new ArrayList<String>();
    requiredDcFields.add(Field.IDENTIFIER.name); // alt value: Predicates.DC_IDENTIFIER.getLocalPart()
    requiredDcFields.add(Field.FORMAT.name);
    requiredDcFields.add(Field.MODIFIED.name);
    //requiredDcFields.add(Field.URI.name);

    for (String[] data : lines) {
        logger.debug("DC entries (" + data.length + ") = " + StringUtils.join(data, "|"));
        // Check for expected number of tab fields
        Assert.isTrue(data.length == FileType.DC.getFieldCount(), "Entry not expected size of "
                + FileType.DC.getFieldCount() + ", got " + data.length + " - " + StringUtils.join(data, "|"));

        if (data[0].endsWith(Field.FORMAT.name)) {
            // Check "format" field
            requiredDcFields.remove(Field.FORMAT.name);
            Assert.isTrue(MimeType.getAllMimeTypes().contains(data[1]),
                    Field.FORMAT.name + " does not contain an accepted value: " + data[1] + " - "
                            + StringUtils.join(MimeType.getAllMimeTypes(), "|"));
        } else if (data[0].endsWith(Field.IDENTIFIER.name)) {
            // Check "identifier" field
            requiredDcFields.remove(Field.IDENTIFIER.name);
            Assert.isTrue(data[1].length() > 0, Field.IDENTIFIER.name + " is empty");
        } else if (data[0].endsWith(Field.MODIFIED.name)) {
            // Check "modified" date field
            requiredDcFields.remove(Field.MODIFIED.name);
            Assert.isTrue(data[1].length() > 0, Field.MODIFIED.name + " date is empty");
            DateValidator validator = DateValidator.getInstance();
            if (!validator.isValid(data[1], "yyyy-MM-dd", true)) {
                throw new IllegalArgumentException(
                        Field.MODIFIED.name + " date is not a valid date: " + data[1]);
            }
        } else if (data[0].endsWith(Field.URI.name)) {
            // Check "URI" field
            requiredDcFields.remove(Field.URI.name);
            new URL(data[1]); // throws MalformedURLException if not valid URL
        }
    }

    if (!requiredDcFields.isEmpty()) {
        throw new NoSuchFieldError("Required fields not found: " + StringUtils.join(requiredDcFields, ", "));
    }
}

From source file:org.mifos.reports.business.AbstractReportParameterForm.java

protected void addErrorIfInvalidRunDate(Errors errors, String runDate, String fieldName, String errorCode) {
    if (!DateValidator.getInstance().isValid(runDate, reportDatePattern(), false)) {
        errors.addError(fieldName, errorCode);
    }/*from   w  w w  . ja v a2  s  .  co m*/
}