Java Code Examples for org.apache.commons.validator.GenericValidator#isInt()

The following examples show how to use org.apache.commons.validator.GenericValidator#isInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataSetsSDKServiceImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
private void checkParameterValues(String[] values, DataSetParameterItem dataSetParameterItem) throws InvalidParameterValue {
	logger.debug("IN");
	try {
		String parameterType = dataSetParameterItem.getType();
		if (parameterType.equalsIgnoreCase("Number")) {
			for (int i = 0; i < values.length; i++) {
				String value = values[i];
				if (GenericValidator.isBlankOrNull(value)
						|| (!(GenericValidator.isInt(value) || GenericValidator.isFloat(value) || GenericValidator.isDouble(value)
								|| GenericValidator.isShort(value) || GenericValidator.isLong(value)))) {
					InvalidParameterValue error = new InvalidParameterValue();
					error.setParameterName(dataSetParameterItem.getName());
					error.setParameterType(parameterType);
					error.setWrongParameterValue(value);
					error.setParameterFormat("");
					throw error;
				}
			}
		}
	} finally {
		logger.debug("OUT");
	}
}
 
Example 2
Source File: ParameterValueValidator.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Validate integer value.
 * 
 * @param context
 *            JSF context.
 * @param uiComponent
 *            UI component.
 * @param value
 *            Value for validation.
 */
private void validateInteger(FacesContext context, UIComponent uiComponent,
        String value) {
    if (!GenericValidator.isInt(value.toString())) {
        Object[] args = null;
        String label = JSFUtils.getLabel(uiComponent);
        if (label != null) {
            args = new Object[] { label };
        }
        ValidationException e = new ValidationException(
                ValidationException.ReasonEnum.INTEGER, label, null);
        String text = JSFUtils.getText(e.getMessageKey(), args, context);
        throw new ValidatorException(new FacesMessage(
                FacesMessage.SEVERITY_ERROR, text, null));
    }
}
 
Example 3
Source File: IntegerParameterValidator.java    From development with Apache License 2.0 6 votes vote down vote up
@Override
public void validate(Object obj) throws ValidationException {
    super.validate(obj);
    VOParameter parameter = (VOParameter) obj;
    VOParameterDefinition parameterDefinition = parameter
            .getParameterDefinition();

    if(isOptionalAndNullOrEmpty(parameter)) {
        return;
    }
    
    if (!GenericValidator.isInt(parameter.getValue())) {
        throw new ValidationException(
                ValidationException.ReasonEnum.INTEGER, null,
                new Object[] { parameter.getParameterDefinition()
                        .getParameterId() });
    }

    if (!isValid(parameter, parameterDefinition)) {
        throw new ValidationException(
                ValidationException.ReasonEnum.VALUE_NOT_IN_RANGE, null,
                new Object[] { parameter.getParameterDefinition()
                        .getParameterId() });
    }
}
 
Example 4
Source File: ExternalParameterValidation.java    From development with Apache License 2.0 5 votes vote down vote up
private static boolean integerIsValid(VOParameterDefinition parDefinition,
        String parValue) {
    if (GenericValidator.isInt(parValue.toString())) {
        return LongValidator.isInRange(Integer.parseInt(parValue),
                parDefinition.getMinValue(), parDefinition.getMaxValue());
    } else {
        return false;
    }
}
 
Example 5
Source File: HcFtpToFileSystemConfigAction.java    From MicroCommunity with Apache License 2.0 4 votes vote down vote up
/**
 * 根据任务名称或任务ID模糊查询
 *
 * @return
 */
