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:fitnesse.responders.run.SuiteResponder.java
private void cleanHistoryForSuite() { String testHistoryDays = context.getProperty("test.history.days"); if (withSuiteHistoryFormatter() && StringUtils.isNumeric(testHistoryDays)) { new HistoryPurger(context.getTestHistoryDirectory(), Integer.parseInt(testHistoryDays)) .deleteTestHistoryOlderThanDays(path); }/*from w ww. ja v a2s.c om*/ }
From source file:fr.paris.lutece.plugins.directory.business.AbstractEntryTypeUpload.java
/** * {@inheritDoc}/* ww w. j a va 2 s . com*/ */ @Override public void canUploadFiles(List<FileItem> listUploadedFileItems, List<FileItem> listFileItemsToUpload, Locale locale) throws DirectoryErrorException { /** 1) Check max files */ Field fieldMaxFiles = DirectoryUtils.findFieldByTitleInTheList(CONSTANT_MAX_FILES, getFields()); // By default, max file is set at 1 int nMaxFiles = 1; if ((fieldMaxFiles != null) && StringUtils.isNotBlank(fieldMaxFiles.getValue()) && StringUtils.isNumeric(fieldMaxFiles.getValue())) { nMaxFiles = DirectoryUtils.convertStringToInt(fieldMaxFiles.getValue()); } if ((listUploadedFileItems != null) && (listFileItemsToUpload != null)) { int nNbFiles = listUploadedFileItems.size() + listFileItemsToUpload.size(); if (nNbFiles > nMaxFiles) { Object[] params = { nMaxFiles }; String strMessage = I18nService.getLocalizedString(PROPERTY_MESSAGE_ERROR_UPLOADING_FILE_MAX_FILES, params, locale); throw new DirectoryErrorException(this.getTitle(), strMessage); } } /** 2) Check files size */ Field fieldFileMaxSize = DirectoryUtils.findFieldByTitleInTheList(CONSTANT_FILE_MAX_SIZE, getFields()); int nMaxSize = DirectoryUtils.CONSTANT_ID_NULL; if ((fieldFileMaxSize != null) && StringUtils.isNotBlank(fieldFileMaxSize.getValue()) && StringUtils.isNumeric(fieldFileMaxSize.getValue())) { nMaxSize = DirectoryUtils.convertStringToInt(fieldFileMaxSize.getValue()); } else { // For version 2.0.13 and below, the max size was stored in the width of the field "option" for EntryTypeDownloadUrl Field fieldOption = DirectoryUtils.findFieldByTitleInTheList(EntryTypeDownloadUrl.CONSTANT_OPTION, getFields()); if (fieldOption != null) { nMaxSize = fieldOption.getWidth(); } } // If no max size defined in the db, then fetch if from the directory.properties file if (nMaxSize == DirectoryUtils.CONSTANT_ID_NULL) { nMaxSize = AppPropertiesService.getPropertyInt(PROPERTY_UPLOAD_FILE_DEFAULT_MAX_SIZE, 5242880); } // If nMaxSize == -1, then no size limit if ((nMaxSize != DirectoryUtils.CONSTANT_ID_NULL) && (listFileItemsToUpload != null) && !listFileItemsToUpload.isEmpty()) { for (FileItem fileItem : listFileItemsToUpload) { if (fileItem.getSize() > nMaxSize) { Object[] params = { nMaxSize }; String strMessage = I18nService.getLocalizedString( PROPERTY_MESSAGE_ERROR_UPLOADING_FILE_FILE_MAX_SIZE, params, locale); throw new DirectoryErrorException(this.getTitle(), strMessage); } } } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.scientificCouncil.thesis.ManageSecondCycleThesisSearchBean.java
private Collection<Person> searchStudentNumber(final String number) { if (StringUtils.isNumeric(number)) { final SearchParameters searchParameters = new SearchParameters(); searchParameters.setStudentNumber(new Integer(number)); return search(searchParameters); }/* ww w. j a va 2 s. c o m*/ return Collections.emptySet(); }
From source file:edu.ku.brc.af.ui.forms.validation.FormattedDateValidator.java
public boolean validate(final UIFieldFormatterIFace formatter, final String value) { reason = "";//from www.j a v a 2 s . com //Calendar cal = Calendar.getInstance(); //System.out.println(formatter.getDateWrapper().getSimpleDateFormat().toPattern()); int len = formatter.getLength(); if (StringUtils.isNotEmpty(value)) { if (formatter.isDate()) { /*if (len == value.length()) { try { cal.setTime(scrDateFormat.getSimpleDateFormat().parse(value)); return checkDate(cal.get(Calendar.MONTH)-1, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.YEAR)); } catch (ParseException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormattedDateValidator.class, ex); reason = "Invalid Date"; return false; } } if (value.length() > len) { reason = "Invalid Date"; return false; } else*/ { List<UIFieldFormatterField> fields = formatter.getFields(); int pos = 0; int mon = -1; int day = -1; int year = -1; for (UIFieldFormatterField field : fields) { if (pos >= len || pos + field.getSize() > value.length()) { reason = "Partial"; break; } if (field.getType() == UIFieldFormatterField.FieldType.numeric) { String part = value.substring(pos, pos + field.getSize()); if (StringUtils.isNumeric(part)) { char c = field.getValue().charAt(0); int numPart = Integer.parseInt(part); if (c == 'M' || c == 'm') { mon = numPart; } else if (c == 'd' || c == 'D') { day = numPart; } else if (c == 'Y' || c == 'y') { year = numPart; } } else if (part.indexOf(separator) > -1) { reason = "Wrong format"; return isValid = false; } else { reason = getFieldSpecificError(field, " is Not numeric"); return isValid = false; } } pos += field.getSize(); } // for loop //Calendar now = Calendar.getInstance(); if (mon != -1 && day != -1 && year != -1) { daysInMonth[1] = year % 4 == 0 || (year % 100 == 0 && year % 400 != 0) ? 29 : 28; if (mon < 1 || mon > 12) { reason = "Invalid Month"; return isValid = false; } // Do Non-Leap Year if (day < 1 || day > daysInMonth[mon - 1]) { reason = "Invalid Day"; return isValid = false; } return isValid = true; } else if (mon != -1 && day != -1) { daysInMonth[1] = 29; if (mon < 1 || mon > 12) { reason = "Invalid Month"; return isValid = false; } // Do Non-Leap Year if (day < 1 || day > daysInMonth[mon]) { reason = "Invalid Day"; return isValid = false; } return isValid = true; } else if (mon != -1) { if (mon < 1 || mon > 12) { reason = "Invalid Month"; return isValid = false; } } else if (day > -1) { if (day < 1 || day > 31) { reason = "Invalid Day"; return isValid = false; } } } } return isValid = true; } reason = "Date is Empty"; return isValid = false; }
From source file:eu.annocultor.converters.geonames.GeonamesCsvToRdf.java
public boolean includeRecordInConversion(String featureCode, String population) { final long MIN_POPULATION = 10000; final String P_PPL = "P.PPL"; final String allowedFeatureCodePrefixes[] = { "A", P_PPL, //"P.PPLC", //"P.PPLA", "S.CSTL", // there are too many churches in US // "S.CH", "S.ANS", "S.MNMT", "S.LIBR", "S.HSTS", "S.OPRA", "S.AMTH", "S.TMPL", "T.ISL" }; //, "P", "S"}; if (featureCode.isEmpty()) { return false; }/*from www.j a v a2 s . com*/ for (String prefix : allowedFeatureCodePrefixes) { if (featureCode.startsWith(prefix)) { if (prefix.equals(P_PPL)) { return (!population.isEmpty() && StringUtils.isNumeric(population) && Integer.parseInt(population) > MIN_POPULATION); } else { return true; } } } return false; }
From source file:fr.paris.lutece.plugins.workflow.modules.mappings.web.component.ActionMappingTypeComponent.java
/** * {@inheritDoc}//from ww w .j ava 2 s . c o m */ @Override public String getModifyCodeMappingHtml(ICodeMapping codeMapping, HttpServletRequest request, Locale locale) { Map<String, Object> model = new HashMap<String, Object>(); String strIdWorkflow = request.getParameter(PARAMETER_ID_WORKFLOW); int nIdWorkflow = WorkflowUtils.CONSTANT_ID_NULL; Action action = null; if (StringUtils.isNotBlank(strIdWorkflow) && StringUtils.isNumeric(strIdWorkflow)) { nIdWorkflow = Integer.parseInt(strIdWorkflow); } else if (StringUtils.isNotBlank(codeMapping.getReferenceCode()) && StringUtils.isNumeric(codeMapping.getReferenceCode())) { int nIdAction = Integer.parseInt(codeMapping.getReferenceCode()); action = _actionService.findByPrimaryKey(nIdAction); if (action != null) { nIdWorkflow = action.getWorkflow().getId(); } } Workflow workflow = _workflowService.findByPrimaryKey(nIdWorkflow); if (workflow != null) { ReferenceList listActions = _codeMappingService.getListActions(getMappingType().getKey(), nIdWorkflow); if (action != null) { listActions.addItem(action.getId(), action.getName()); } model.put(MARK_LIST_ACTIONS, listActions); model.put(MARK_WORKFLOW, workflow); } model.put(MARK_LIST_WORKFLOWS, _codeMappingService.getListWorkflow()); model.put(MARK_REFERENCE_CODE, codeMapping.getReferenceCode()); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_MODIFY_MAPPING, locale, model); return template.getHtml(); }
From source file:com.zmanww.bukkit.SnowControl.Config.java
private List<Material> stringToMaterial(List<String> tempList) { List<Material> retVal = new ArrayList<Material>(); if (tempList != null) { for (String str : tempList) { str = StringUtils.trimToEmpty(str); if (StringUtils.isNumeric(str)) { retVal.add(Material.getMaterial(Integer.parseInt(str))); } else if (!StringUtils.isBlank(str)) { retVal.add(Material.getMaterial(str)); }//ww w.j a v a 2s.c o m } } return retVal; }
From source file:com.healthcit.cacure.web.controller.question.BaseFormElementController.java
protected Set<Category> prepareCategories(HttpServletRequest req, Map lookupData) { // Save newly added String addedCategoryIds = req.getParameter(PARAM_ADDED_CATEGORY_IDS); HashMap<String, Category> newCategories = new HashMap<String, Category>(); if (StringUtils.isNotBlank(addedCategoryIds)) { for (String tempId : addedCategoryIds.split(",")) { String name = req.getParameter("category_name_" + tempId); String description = req.getParameter("category_description_" + tempId); Category category = new Category(); category.setName(name);/*from w w w .j a v a 2s . c o m*/ category.setDescription(description); categoryManager.saveCategory(category); newCategories.put(tempId, category); } } // Collect selected categories String selectedCategoryIds = req.getParameter(PARAM_SELECTED_CATEGORIES); Set<Category> selectedCategories = new LinkedHashSet<Category>(); if (StringUtils.isNotBlank(selectedCategoryIds)) { List<Category> categories = (List<Category>) lookupData.get(KEY_ALL_CATEGORIES); String[] idsSA = selectedCategoryIds.split(","); for (String id : idsSA) { if (StringUtils.isNumeric(id)) { Long lId = Long.valueOf(id); for (Category cat : categories) { if (cat.getId().equals(lId)) { selectedCategories.add(cat); break; } } } else { Category newCategory = newCategories.get(id); if (newCategory != null) { selectedCategories.add(newCategory); } } } } return selectedCategories; }
From source file:com.greenline.hrs.admin.web.war.user.UserInfoController.java
/** * /*from w w w . ja va 2 s .co m*/ * * @param map ?,id. * @return JSON?, ???. */ @RequestMapping(value = "/del", method = RequestMethod.POST, produces = { "application/json;charset=UTF-8" }) @ResponseBody public Object deleteUser(@RequestBody MultiValueMap<String, String> map) { String uidStr = map.getFirst("uid"); //id??, if (!StringUtils.isNumeric(uidStr)) { LOG.info(UserResponseConst.ADD_USER_FAIL + uidStr); return JSONResponseUtil.failObject(UserResponseConst.DEL_USER_FAIL); } userInfoService.delUserNomalInfo(Long.valueOf(uidStr)); LOG.info(JSONResponseUtil.successString(UserResponseConst.DEL_USER_SUCCESS)); return JSONResponseUtil.successObject(UserResponseConst.DEL_USER_SUCCESS); }
From source file:fr.paris.lutece.plugins.directory.web.action.MassDeleteRecordsDirectoryAction.java
/** * Redirects to {@link #JSP_DIRECTORY_MASS_REMOVE_RECORDS} *///from w w w .ja v a2 s . c om public IPluginActionResult process(HttpServletRequest request, HttpServletResponse response, AdminUser adminUser, DirectoryAdminSearchFields sessionFields) throws AccessDeniedException { IPluginActionResult result = new DefaultPluginActionResult(); String strRedirect = StringUtils.EMPTY; if ((sessionFields.getSelectedRecords() != null) && !sessionFields.getSelectedRecords().isEmpty()) { String strIdDirectory = request.getParameter(DirectoryUtils.PARAMETER_ID_DIRECTORY); UrlItem url = new UrlItem(AppPathService.getBaseUrl(request) + JSP_DIRECTORY_MASS_REMOVE_RECORDS); url.addParameter(DirectoryUtils.PARAMETER_ID_DIRECTORY, strIdDirectory); for (String strIdRecord : sessionFields.getSelectedRecords()) { if (StringUtils.isNotBlank(strIdRecord) && StringUtils.isNumeric(strIdRecord)) { url.addParameter(DirectoryUtils.PARAMETER_ID_DIRECTORY_RECORD, strIdRecord); } } strRedirect = url.getUrl(); } else { strRedirect = AdminMessageService.getMessageUrl(request, DirectoryUtils.MESSAGE_SELECT_RECORDS, AdminMessage.TYPE_INFO); } result.setRedirect(strRedirect); return result; }