Example usage for java.text SimpleDateFormat setLenient

List of usage examples for java.text SimpleDateFormat setLenient

Introduction

In this page you can find the example usage for java.text SimpleDateFormat setLenient.

Prototype

public void setLenient(boolean lenient) 

Source Link

Document

Specify whether or not date/time parsing is to be lenient.

Usage

From source file:ru.codeinside.gses.activiti.forms.types.DateType.java

@Override
public Date convertFormValueToModelValue(Object propertyValue, String pattern, Map<String, String> values) {
    if (propertyValue == null) {
        return null;
    }/* w  ww .jav a2  s  .c o  m*/
    if (propertyValue instanceof Date) {
        return (Date) propertyValue;
    }
    if (StringUtils.trimToNull(pattern) == null) {
        pattern = PATTERN1;
    }
    String string = propertyValue.toString();
    try {
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        format.setLenient(false);
        return format.parse(string);
    } catch (ParseException e1) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(PATTERN2);
            simpleDateFormat.setLenient(false);
            return simpleDateFormat.parse(string);
        } catch (ParseException e) {
            return null;
        }
    }
}

From source file:org.thymeleaf.engine.stsm.context.STSMWebProcessingContextBuilder.java

@Override
protected void initBinder(final String bindingVariableName, final Object bindingObject, final ITest test,
        final DataBinder dataBinder, final Locale locale, final Map<String, Object> variables) {

    final ITestMessages messages = test.getMessages();
    if (messages == null) {
        throw new TestEngineExecutionException("Test \"" + test.getName() + "\" returns no messages object.");
    }/*from   ww  w . ja v  a2s  .c  o m*/

    final String dateformat = messages.computeMessage(locale, "date.format", null);
    final SimpleDateFormat sdf = new SimpleDateFormat(dateformat);
    sdf.setLenient(false);
    dataBinder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, false));

    dataBinder.registerCustomEditor(Variety.class, new VarietyPropertyEditor(new VarietyRepository()));

}

From source file:com.persistent.cloudninja.controller.TaskCompletionController.java

@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy hh:mm:SS");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));

}

From source file:org.jasig.schedassist.web.admin.EventDetailsController.java

/**
 * //from w w  w  . j  a va 2 s  .co  m
 * @param binder
 */
@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat();
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}

From source file:com.jhkt.playgroundArena.examples.generic.controller.GeneralController.java

@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}

From source file:org.kisoonlineapp.jsf.CalendarConverterInternal.java

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
    final String trimmedValue = StringUtils.trimToNull(value);
    if (StringUtils.isBlank(trimmedValue)) {
        return null;
    }/*from   ww w. j  a v  a 2 s .c o  m*/

    final SimpleDateFormat sdf = createSimpleDateFormat(context, pattern);
    sdf.setLenient(false);
    final ParsePosition pos = new ParsePosition(0);
    final Date date = sdf.parse(trimmedValue, pos);

    if (pos.getErrorIndex() >= 0 || pos.getIndex() != trimmedValue.length()) {
        throw new ConverterException("Cannot parse " + trimmedValue);
    }

    final Calendar cal = kisoOnlineApp.getNow();
    cal.setTime(date);
    return cal;
}

From source file:com.adobe.acs.commons.http.headers.impl.AbstractExpiresHeaderFilter.java

@Override
protected void doActivate(ComponentContext context) throws Exception {
    Dictionary<?, ?> properties = context.getProperties();
    String time = PropertiesUtil.toString(properties.get(PROP_EXPIRES_TIME), null);
    if (StringUtils.isBlank(time)) {
        throw new ConfigurationException(PROP_EXPIRES_TIME, "Expires Time must be specified.");
    }/* w w w . j  ava  2  s  . c o m*/
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    sdf.setLenient(false);
    try {
        Date date = sdf.parse(time);
        expiresTime.setTime(date);
    } catch (ParseException ex) {
        throw new ConfigurationException(PROP_EXPIRES_TIME, "Expires Time must be specified.");
    }
}

From source file:com.fahmi.hardinal.controller.ArticleController.java

@InitBinder //convert date 
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}

From source file:org.kuali.kpme.core.leaveplan.validation.LeavePlanValidation.java

boolean validateCalendarYearStart(String dateString) {
    if (StringUtils.isBlank(dateString)) {
        return false;
    }/*  w w w.  j  a v  a 2 s .co  m*/
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd");
    sdf.setLenient(false);
    try {
        sdf.parse(dateString);
    } catch (ParseException e) {
        this.putFieldError("calendarYearStart", "error.calendar.year.start", "Calendar Year Start");
        return false;
    }
    return true;
}

From source file:edu.gmu.csd.validation.Validation.java

public void validateDateOfSurvey(FacesContext context, UIComponent componentToValidate, Object value)
        throws ValidationException {
    boolean isDateValid = false;
    String dateOfSurvey = (String) value;

    SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy");
    sdf.setLenient(false);

    try {//from ww  w .ja  v a  2  s.com
        sdf.parse(dateOfSurvey);
        isDateValid = true;
    } catch (ParseException pexp) {
        pexp.printStackTrace();
        isDateValid = false;
    }

    if (!isDateValid && StringUtils.isNotEmpty(dateOfSurvey)) {
        FacesMessage message = new FacesMessage("Date of survey should be of valid format.");
        throw new ValidatorException(message);
    }
}