public String searchTaskByNameOrId(HttpServletRequest request) {

	String ftpItemJson = request.getParameter("ftpItemJson");
	JSONObject ftpItemJsonObj = null;
	try {
		// 校验格式是否正确
		// {"taskName":"经办人照片同步处理"}
		ftpItemJsonObj = JSONObject.parseObject(ftpItemJson);
	} catch (Exception e) {
		logger.error("传入参数格式不正确:" + ftpItemJson, e);
		resultMsg = createResultMsg("1999", "传入参数格式不正确:" + ftpItemJson, "");
		return "addFtpItem";
	}

	// 将ftpItemJson装为Map保存操作
	Map paramIn = JSONObject.parseObject(ftpItemJsonObj.toJSONString(), Map.class);

	String taskNameOrTaskId = paramIn.get("taskName") == null ? "1" : paramIn.get("taskName").toString();

	taskNameOrTaskId = ValidatorUtils.getValueAsString(paramIn, "taskName");

	// 规则校验
	JSONObject data = new JSONObject();
	data.put("total", 1); // 搜索不进行分页处理
	data.put("currentPage", 1);
	List<Map> ftpItems = null;
	// 说明是taskId
	if (GenericValidator.isInt(taskNameOrTaskId) || GenericValidator.isLong(taskNameOrTaskId)) {
		// 根据taskId 查询记录
		paramIn.put("taskId", taskNameOrTaskId);
		Map ftpItem = iHcFtpFileDAO.queryFtpItemByTaskId(paramIn);
		if (ftpItem != null && ftpItem.containsKey("FTP_ITEM_ATTRS")) {
			ftpItem.remove("FTP_ITEM_ATTRS");// 前台暂时用不到,所以这里将属性移除

			ftpItems = new ArrayList<Map>();
			ftpItems.add(ftpItem);
		}
	} else {
		ftpItems = iHcFtpFileDAO.searchFtpItemByTaskName(paramIn);
	}

	JSONArray rows = new JSONArray();
	if (ftpItems != null && ftpItems.size() > 0) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		for (Map ftpItemMap : ftpItems) {

			// 处理时间显示和界面显示传输类型
			ftpItemMap.put("U_OR_D_NAME", ftpItemMap.get("U_OR_D"));// 暂且写死,最终还是读取配置
			ftpItemMap.put("CREATE_DATE", df.format(ftpItemMap.get("CREATE_DATE")));// 暂且写死,最终还是读取配置
			rows.add(JSONObject.parseObject(JSONObject.toJSONString(ftpItemMap)));
		}
	}
	data.put("rows", rows);
	resultMsg = data;
	return "searchTaskByNameOrId";
}
 
Example 6
Source File: QueryDetail.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
private void validateNumber(String value) {
	if (!(GenericValidator.isInt(value) || GenericValidator.isFloat(value) || GenericValidator.isDouble(value) || GenericValidator.isShort(value)
			|| GenericValidator.isLong(value))) {
		throw new SecurityException("Input value " + value + " is not a valid number");
	}
}
 
Example 7
Source File: BLValidator.java    From development with Apache License 2.0 3 votes vote down vote up
/**
 * Validates that the given input string is a valid integer number.
 * 
 * @param member
 *            The indicator of the field to be validated.
 * @param inputValue
 *            The value to be validated.
 * @throws ValidationException
 *             Thrown in case the value is not a valid integer.
 */
public static void isInteger(String member, String inputValue)
        throws ValidationException {
    if (!GenericValidator.isInt(inputValue)) {
        ValidationException vf = new ValidationException(
                ReasonEnum.INTEGER, member, new Object[] { inputValue });
        logValidationFailure(vf);
        throw vf;
    }
}
 
Example 8
Source File: ValidateUtil.java    From primecloud-controller with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 最小値、最大値チェック(int)
 *
 * @param value 入力チェック対象の値
 * @param min 最小値
 * @param max 最大値
 * @param code 入力チェックエラー時のメッセージコード
 * @param params 入力チェックエラー時のメッセージパラメータ
 */
public static void intInRange(String value, int min, int max, String code, Object[] params) {
    if (GenericValidator.isInt(value) == false) {
        throw new AutoApplicationException(code, params);
    }
    if (GenericValidator.isInRange(Integer.valueOf(value), min, max) == false) {
        throw new AutoApplicationException(code, params);
    }
}