List of usage examples for org.apache.commons.lang StringUtils isNumeric
public static boolean isNumeric(String str)
Checks if the String contains only unicode digits.
From source file:de.qaware.chronix.solr.query.date.DateQueryParser.java
/** * Converts the given date term into a numeric representation * * @param dateTerm - the date term, e.g, start:NOW+30DAYS * @return the long representation of the date term * @throws ParseException if the date term could not be evaluated *//*from ww w. ja va 2 s . c o m*/ private long getNumberRepresentation(String dateTerm) throws ParseException { long numberRepresentation; if (StringUtils.isNumeric(dateTerm)) { numberRepresentation = Long.valueOf(dateTerm); } else if (solrDateMathPattern.matcher(dateTerm).matches()) { numberRepresentation = parseDateTerm(dateTerm); } else if (instantDatePattern.matcher(dateTerm).matches()) { numberRepresentation = Instant.parse(dateTerm).toEpochMilli(); } else { throw new ParseException("Could not parse date representation '" + dateTerm + "'", 0); } return numberRepresentation; }
From source file:com.edmunds.etm.management.api.HostAddress.java
private static int extractPort(Properties properties) { final String portText = properties.getProperty("port"); Validate.notEmpty(portText, "port cannot be empty"); try {/* w ww. j a v a2 s . c o m*/ if (StringUtils.isNumeric(portText)) { return Integer.parseInt(portText); } else { throw new IllegalStateException("Port must be numeric: " + portText); } } catch (NumberFormatException e) { throw new IllegalStateException("Port must be numeric: " + portText, e); } }
From source file:com.impetus.kundera.property.accessor.SQLTimestampAccessor.java
@Override public Timestamp fromString(Class targetClass, String s) { if (s == null) { return null; }//from w ww . ja va2s . c o m if (StringUtils.isNumeric(s)) { return new Timestamp(Long.parseLong(s)); } Timestamp t = Timestamp.valueOf(s); return t; }
From source file:com.impetus.kundera.service.HostConfiguration.java
/** * Validate host and port./*w ww .jav a2 s . c o m*/ * * @param host * @param port */ protected void onValidation(final String host, final String port) { if (host == null || !StringUtils.isNumeric(port) || port.isEmpty()) { logger.error("Host or port should not be null / port should be numeric."); throw new IllegalArgumentException("Host or port should not be null / port should be numeric."); } }
From source file:com.neusoft.mid.clwapi.service.news.NewsServiceImpl.java
/** * ???/*from w w w.jav a2s . co m*/ * * @param token * * @param body * ? * @return */ @Override public Object getNewsSummaryInfo(String token, String body) { logger.info("????"); // ?? NewsRequ iNewsRequ = JacksonUtils.fromJsonRuntimeException(body, NewsRequ.class); // ?? iNewsRequ.setEndTime(StringUtils.strip(iNewsRequ.getEndTime())); iNewsRequ.setStartTime(StringUtils.strip(iNewsRequ.getStartTime())); iNewsRequ.setNum(StringUtils.strip(iNewsRequ.getNum())); iNewsRequ.setType(StringUtils.strip(iNewsRequ.getType())); // ?? logger.info("??"); if (StringUtils.isEmpty(iNewsRequ.getType())) { logger.error("??"); throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST); } else if (StringUtils.isEmpty(iNewsRequ.getStartTime()) || StringUtils.isEmpty(iNewsRequ.getEndTime())) { logger.error("????"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } else if (HttpConstant.TIME_15_DAY_AGO.equalsIgnoreCase(iNewsRequ.getStartTime()) && !HttpConstant.TIME_ZERO.equals(iNewsRequ.getEndTime())) { logger.error( "??-dd15????0"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } // numNumnull??num? if (StringUtils.isEmpty(iNewsRequ.getNum())) { iNewsRequ.setNum(null); } else if (!StringUtils.isNumeric(iNewsRequ.getNum())) { logger.error("??num?"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } // ???? if (!HttpConstant.TIME_ZERO.equals(iNewsRequ.getStartTime()) && !HttpConstant.TIME_15_DAY_AGO.equalsIgnoreCase(iNewsRequ.getStartTime())) { try { TimeUtil.parseStringToDate(iNewsRequ.getStartTime(), HttpConstant.TIME_FORMAT); } catch (ParseException e) { logger.error("????" + e.getMessage()); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } } if (!HttpConstant.TIME_ZERO.equals(iNewsRequ.getEndTime())) { try { TimeUtil.parseStringToDate(iNewsRequ.getEndTime(), HttpConstant.TIME_FORMAT); } catch (ParseException e) { logger.error("?????" + e.getMessage()); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } } if (HttpConstant.TIME_ZERO.equals(iNewsRequ.getStartTime())) { iNewsRequ.setStartTime(null); } else if (HttpConstant.TIME_15_DAY_AGO.equalsIgnoreCase(iNewsRequ.getStartTime())) { Date dBTime = iCommonMapper.getDBTime(); Date fifteenDayAgo = TimeUtil.get15Ago(dBTime); String startTime = TimeUtil.formatDateToString(fifteenDayAgo, HttpConstant.TIME_FORMAT); iNewsRequ.setStartTime(startTime); } if (HttpConstant.TIME_ZERO.equals(iNewsRequ.getEndTime())) { iNewsRequ.setEndTime(null); } // Type if (iNewsRequ.getType().equalsIgnoreCase("-1")) { iNewsRequ.setType(null); } else if (iNewsRequ.getType().equals("0") || iNewsRequ.getType().equals("1")) { // ?????? } else { logger.error("??type"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } // 0 logger.info("??"); logger.info("???"); // ??? List<NewsInfo> list = iNewsMapper.getNewsList(iNewsRequ); logger.debug("list=" + (list == null ? "NULL" : list.size())); if (list == null || list.size() == 0) { logger.info("???"); return Response.noContent().build(); } logger.info("????"); logger.debug("???"); if (logger.isDebugEnabled()) { Iterator<NewsInfo> it = list.iterator(); while (it.hasNext()) { NewsInfo temp = it.next(); logger.debug(temp.toString()); } } // ? Map<String, List<NewsInfo>> map = new HashMap<String, List<NewsInfo>>(); map.put("news", list); logger.info("?????"); return JacksonUtils.toJsonRuntimeException(map); }
From source file:net.bible.service.readingplan.ReadingPlanDao.java
/** get last day number - there may be missed days so cannot simply do props.size() *//*from w w w.j a va2 s . c om*/ public int getNumberOfPlanDays(String planCode) { int maxDayNo = 0; for (Object oDayNo : getPlanProperties(planCode).keySet()) { String dayNoStr = (String) oDayNo; if (StringUtils.isNumeric(dayNoStr)) { int dayNo = Integer.parseInt(dayNoStr); maxDayNo = Math.max(maxDayNo, dayNo); } else { if (!VERSIFICATION.equalsIgnoreCase(dayNoStr)) { Log.e(TAG, "Invalid day number:" + dayNoStr); } } } return maxDayNo; }
From source file:fr.paris.lutece.plugins.genericattributes.service.upload.AbstractGenAttUploadHandler.java
/** * {@inheritDoc}/*from w w w .ja v a2s .c o m*/ */ @Override public String canUploadFiles(HttpServletRequest request, String strFieldName, List<FileItem> listFileItemsToUpload, Locale locale) { if (StringUtils.isNotBlank(strFieldName) && (strFieldName.length() > PREFIX_ENTRY_ID.length())) { initMap(request.getSession().getId(), strFieldName); String strIdEntry = getEntryIdFromFieldName(strFieldName); if (StringUtils.isEmpty(strIdEntry) || !StringUtils.isNumeric(strIdEntry)) { return I18nService.getLocalizedString(ERROR_MESSAGE_UNKNOWN_ERROR, locale); } int nIdEntry = Integer.parseInt(strIdEntry); Entry entry = EntryHome.findByPrimaryKey(nIdEntry); List<FileItem> listUploadedFileItems = getListUploadedFiles(strFieldName, request.getSession()); if (entry != null) { GenericAttributeError error = EntryTypeServiceManager.getEntryTypeService(entry) .canUploadFiles(entry, listUploadedFileItems, listFileItemsToUpload, locale); if (error != null) { return error.getErrorMessage(); } return null; } } return I18nService.getLocalizedString(ERROR_MESSAGE_UNKNOWN_ERROR, locale); }
From source file:ee.pri.rl.blog.web.page.setting.SettingValidator.java
private void validateEditorSettings(IValidatable<String> validatable) { String value = validatable.getValue(); if (!StringUtils.isNumeric(value)) { error(validatable, "Value must be number"); } else {//from ww w . j ava 2s . c o m int intValue = Integer.valueOf(value); if (intValue < 10 || intValue > 200) { error(validatable, "Value must be between 10 and 200"); } } }
From source file:com.aimluck.eip.project.ProjectTaskProgressFormData.java
/** * ???????/*from w w w. j a va 2 s.c om*/ * * @param msgList * * @return TRUE ? FALSE */ @Override protected boolean validate(List<String> msgList) { // ? if ("progress_rate".equals(name)) { if (StringUtils.isEmpty(taskId) || StringUtils.isEmpty(value) || !(StringUtils.isNumeric(taskId) && StringUtils.isNumeric(value))) { msgList.add(getl10n("PROJECT_UPDATE_ERROR")); } if (!ProjectFormUtils.isEditable(taskId, loginUserId)) { msgList.add(getl10n("PROJECT_TASK_NOT_UPDATE")); } } return msgList.isEmpty(); }
From source file:edu.harvard.iq.dataverse.datasetutility.FileUploadTestPage.java
public String init() { Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext() .getRequestParameterMap();/* ww w .ja v a 2s . co m*/ msgt("params: " + params.toString()); if (params.containsKey("ds_id")) { String ds_id = params.get("ds_id"); if ((!ds_id.isEmpty()) && (StringUtils.isNumeric(ds_id))) { datasetId = Long.parseLong(ds_id); dataset = datasetService.find(datasetId); datasetVersion = dataset.getLatestVersion(); checkRetrievalTest(); } } if (params.containsKey("fid")) { String fid = params.get("fid"); if ((!fid.isEmpty()) && (StringUtils.isNumeric(fid))) { fileToReplace = datafileService.find(Long.parseLong(fid)); } } if (fileToReplace != null) { replaceOperation = true; } else { replaceOperation = false; } return null; }