List of usage examples for org.apache.commons.validator Field clone
@Override
public Object clone()
From source file:jp.terasoluna.fw.web.struts.form.FieldChecksEx.java
/** * wIndextB?[h?B//from w w w. j a v a2s .c om * * <b>?\bhANVtH?[? tH?[O?Ap?s???B</b> * * @param field * utB?[hIuWFNg * @param pos * ?CfbNX * @return u?tB?[hIuWFNg */ protected static Field getArrayIndexField(Field field, int pos) { Field cloneField = (Field) field.clone(); // ##index?A?vf?? Arg argParam = null; String argStr = null; argParam = cloneField.getArg(0); if (argParam != null) { argStr = argParam.getKey(); cloneField.getArg(0).setKey(replaceIndexString(argStr, pos + 1)); } argParam = cloneField.getArg(1); if (argParam != null) { argStr = argParam.getKey(); cloneField.getArg(1).setKey(replaceIndexString(argStr, pos + 1)); } argParam = cloneField.getArg(2); if (argParam != null) { argStr = argParam.getKey(); cloneField.getArg(2).setKey(replaceIndexString(argStr, pos + 1)); } argParam = cloneField.getArg(3); if (argParam != null) { argStr = argParam.getKey(); cloneField.getArg(3).setKey(replaceIndexString(argStr, pos + 1)); } return cloneField; }
From source file:jp.terasoluna.fw.web.struts.form.FieldChecksEx.java
/** * wtB?[hp?`FbN?B//from w w w . j a v a 2 s. c o m * * <p> * G?[???AG?[????A wG?[?Xg?B G?[?bZ?[WtH?[}bg?A<code>validation-rules.xml</code> * L?q?B * </p> * * @param bean * ??IuWFNg * @param va * StrutspValidatorAction * @param field * tB?[hIuWFNg * @param errors * ActionMessages ANVG?[ * @param validator * ValidatorCX^X * @param request * HTTPNGXg * @return l? <code>true</code> */ public static boolean validateAlphaNumericString(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) { // tB?[hN??[?? Field fieldClone = (Field) field.clone(); fieldClone.addVar("mask", "^[0-9a-zA-Z]*$", "false"); // p?l`FbN?s return validateMask(bean, va, fieldClone, errors, validator, request); }
From source file:jp.terasoluna.fw.web.struts.form.FieldChecksEx.java
/** * wtB?[h? `FbN?B//from w w w. j a va 2 s.c o m * * <p> * G?[???AG?[????A wG?[?Xg?B G?[?bZ?[WtH?[}bg?A * <code>validation-rules.xml</code>L?q?B * </p> * * @param bean * ??IuWFNg * @param va * <code>Validator</code>p <code>ValidatorAction</code> * @param field * tB?[hIuWFNg * @param errors * ANVG?[ * @param validator * ValidatorCX^X * @param request * HTTPNGXg * @return l? <code>true</code> */ public static boolean validateNumericString(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) { // tB?[hN??[?? Field fieldClone = (Field) field.clone(); fieldClone.addVar("mask", "^[0-9]*$", "false"); // ?l`FbN?s return validateMask(bean, va, fieldClone, errors, validator, request); }
From source file:jp.terasoluna.fw.web.struts.form.FieldChecksEx.java
/** * wtB?[hp?`FbN?B/*from w w w. ja va2s. c o m*/ * * <p> * G?[???AG?[????A wG?[?Xg?B G?[?bZ?[WtH?[}bg?A<code>validation-rules.xml</code> * L?q?B * </p> * * @param bean * ??IuWFNg * @param va * StrutspValidatorAction * @param field * tB?[hIuWFNg * @param errors * ActionMessages ANVG?[ * @param validator * ValidatorCX^X * @param request * HTTPNGXg * @return l? <code>true</code> */ public static boolean validateCapAlphaNumericString(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) { // tB?[hN??[?? Field fieldClone = (Field) field.clone(); fieldClone.addVar("mask", "^[0-9A-Z]*$", "false"); // p?l`FbN?s return validateMask(bean, va, fieldClone, errors, validator, request); }
From source file:jp.terasoluna.fw.web.struts.form.FieldChecksEx.java
/** * z?ERNV^tB?[hlSvf`FbN?B/* w w w . jav a2 s . co m*/ * <p> * z?ERNV^tH?[vf??A? CfbNX? <code>ActionMessage</code>?B * ?sTu?\bh?^?A???A?\bh vKv?B * Fieldproperty?JXPathIndexedBeanWrapperImpldl?]?A * lXgv?peB?\?B * </p> * * @param bean * ??IuWFNg * @param va * Strutsp<code>ValidatorAction</code> * @param field * tB?[hIuWFNg * @param errors * ANVG?[ * @param validator * ValidatorCX^X * @param request * HTTPNGXg * @return vfl? <code>true</code> */ public static boolean validateArraysIndex(@SuppressWarnings("unused") Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) { // ?? int methodArgCount = 6; // z?ERNV???ifalsep???Afalse?j boolean totalResult = true; try { // RXgN^?NXp^?[ Class[] paramClass = getParamClass(va); if (paramClass == null) { log.error("Can not get class pattern."); return true; } // paramClassvf?=0?AG?[?O?o?Atruep if (paramClass.length == 0) { log.error("Class pattern length is zero."); return true; } // evf??s?\bh Method method = getMethod(va, paramClass); if (method == null) { log.error("Can not get validateMethod."); return true; } // tH?[IuWFNg ActionForm form = getActionForm(request); if (form == null) { log.error("Can not get ActionForm."); return true; } // vfof?[V?[?A // O?svIuWFNg Object[] argParams = new Object[methodArgCount]; argParams[0] = form; argParams[1] = va; argParams[3] = errors; argParams[4] = validator; argParams[5] = request; IndexedBeanWrapper wrapper = new JXPathIndexedBeanWrapperImpl(form); Map<String, Object> propertyMap = wrapper.getIndexedPropertyValues(field.getKey()); int index = 0; for (String key : propertyMap.keySet()) { // CfbNXtv?peBtB?[h? Field indexedField = (Field) field.clone(); indexedField.setIndexedListProperty(null); indexedField = getArrayIndexField(indexedField, index); indexedField.setKey(key); indexedField.setProperty(key); argParams[2] = indexedField; // tB?[h // `FbN?\bh?o Object resultObj = method.invoke(FieldChecksEx.class, argParams); // ? if (!isValid(resultObj)) { totalResult = false; } index++; } } catch (IllegalArgumentException e) { log.error("", e); return true; } catch (IllegalAccessException e) { log.error("", e); return true; } catch (InvocationTargetException e) { log.error("", e); return true; } return totalResult; }
From source file:jp.terasoluna.fw.validation.FieldChecks.java
/** * ????????// w ww . j a v a2s . co m * ??????????errors??? * false?? * * <p>?????????? * ?????????validation.xml? * ??depends????Array??????? * depends="requiredArray" "required" ? * * @param bean ?JavaBean * @param va Validator????ValidatorAction * @param field * @param errors * @return ????????? true * @throws ValidatorException validation?????? * ???bean?null????? */ public boolean validateArraysIndex(Object bean, ValidatorAction va, Field field, ValidationErrors errors) throws ValidatorException { if (bean == null) { log.error("validation target bean is null."); throw new ValidatorException("validation target bean is null."); } @SuppressWarnings("rawtypes") Class[] paramClass = null; // ?? Method method = null; // try { paramClass = getParamClass(va); if (paramClass == null || paramClass.length == 0) { String message = "Mistake on validation rule file. " + "- Can not get argument class. " + "You'll have to check it over. "; log.error(message); throw new ValidatorException(message); } method = getMethod(va, paramClass); if (method == null) { String message = "Mistake on validation rule file. " + "- Can not get validateMethod. " + "You'll have to check it over. "; log.error(message); throw new ValidatorException(message); } } catch (RuntimeException e) { log.error(e.getMessage(), e); throw new ValidatorException(e.getMessage()); } try { // ??????????? Object[] argParams = new Object[paramClass.length]; argParams[0] = bean; argParams[1] = va; argParams[3] = errors; // ????? IndexedBeanWrapper bw = getIndexedBeanWrapper(bean); Map<String, Object> propertyMap = bw.getIndexedPropertyValues(field.getKey()); boolean isValid = true; // for (String key : propertyMap.keySet()) { // ?????????? Field indexedField = (Field) field.clone(); indexedField.setKey(key); indexedField.setProperty(key); argParams[2] = indexedField; // // ???? boolean bool = (Boolean) method.invoke(this, argParams); if (!bool) { isValid = false; } } return isValid; } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof ValidatorException) { throw (ValidatorException) t; } log.error(t.getMessage(), t); throw new ValidatorException(t.getMessage()); } catch (Exception e) { log.error(e.getMessage(), e); throw new ValidatorException(e.getMessage()); } }