List of usage examples for java.text SimpleDateFormat setLenient
public void setLenient(boolean lenient)
From source file:com.pax.pay.service.ParseReq.java
/** * /*w w w. ja va2s .co m*/ * * @return */ @SuppressLint("SimpleDateFormat") private int checkOrigDate() { String temp; try { temp = json.getString(ServiceConstant.ORIG_DATE); } catch (JSONException e) { return TransResult.SUCC; } if (temp == null || temp.length() == 0) { return TransResult.SUCC; } if (temp.length() != 4) { return TransResult.ERR_PARAM; } // ? SimpleDateFormat dateFormat = new SimpleDateFormat("MMdd"); try { dateFormat.setLenient(false); dateFormat.parse(temp); } catch (Exception e) { e.printStackTrace(); return TransResult.ERR_PARAM; } requestData.setOrigDate(temp); return TransResult.SUCC; }
From source file:synergyj.ListController.java
private String removeTimeStamp(String fileNameWithoutExt) { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); sdf.setLenient(false); int idx = fileNameWithoutExt.lastIndexOf("-"); String timestamp = fileNameWithoutExt.substring(idx + 1); try {//from w w w. j a v a 2s . c o m //validate date by parsing it sdf.parse(timestamp); //if parse didn't error, we're good fileNameWithoutExt = fileNameWithoutExt.substring(0, idx); } catch (ParseException ex) { Logger.log(ex.getMessage()); } return fileNameWithoutExt; }
From source file:org.fao.fenix.data.CSVBasicValidator.java
private boolean isValidDate(String dateString, StringBuilder errorStringBuilder) { SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); String errorMessage = ""; // LOGGER.info("isValidDate dateString = "+dateString); if (dateString != null && !dateString.isEmpty() && dateString.length() == 10) { try {/*from w ww. j a v a 2 s .c o m*/ df.setLenient(false); df.parse(dateString); return true; } catch (ParseException e) { LOGGER.error( getErrorMessage(dateString) + " [THE ParseException ERROR EMAIL HAS BEEN SENT TO USER]"); errorMessage = getErrorMessage(dateString); //throw new FenixException("The FTP CSV file contains an incorrect date format. Found '" + dateString + "' but expected a dd/mm/yyyy format e.g. '21/12/2000'. Please correct the CSV file."); } catch (IllegalArgumentException e) { LOGGER.error(getErrorMessage(dateString) + " [THE IllegalArgumentException ERROR EMAIL HAS BEEN SENT TO USER]"); errorMessage = getErrorMessage(dateString); //throw new FenixException("The FTP CSV file contains an incorrect date. Found '" + dateString + "' but expected a dd/mm/yyyy format e.g. '21/12/2000'. Please correct the CSV file."); } } else { LOGGER.error(getErrorMessage(dateString) + " [THE ERROR EMAIL HAS BEEN SENT TO USER]"); errorMessage = getErrorMessage(dateString); //throw new FenixException("The FTP CSV file contains an incorrect date. Found '" + dateString + "' but expected a dd/mm/yyyy format e.g. '21/12/2000'. Please correct the CSV file."); } if (errorMessage.length() > 0) { errorStringBuilder.append(errorMessage); } return false; }
From source file:org.squale.welcom.outils.excel.ExcelTable.java
/** * Retourne la valeur d'un element Renvoie une date ou une string selon le cas * /*ww w. j a v a 2s. c o m*/ * @param element : Object * @param headerElement :Property de la colonne * @return : Valeur de l'objet */ private Object getValue(final Object element, final HeaderElement headerElement) { try { Object value = LayoutUtils.getProperty(element, headerElement.getProperty()); Object retour = ""; if (value instanceof Date) { retour = (Date) value; } else if ((headerElement.getType() == HeaderElement.DATE_HEURE || headerElement.getType() == HeaderElement.DATE) && value instanceof String) { try { retour = new Date(Long.parseLong((String) value)); } catch (final NumberFormatException nfe) { // On a pas un long dans la chane donc on va la parser avec un dateformat // On gre les deux cas possibles pour viter au maximum les soucis SimpleDateFormat sdf = null; sdf = Util.formatDtHr; sdf.setLenient(false); try { retour = sdf.parse((String) value); } catch (final ParseException pe) { sdf = Util.formatDt; sdf.setLenient(false); try { retour = sdf.parse((String) value); } catch (final ParseException pe2) { log.error(pe2, pe2); return null; } } } } else { retour = BeanUtils.getProperty(element, headerElement.getProperty()); } return retour; } catch (final Exception ex) { log.error(ex, ex); return null; } }
From source file:org.wso2.carbon.registry.jcr.nodetype.RegistryNodeType.java
public boolean isValidDate(String inDate) { if (inDate == null) return false; //set the format to use as a constructor argument SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); if (inDate.trim().length() != dateFormat.toPattern().length()) return false; dateFormat.setLenient(false); try {/*w w w . ja v a 2 s . co m*/ //parse the inDate parameter dateFormat.parse(inDate.trim()); } catch (ParseException pe) { return false; } return true; }
From source file:org.squale.welcom.taglib.field.BaseDateHeureTag.java
/** * Retrouve la valeur si elle viens suite a une soumission avec erreur * /* www .j a va 2 s . co m*/ * @param typeOfElement type TYPE_WDATE / TYPE_WHOUR * @return la valeur statock en requete */ private String doRenderValueFromError(int typeOfElement) { SimpleDateFormat sdf = getSimpleDateOrHourFormat(typeOfElement); String valString = pageContext.getRequest().getParameter(getParameterNameInRequest(typeOfElement)); if (!GenericValidator.isBlankOrNull(valString)) { try { sdf.setLenient(false); sdf.parse(valString); } catch (ParseException e) { return valString; } } return ""; }
From source file:com.pentaho.di.purge.RepositoryCleanupUtil.java
/** * Ensure provided parameters are present and what we expect * //from w ww . ja v a 2 s. c o m * @param arguments * @throws Exception */ private void validateParameters(Map<String, String> arguments) throws Exception { String aUrl = arguments.get(OPTION_PREFIX + URL); String aUser = arguments.get(OPTION_PREFIX + USER); String aPassword = arguments.get(OPTION_PREFIX + PASS); String aVerCount = arguments.get(OPTION_PREFIX + VER_COUNT); String aDelFrom = arguments.get(OPTION_PREFIX + DEL_DATE); String aPurgeFiles = arguments.get(OPTION_PREFIX + PURGE_FILES); String aPurgeRev = arguments.get(OPTION_PREFIX + PURGE_REV); String aPurgeShared = arguments.get(OPTION_PREFIX + PURGE_SHARED); String aLogLevel = arguments.get(OPTION_PREFIX + LOG_LEVEL); String aLogFile = arguments.get(OPTION_PREFIX + LOG_FILE); StringBuffer errors = new StringBuffer(); boolean isValidOperationSelected = false; fileFilter = "*.kjb|*.ktr"; repositoryPath = "/"; purgeShared = false; if (aLogLevel != null && !(aLogLevel.equals("DEBUG") || aLogLevel.equals("ERROR") || aLogLevel.equals("FATAL") || aLogLevel.equals("INFO") || aLogLevel.equals("OFF") || aLogLevel.equals("TRACE") || aLogLevel.equals("WARN"))) { errors.append(OPTION_PREFIX + LOG_LEVEL + "=" + aLogLevel + " " + Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.ERROR_0003.INVALID_LOGLEVEL") + "\n"); } else { logLevel = aLogLevel; } if (aLogFile != null) { File f = new File(aLogFile); if (f.exists() && f.isDirectory()) { errors.append(Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.ERROR_0004.FOLDER_EXISTS", OPTION_PREFIX + LOG_FILE) + "\n"); } logFile = aLogFile; } if (aUrl == null) { errors.append(Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.ERROR_0005.MISSING_PARAM", OPTION_PREFIX + URL) + "\n"); } else { url = aUrl; } if (aUser == null) { errors.append(Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.ERROR_0005.MISSING_PARAM", OPTION_PREFIX + USER) + "\n"); } else { username = aUser; } if (aPassword == null) { errors.append(Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.ERROR_0005.MISSING_PARAM", OPTION_PREFIX + PASS) + "\n"); } else { password = aPassword; } if (aPurgeFiles != null) { if ((aPurgeFiles.equalsIgnoreCase(Boolean.TRUE.toString()) || aPurgeFiles.equalsIgnoreCase(Boolean.FALSE.toString()))) { purgeFiles = Boolean.parseBoolean(aPurgeFiles); isValidOperationSelected = true; } else { errors.append(Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.ERROR_0006.INVALID_BOOLEAN", OPTION_PREFIX + PURGE_FILES + "=" + aPurgeFiles) + "\n"); } } if (aPurgeRev != null) { if (aPurgeRev.equalsIgnoreCase(Boolean.TRUE.toString()) || aPurgeRev.equalsIgnoreCase(Boolean.FALSE.toString())) { if (isValidOperationSelected) { errors.append(Messages.getInstance() .getString("REPOSITORY_CLEANUP_UTIL.ERROR_0010.INVALID_COMBINATION_OF_PARAMS") + "\n"); } else { purgeRev = Boolean.parseBoolean(aPurgeRev); isValidOperationSelected = true; } } else { errors.append(Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.ERROR_0006.INVALID_BOOLEAN", OPTION_PREFIX + PURGE_REV + "=" + aPurgeRev) + "\n"); } } if (aPurgeShared != null) { if (Boolean.parseBoolean(aPurgeFiles) != Boolean.TRUE) { errors.append(Messages.getInstance() .getString("REPOSITORY_CLEANUP_UTIL.ERROR_0014.INVALID_PURGE_SHARED")); } else { purgeShared = Boolean.parseBoolean(aPurgeShared); } } if (aDelFrom != null) { // only allow one operation if (isValidOperationSelected) { errors.append(Messages.getInstance() .getString("REPOSITORY_CLEANUP_UTIL.ERROR_0010.INVALID_COMBINATION_OF_PARAMS") + "\n"); } else { SimpleDateFormat sdf = new SimpleDateFormat(purgeBeforeDateFormat); sdf.setLenient(false); try { sdf.parse(aDelFrom); delFrom = aDelFrom; isValidOperationSelected = true; } catch (ParseException e) { errors.append(Messages.getInstance().getString( "REPOSITORY_CLEANUP_UTIL.ERROR_0008.IMPROPERLY_FORMATTED_DATE", OPTION_PREFIX + DEL_DATE + "=" + aDelFrom, purgeBeforeDateFormat) + "\n"); } } } if (aVerCount != null) { // only allow one operation if (isValidOperationSelected) { errors.append(Messages.getInstance() .getString("REPOSITORY_CLEANUP_UTIL.ERROR_0010.INVALID_COMBINATION_OF_PARAMS") + "\n"); } else { try { verCount = Integer.parseInt(aVerCount); isValidOperationSelected = true; } catch (NumberFormatException e) { errors.append( Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.ERROR_0009.INVALID_INTEGER", OPTION_PREFIX + VER_COUNT + "=" + aVerCount) + "\n"); } } } if (!isValidOperationSelected) { errors.append(Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.ERROR_0013.MISSING_OPERATION") + "\n"); } if (errors.length() != 0) { errors.insert(0, "\n\n" + Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.ERROR_0011.ERRORS_HEADER") + "\n"); throw new Exception(errors.toString()); } }
From source file:org.uhp.portlets.news.web.ItemEditController.java
@Override protected void initBinder(PortletRequest request, PortletRequestDataBinder binder) throws Exception { SimpleDateFormat dateFormat = new SimpleDateFormat( getMessageSourceAccessor().getMessage(Constants.DATE_FORMAT)); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, null, new CustomDateEditor(dateFormat, true)); }
From source file:py.una.pol.karaku.util.FormatProvider.java
private synchronized void init() { if (this.initialized) { return;//from w w w . j a va 2 s . c o m } this.initialized = true; this.formats = new HashMap<String, SimpleDateFormat>(); this.formats.put(DATE_FORMAT, new SimpleDateFormat(DATE_FORMAT)); this.formats.put(DATE_SHORT_FORMAT, new SimpleDateFormat(DATE_SHORT_FORMAT)); this.formats.put(TIME_FORMAT, new SimpleDateFormat(TIME_FORMAT)); this.formats.put(DATETIME_FORMAT, new SimpleDateFormat(DATETIME_FORMAT)); this.formats.put(DATETIME_SHORT_FORMAT, new SimpleDateFormat(DATETIME_SHORT_FORMAT)); for (SimpleDateFormat sdf : this.formats.values()) { sdf.setLenient(false); } }
From source file:com.microsoft.tfs.util.datetime.LenientDateTimeParserExpander.java
/** * Given an array of strings, expands each into multiple format strings and * add the results to this instance in order. * * The formats are expanded to include variants with all the date * separators, time separators, month styles, and zone patterns defined * above (_dateSeparators, _timeSeparators, _monthPatterns, _zonePatterns). * * @param patterns// w ww. j a va 2 s .c o m * the patterns to expand (not null). * */ public void addExpanded(final LenientDateTimePattern[] patterns) { Check.notNull(patterns, "patterns"); //$NON-NLS-1$ /* * This is officially the deepest I've ever nested loops in any program. */ for (int i = 0; i < patterns.length; i++) { final LenientDateTimePattern pattern = patterns[i]; for (int j = 0; j < dateSeparators.length; j++) { for (int k = 0; k < timeSeparators.length; k++) { for (int l = 0; l < monthPatterns.length; l++) { for (int m = 0; m < zonePatterns.length; m++) { final SimpleDateFormat sdf = new SimpleDateFormat(pattern.getPattern() .replaceAll("/", dateSeparators[j]).replaceAll( //$NON-NLS-1$ ":", //$NON-NLS-1$ timeSeparators[k]) .replaceAll("MM", monthPatterns[l]).replaceAll( //$NON-NLS-1$ "z", //$NON-NLS-1$ zonePatterns[m]), locale); sdf.setLenient(constructLenient); lenientDateTimeParserFormats.add(new LenientDateTimeFormat(sdf, counter++, pattern.specifiesDate(), pattern.specifiesTime())); } } } } } }