List of usage examples for org.apache.commons.validator GenericValidator isBlankOrNull
public static boolean isBlankOrNull(String value)
Checks if the field isn't null and length of the field is greater than zero not including whitespace.
From source file:com.sapienter.jbilling.common.GatewayBL.java
private Date getDatePar(String name, boolean required) { Date retValue = null;//from w ww .j a v a 2 s.c o m String field = request.getParameter(name); if (required && GenericValidator.isBlankOrNull(field)) { code = RES_CODE_ERROR; subCode = RES_SUB_CODE_ERR_REQ; text = MSG_REQUIRED + " [" + name + "]"; } else { if (field != null) { retValue = Util.parseDate(field); if (retValue == null) { code = RES_CODE_ERROR; subCode = RES_SUB_CODE_ERR_TYPE; text = name + MSG_DATE; } } } return retValue; }
From source file:jp.terasoluna.fw.web.struts.form.FieldChecksEx.java
/** * wtB?[hpJi`FbN?B//from w w w. j a v a2s . c om * * <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 * ActionMessages ANVG?[ * @param validator * ValidatorCX^X * @param request * HTTPNGXg * @return l? <code>true</code> */ public static boolean validateHankakuKanaString(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) { // beannull?AG?[?O?o?Atruep?B if (bean == null) { log.error("bean is null."); return true; } String value = null; if (isString(bean)) { value = (String) bean; } else { value = ValidatorUtils.getValueAsString(bean, field.getProperty()); } // ?lnull?Atruep if (GenericValidator.isBlankOrNull(value)) { return true; } char[] chars = value.toCharArray(); for (int i = 0; i < chars.length; i++) { if (!isHankakuKana(chars[i])) { errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field)); return false; } } return true; }
From source file:com.sapienter.jbilling.common.GatewayBL.java
private Integer getIntPar(String name, boolean required) { Integer retValue = null;//from w w w . j a va 2 s . c o m String field = request.getParameter(name); if (required && GenericValidator.isBlankOrNull(field)) { code = RES_CODE_ERROR; subCode = RES_SUB_CODE_ERR_REQ; text = MSG_REQUIRED + " [" + name + "]"; } else { if (field != null) { try { retValue = Integer.valueOf(field); } catch (NumberFormatException e) { code = RES_CODE_ERROR; subCode = RES_SUB_CODE_ERR_TYPE; text = name + MSG_INT; } } } return retValue; }
From source file:com.sapienter.jbilling.common.GatewayBL.java
private Float getFloatPar(String name, boolean required) { Float retValue = null;/*from ww w .j ava2s . co m*/ String field = request.getParameter(name); if (required && GenericValidator.isBlankOrNull(field)) { code = RES_CODE_ERROR; subCode = RES_SUB_CODE_ERR_REQ; text = MSG_REQUIRED + " [" + name + "]"; } else { if (field != null) { try { retValue = Float.valueOf(field); } catch (NumberFormatException e) { code = RES_CODE_ERROR; subCode = RES_SUB_CODE_ERR_TYPE; text = name + MSG_FLOAT; } } } return retValue; }
From source file:jp.terasoluna.fw.web.struts.form.FieldChecksEx.java
/** * wtB?[hp`FbN?B/* w w w . j a v a 2 s .c om*/ * * <p> * G?[???AG?[????A wG?[?Xg?BG?[?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 validateHankakuString(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) { // beannull?AG?[?O?o?Atruep?B if (bean == null) { log.error("bean is null."); return true; } String value = null; if (isString(bean)) { value = (String) bean; } else { value = ValidatorUtils.getValueAsString(bean, field.getProperty()); } // ?lnull?Atruep if (GenericValidator.isBlankOrNull(value)) { return true; } char[] chars = value.toCharArray(); for (int i = 0; i < chars.length; i++) { if (!isHankaku(chars[i])) { errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field)); return false; } } return true; }
From source file:com.aoindustries.website.signup.SignupCustomizeServerActionHelper.java
public static void printConfirmation(HttpServletRequest request, ChainWriter emailOut, AOServConnector rootConn, PackageDefinition packageDefinition, SignupCustomizeServerForm signupCustomizeServerForm) throws IOException, SQLException { String powerOption = getPowerOption(rootConn, signupCustomizeServerForm); if (!GenericValidator.isBlankOrNull(powerOption)) { emailOut.print(" <tr>\n" + " <td>").print(accessor.getMessage("signup.notRequired")) .print("</td>\n" + " <td>") .print(accessor.getMessage("signupCustomizeServerConfirmation.power.prompt")) .print("</td>\n" + " <td>").print(powerOption).print("</td>\n" + " </tr>\n"); }// w w w . j a v a 2 s. co m emailOut.print(" <tr>\n" + " <td>").print(accessor.getMessage("signup.notRequired")) .print("</td>\n" + " <td>") .print(accessor.getMessage("signupCustomizeServerConfirmation.cpu.prompt")) .print("</td>\n" + " <td>").print(getCpuOption(rootConn, signupCustomizeServerForm)) .print("</td>\n" + " </tr>\n" + " <tr>\n" + " <td>") .print(accessor.getMessage("signup.notRequired")).print("</td>\n" + " <td>") .print(accessor.getMessage("signupCustomizeServerConfirmation.ram.prompt")) .print("</td>\n" + " <td>").encodeXhtml(getRamOption(rootConn, signupCustomizeServerForm)) .print("</td>\n" + " </tr>\n"); String sataControllerOption = getSataControllerOption(rootConn, signupCustomizeServerForm); if (!GenericValidator.isBlankOrNull(sataControllerOption)) { emailOut.print(" <tr>\n" + " <td>").print(accessor.getMessage("signup.notRequired")) .print("</td>\n" + " <td>") .print(accessor.getMessage("signupCustomizeServerConfirmation.sataController.prompt")) .print("</td>\n" + " <td>").print(sataControllerOption).print("</td>\n" + " </tr>\n"); } String scsiControllerOption = getScsiControllerOption(rootConn, signupCustomizeServerForm); if (!GenericValidator.isBlankOrNull(scsiControllerOption)) { emailOut.print(" <tr>\n" + " <td>").print(accessor.getMessage("signup.notRequired")) .print("</td>\n" + " <td>") .print(accessor.getMessage("signupCustomizeServerConfirmation.scsiController.prompt")) .print("</td>\n" + " <td>").print(scsiControllerOption).print("</td>\n" + " </tr>\n"); } for (String diskOption : getDiskOptions(rootConn, signupCustomizeServerForm)) { emailOut.print(" <tr>\n" + " <td>").print(accessor.getMessage("signup.notRequired")) .print("</td>\n" + " <td>") .print(accessor.getMessage("signupCustomizeServerConfirmation.disk.prompt")) .print("</td>\n" + " <td>").encodeXhtml(diskOption).print("</td>\n" + " </tr>\n"); } emailOut.print(" <tr>\n" + " <td>").print(accessor.getMessage("signup.notRequired")) .print("</td>\n" + " <td>") .print(accessor.getMessage("signupCustomizeServerConfirmation.setup.prompt")) .print("</td>\n" + " <td>\n"); BigDecimal setup = packageDefinition.getSetupFee(); if (setup == null) { emailOut.print(" ") .print(accessor.getMessage("signupCustomizeServerConfirmation.setup.none")).print("\n"); } else { emailOut.print(" $").print(setup).print("\n"); } emailOut.print(" </td>\n" + " </tr>\n" + " <tr>\n" + " <td>") .print(accessor.getMessage("signup.notRequired")) .print("</td>\n" + " <td style='white-space:nowrap'>") .print(accessor.getMessage("signupCustomizeServerConfirmation.monthlyRate.prompt")) .print("</td>\n" + " <td>$").print(request.getAttribute("monthlyRate")) .print("</td>\n" + " </tr>\n"); }
From source file:jp.terasoluna.fw.web.struts.form.FieldChecksEx.java
/** * wtB?[hSp`FbN?B//from w w w .j a va 2 s . c o m * * <p> * G?[???AG?[????A wG?[?Xg?BG?[?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 validateZenkakuString(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) { // beannull?AG?[?O?o?Atruep?B if (bean == null) { log.error("bean is null."); return true; } String value = null; if (isString(bean)) { value = (String) bean; } else { value = ValidatorUtils.getValueAsString(bean, field.getProperty()); } // ?lnull?Atruep if (GenericValidator.isBlankOrNull(value)) { return true; } char[] chars = value.toCharArray(); for (int i = 0; i < chars.length; i++) { if (!isZenkaku(chars[i])) { errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field)); return false; } } return true; }
From source file:jp.terasoluna.fw.validation.FieldChecks.java
/** * ???int??????//from w w w. ja va 2 s . co m * ?????? * * <p>???10?100??????????? * true????? * * <h5>validation.xml?</h5> * <code><pre> * <form name="sample"> * * <field property="intField" * depends="intRange"> * <arg key="sample.intField" position="0"/> * <var> * <var-name>intRangeMin</var-name> * <var-value>10</var-value> * </var> * <var> * <var-name>intRangeMax</var-name> * <var-value>100</var-value> * </var> * </field> * * </form> * </pre></code> * * <h5>validation.xml???<var>?</h5> * <table border="1"> * <tr> * <td><center><b><code>var-name</code></b></center></td> * <td><center><b><code>var-value</code></b></center></td> * <td><center><b></b></center></td> * <td><center><b>?</b></center></td> * </tr> * <tr> * <td> intRangeMin </td> * <td>?</td> * <td>false</td> * <td>????????Integer??? * ? * ????????</td> * </tr> * <tr> * <td> intRangeMax </td> * <td></td> * <td>false</td> * <td>???????Integer?? * ? * ????????</td> * </tr> * </table> * * @param bean ?JavaBean * @param va ?<code>ValidatorAction</code> * @param field ?<code>Field</code> * @param errors ????? * ?? * @return ??????<code>true</code>? * ????<code>false</code>? * @throws ValidatorException validation?????? * ? */ public boolean validateIntRange(Object bean, ValidatorAction va, Field field, ValidationErrors errors) throws ValidatorException { // String value = extractValue(bean, field); if (StringUtils.isEmpty(value)) { return true; } // int?? --- Integer?????? int intValue = 0; try { intValue = Integer.parseInt(value); } catch (NumberFormatException e) { rejectValue(errors, field, va, bean); return false; } // --- ?Integer?????? // ???? String strMin = field.getVarValue("intRangeMin"); int min = Integer.MIN_VALUE; if (!GenericValidator.isBlankOrNull(strMin)) { try { min = Integer.parseInt(strMin); } catch (NumberFormatException e) { String message = "Mistake on validation definition file. " + "- intRangeMin is not number. " + "You'll have to check it over. "; log.error(message, e); throw new ValidatorException(message); } } String strMax = field.getVarValue("intRangeMax"); int max = Integer.MAX_VALUE; if (!GenericValidator.isBlankOrNull(strMax)) { try { max = Integer.parseInt(strMax); } catch (NumberFormatException e) { String message = "Mistake on validation definition file. " + "- intRangeMax is not number. " + "You'll have to check it over. "; log.error(message, e); throw new ValidatorException(message); } } // if (!GenericValidator.isInRange(intValue, min, max)) { rejectValue(errors, field, va, bean); return false; } return true; }
From source file:jp.terasoluna.fw.web.struts.form.FieldChecksEx.java
/** * wtB?[hSpJ^Ji`FbN?B//from www . j a v a2 s. c o m * * <p> * G?[???AG?[????A wG?[?Xg?BG?[?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 validateZenkakuKanaString(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) { // beannull?AG?[?O?o?Atruep?B if (bean == null) { log.error("bean is null."); return true; } String value = null; if (isString(bean)) { value = (String) bean; } else { value = ValidatorUtils.getValueAsString(bean, field.getProperty()); } // ?lnull?Atruep if (GenericValidator.isBlankOrNull(value)) { return true; } char[] chars = value.toCharArray(); for (int i = 0; i < chars.length; i++) { if (!isZenkakuKana(chars[i])) { errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field)); return false; } } return true; }
From source file:jp.terasoluna.fw.validation.FieldChecks.java
/** * ???double??????//from w ww.jav a 2 s. c o m * ?????? * * <p>???10?100??????????? * true????? * * <h5>validation.xml?</h5> * <code><pre> * <form name="sample"> * * <field property="doubleField" * depends="doubleRange"> * <arg key="sample.doubleField" position="0"/> * <var> * <var-name>doubleRangeMin</var-name> * <var-value>10.0</var-value> * </var> * <var> * <var-name>doubleRangeMax</var-name> * <var-value>100.0</var-value> * </var> * </field> * * </form> * </pre></code> * * <h5>validation.xml???<var>?</h5> * <table border="1"> * <tr> * <td><center><b><code>var-name</code></b></center></td> * <td><center><b><code>var-value</code></b></center></td> * <td><center><b></b></center></td> * <td><center><b>?</b></center></td> * </tr> * <tr> * <td> doubleRangeMin </td> * <td>?</td> * <td>false</td> * <td>????????Double??? * ? * ????????</td> * </tr> * <tr> * <td> doubleRangeMax </td> * <td></td> * <td>false</td> * <td>???????Double?? * ? * ????????</td> * </tr> * </table> * * @param bean ?JavaBean * @param va ?<code>ValidatorAction</code> * @param field ?<code>Field</code> * @param errors ????? * ?? * @return ??????<code>true</code>? * ????<code>false</code>? * @throws ValidatorException validation?????? * ? */ public boolean validateDoubleRange(Object bean, ValidatorAction va, Field field, ValidationErrors errors) throws ValidatorException { // String value = extractValue(bean, field); if (StringUtils.isEmpty(value)) { return true; } // double?? --- Double?????? double dblValue = 0; try { dblValue = Double.parseDouble(value); } catch (NumberFormatException e) { rejectValue(errors, field, va, bean); return false; } // --- ?Double?????? // ???? String strMin = field.getVarValue("doubleRangeMin"); double min = Double.MIN_VALUE; if (!GenericValidator.isBlankOrNull(strMin)) { try { min = Double.parseDouble(strMin); } catch (NumberFormatException e) { String message = "Mistake on validation definition file. " + "- doubleRangeMin is not number. " + "You'll have to check it over. "; log.error(message, e); throw new ValidatorException(message); } } String strMax = field.getVarValue("doubleRangeMax"); double max = Double.MAX_VALUE; if (!GenericValidator.isBlankOrNull(strMax)) { try { max = Double.parseDouble(strMax); } catch (NumberFormatException e) { String message = "Mistake on validation definition file. " + "- doubleRangeMax is not number. " + "You'll have to check it over. "; log.error(message, e); throw new ValidatorException(message); } } // if (!GenericValidator.isInRange(dblValue, min, max)) { rejectValue(errors, field, va, bean); return false; } return true; }