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

The following examples show how to use org.apache.commons.validator.GenericValidator#isLong() . 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: LongValidator.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the specified string into a long integer.
 * 
 * @param context
 *            FacesContext for the request we are processing
 * @param component
 *            UIComponent we are checking for correctness
 * @param value
 *            the value to parse
 * @throws ValidatorException
 *             if the specified string could not be parsed into a valid long
 *             integer.
 */
public static long parse(FacesContext context, UIComponent uiComponent,
        String value) throws ValidatorException {
    if (!GenericValidator.isLong(value)) {
        Object[] args = null;
        String label = JSFUtils.getLabel(uiComponent);
        if (label != null) {
            args = new Object[] { label };
        }
        ValidationException e = new ValidationException(
                ValidationException.ReasonEnum.LONG, label, null);
        String message = JSFUtils.getText(e.getMessageKey(), args, context);
        throw getException(message);
    }
    return Long.parseLong(value);
}
 
Example 3
Source File: LongParameterValidator.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.isLong(parameter.getValue())) {
        throw new ValidationException(ValidationException.ReasonEnum.LONG,
                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: ConfigurationSettingsValidator.java    From development with Apache License 2.0 5 votes vote down vote up
private static long parse(ConfigurationKey key, String value,
        Long minValue, Long maxValue) {
    if (!GenericValidator.isLong(value)) {
        minValue = (minValue != null ? minValue : Long
                .valueOf(Long.MIN_VALUE));
        maxValue = (maxValue != null ? maxValue : Long
                .valueOf(Long.MAX_VALUE));
        throw new RuntimeException(
                "The value for "
                        + key.getKeyName()
                        + " is illegal.Please enter a valid integer value within the range of "
                        + minValue + " and " + maxValue + ".");
    }
    return Long.parseLong(value);
}
 
Example 5
Source File: ConfigurationSettingsValidator.java    From development with Apache License 2.0 5 votes vote down vote up
private static long parse(PlatformConfigurationKey key, String value,
        Long minValue, Long maxValue) {
    if (!GenericValidator.isLong(value)) {
        minValue = (minValue != null ? minValue : Long
                .valueOf(Long.MIN_VALUE));
        maxValue = (maxValue != null ? maxValue : Long
                .valueOf(Long.MAX_VALUE));
        throw new RuntimeException(
                "The value for"
                        + key
                        + " is illegal.Please enter a valid integer value within the range of "
                        + minValue + " and " + maxValue + ".");
    }
    return Long.parseLong(value);
}
 
Example 6
Source File: ExternalParameterValidation.java    From development with Apache License 2.0 5 votes vote down vote up
private static boolean longIsValid(VOParameterDefinition parDefinition,
        String parValue) {
    if (GenericValidator.isLong(parValue.toString())) {
        return LongValidator.isInRange(Long.parseLong(parValue),
                parDefinition.getMinValue(), parDefinition.getMaxValue());
    } else {
        return false;
    }
}
 
Example 7
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 8
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 9
Source File: LongValidator.java    From development with Apache License 2.0 4 votes vote down vote up
/**
 * Parses the specified string into a long integer between the specified
 * minimum and maximum.
 * 
 * @param context
 *            FacesContext for the request we are processing
 * @param minValue
 *            the minimum allowed value
 * @param maxValue
 *            the maximum allowed value
 * @param value
 *            the value to parse
 * @throws ValidatorException
 *             if the specified string could not be parsed into a valid long
 *             integer or if it exceeds the specified minimum and maximum.
 */
private static long parse(FacesContext context, String value,
        Long minValue, Long maxValue) throws ValidatorException {
    if (!GenericValidator.isLong(value)) {
        minValue = (minValue != null ? minValue : Long
                .valueOf(Long.MIN_VALUE));
        maxValue = (maxValue != null ? maxValue : Long
                .valueOf(Long.MAX_VALUE));
        String message = JSFUtils.getText(
                BaseBean.ERROR_LONG_VALUE_OUT_OF_RANGE,
                new String[] { String.valueOf(minValue),
                        String.valueOf(maxValue) }, context);
        throw getException(message);
    }
    return Long.parseLong(value);
}
 
Example 10
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 long 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 long.
 */
public static void isLong(String member, String inputValue)
        throws ValidationException {
    if (!GenericValidator.isLong(inputValue)) {
        ValidationException vf = new ValidationException(ReasonEnum.LONG,
                member, new Object[] { inputValue });
        logValidationFailure(vf);
        throw vf;
    }
}
 
Example 11
Source File: ValidateUtil.java    From primecloud-controller with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 最小値、最大値チェック(long)
 *
 * @param value 入力チェック対象の値
 * @param min 最小値
 * @param max 最大値
 * @param code 入力チェックエラー時のメッセージコード
 * @param params 入力チェックエラー時のメッセージパラメータ
 */
public static void longInRange(String value, long min, long max, String code, Object... params) {
    if (GenericValidator.isLong(value) == false) {
        throw new AutoApplicationException(code, params);
    }
    if (GenericValidator.isInRange(Long.parseLong(value), min, max) == false) {
        throw new AutoApplicationException(code, params);
    }
}