Example usage for org.apache.commons.validator GenericValidator isBlankOrNull

List of usage examples for org.apache.commons.validator GenericValidator isBlankOrNull

Introduction

In this page you can find the example usage for org.apache.commons.validator GenericValidator isBlankOrNull.

Prototype

public static boolean isBlankOrNull(String value) 

Source Link

Document

Checks if the field isn't null and length of the field is greater than zero not including whitespace.

Usage

From source file:net.bpfurtado.tas.model.persistence.XMLAdventureReader.java

/**
 * @param scene//w  w  w  . j  a  v a2  s  .  c  o m
 * @param scenesNotScannedYet
 *            Just to keep the scenes not yet visited.
 */
@SuppressWarnings("unchecked")
private void findAllTos(Scene scene, Collection<Scene> scenesNotScannedYet) {
    if (scenesNotScannedYet != null) {
        scenesNotScannedYet.remove(scene);
    }

    Node sceneNode = xmlDocument.selectSingleNode("//scene[@id='" + scene.getId() + "']");
    List<Node> pathNodes = sceneNode.selectNodes("./path");
    int i = 0;
    logger.debug("Scene=" + scene + ", pathNodes.sz=" + pathNodes.size());
    for (Node pathNode : pathNodes) {
        logger.debug(i);
        IPath p = scene.createPath(pathNode.getText());
        String orderStr = pathNode.valueOf("@order");
        if (orderStr == null || orderStr.length() == 0) {
            p.setOrder(i++);
        }
        String idToStr = pathNode.valueOf("@toScene");
        if (!GenericValidator.isBlankOrNull(idToStr)) {
            Scene to = adventure.getScene(Integer.parseInt(idToStr));
            boolean hadScenesFrom = !to.getScenesFrom().isEmpty();
            p.setTo(to);

            logger.debug(p);

            if (!hadScenesFrom) {
                logger.debug("BEFORE RECURSION: to=" + to);
                logger.debug("BEFORE RECURSION: all=" + scenesNotScannedYet);
                if (scenesNotScannedYet.contains(to)) {
                    findAllTos(to, scenesNotScannedYet);
                }
            }
        } else {
            logger.debug(p);
        }
    }
}

From source file:de.codecentric.janus.plugin.bootstrap.BootstrapProjectAction.java

public String validateNewUsername(JiraClient client, String username) {
    if (GenericValidator.isBlankOrNull(username)) {
        return "Please enter a username.";
    } else if (isUsernameRegistered(client, username)) {
        return "This username is already used.";
    }/* w  ww .j  av  a  2s .c o m*/

    return null;
}

From source file:com.core.validators.CommonValidator.java

public static boolean validateRequiredIf(Object bean, Field field, Validator validator) {

    Object form = validator.getParameterValue(Validator.BEAN_PARAM);
    String value = null;//from  w w w  .j a  v  a  2s .  c o  m
    boolean required = false;
    if (isString(bean)) {
        value = (String) bean;
    } else {
        value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    }
    int i = 0;
    String fieldJoin = "AND";
    if (!GenericValidator.isBlankOrNull(field.getVarValue("fieldJoin"))) {
        fieldJoin = field.getVarValue("fieldJoin");
    }
    if (fieldJoin.equalsIgnoreCase("AND")) {
        required = true;
    }
    while (!GenericValidator.isBlankOrNull(field.getVarValue("field[" + i + "]"))) {
        String dependProp = field.getVarValue("field[" + i + "]");
        String dependTest = field.getVarValue("fieldTest[" + i + "]");
        String dependTestValue = field.getVarValue("fieldValue[" + i + "]");
        String dependIndexed = field.getVarValue("fieldIndexed[" + i + "]");
        if (dependIndexed == null)
            dependIndexed = "false";
        String dependVal = null;
        boolean this_required = false;
        if (field.isIndexed() && dependIndexed.equalsIgnoreCase("true")) {
            String key = field.getKey();
            if ((key.indexOf("[") > -1) && (key.indexOf("]") > -1)) {
                String ind = key.substring(0, key.indexOf(".") + 1);
                dependProp = ind + dependProp;
            }
        }
        dependVal = ValidatorUtils.getValueAsString(form, dependProp);
        if (dependTest.equals(FIELD_TEST_NULL)) {
            if ((dependVal != null) && (dependVal.length() > 0)) {
                this_required = false;
            } else {
                this_required = true;
            }
        }
        if (dependTest.equals(FIELD_TEST_NOTNULL)) {
            if ((dependVal != null) && (dependVal.length() > 0)) {
                this_required = true;
            } else {
                this_required = false;
            }
        }
        if (dependTest.equals(FIELD_TEST_EQUAL)) {
            this_required = dependTestValue.equalsIgnoreCase(dependVal);
        }
        if (fieldJoin.equalsIgnoreCase("AND")) {
            required = required && this_required;
        } else {
            required = required || this_required;
        }
        i++;
    }
    if (required) {
        if ((value != null) && (value.length() > 0)) {
            return true;
        } else {
            return false;
        }
    }
    return true;
}

From source file:gov.va.vinci.leo.ae.LeoBaseAnnotator.java

/**
 * Initialize this annotator./*from  w ww  . j  a v  a  2 s  .co m*/
 *
 * @param aContext the UimaContext to initialize with.
 * @param params the annotator params to load from the descriptor.
 *
 * @see org.apache.uima.analysis_component.JCasAnnotator_ImplBase#initialize(org.apache.uima.UimaContext)
 * @param aContext
 * @param params
 * @throws ResourceInitializationException  if any exception occurs during initialization.
 */
public void initialize(UimaContext aContext, ConfigurationParameter[] params)
        throws ResourceInitializationException {
    super.initialize(aContext);

    if (params != null) {
        for (ConfigurationParameter param : params) {
            if (param.isMandatory()) {
                /** Check for null value **/
                if (aContext.getConfigParameterValue(param.getName()) == null) {
                    throw new ResourceInitializationException(new IllegalArgumentException(
                            "Required parameter: " + param.getName() + " not set."));
                }
                /** Check for empty as well if it is a plain string. */
                if (ConfigurationParameter.TYPE_STRING.equals(param.getType()) && !param.isMultiValued()
                        && GenericValidator
                                .isBlankOrNull((String) aContext.getConfigParameterValue(param.getName()))) {
                    throw new ResourceInitializationException(new IllegalArgumentException(
                            "Required parameter: " + param.getName() + " cannot be blank."));
                }
            }

            parameters.put(param, aContext.getConfigParameterValue(param.getName()));

            /** Set the parameter value in the class field variable **/
            try {
                Field field = FieldUtils.getField(this.getClass(), param.getName(), true);
                if (field != null) {
                    FieldUtils.writeField(field, this, aContext.getConfigParameterValue(param.getName()), true);
                }
            } catch (IllegalAccessException e) {
                logger.warn("Could not set field (" + param.getName()
                        + "). Field not found on annotator class to reflectively set.");
            }
        }
    }
}

From source file:de.codecentric.janus.plugin.bootstrap.BootstrapProjectAction.java

public String validateNewFullName(JiraClient client, String fullName) {
    if (GenericValidator.isBlankOrNull(fullName)) {
        return "Please enter a full name.";
    }/*from   w ww  .ja v a 2s  . c  om*/

    return null;
}

From source file:de.codecentric.janus.plugin.bootstrap.BootstrapProjectAction.java

public String validateNewEmail(JiraClient client, String email) {
    if (GenericValidator.isBlankOrNull(email)) {
        return "Please enter an email address.";
    } else if (!EmailValidator.getInstance().isValid(email)) {
        return "Please enter a valid email address.";
    } else if (isEmailAddressRegistered(client, email)) {
        return "Email address already registered.";
    }//  ww w.  jav  a  2 s.  c  o  m

    return null;
}

From source file:de.codecentric.janus.plugin.bootstrap.BootstrapProjectAction.java

public String validateNewPassword(JiraClient client, String password) {
    if (GenericValidator.isBlankOrNull(password)) {
        return "Please enter a password.";
    } else if (password.length() < 5) {
        return "Minimum password length is 5 characters.";
    }//from w w w.  jav a2s .com

    return null;
}

From source file:com.dell.asm.asmcore.asmmanager.util.ServiceTemplateValidator.java

public void validateTemplateFields(final ServiceTemplate svcTemplate) {
    final ServiceTemplateValid serviceTemplateValid = svcTemplate.getTemplateValid();

    // validate template name
    String templateName = svcTemplate.getTemplateName();
    if (GenericValidator.isBlankOrNull(templateName)) {
        serviceTemplateValid.addMessage(AsmManagerMessages.InvalidTemplateName(templateName));
    } else {//from w w  w  . j  a va2  s .co m
        // TODO[fcarta] find out if we need this doesnt look like it really does anything
        templateName = templateName.trim();
        Validator.isLocalisedTemplateNameValid(templateName);
    }
    if (!GenericValidator.isInRange(templateName.length(), Validator.NAME_MIN_SIZE, Validator.NAME_MAX_SIZE)) {
        serviceTemplateValid.addMessage(AsmManagerMessages.InvalidTemplateNameLength(templateName));
    }
    svcTemplate.setTemplateName(templateName.trim());

    // validate template description
    String description = svcTemplate.getTemplateDescription();
    try {
        Validator.validateDescription(description);
    } catch (AsmValidationException ex) {
        serviceTemplateValid.addMessage(ex.getEEMILocalizableMessage());
    }

    // if there are any validation error messages then template is invalid
    if (CollectionUtils.isNotEmpty(serviceTemplateValid.getMessages())) {
        serviceTemplateValid.setValid(Boolean.FALSE);
    }
}

From source file:com.aoindustries.website.signup.SignupCustomizeManagementActionHelper.java

public static void printConfirmation(HttpServletRequest request, ChainWriter emailOut, AOServConnector rootConn,
        SignupCustomizeManagementForm signupCustomizeManagementForm) throws IOException, SQLException {
    String backupOnsiteOption = getBackupOnsiteOption(rootConn, signupCustomizeManagementForm);
    if (!GenericValidator.isBlankOrNull(backupOnsiteOption)) {
        emailOut.print("    <tr>\n" + "        <td>").print(accessor.getMessage("signup.notRequired"))
                .print("</td>\n" + "        <td>")
                .print(accessor.getMessage("signupCustomizeManagementConfirmation.backupOnsite.prompt"))
                .print("</td>\n" + "        <td>").print(backupOnsiteOption).print("</td>\n" + "    </tr>\n");
    }/* w  w  w  . j av a2  s .  c  o m*/
    String backupOffsiteOption = getBackupOffsiteOption(rootConn, signupCustomizeManagementForm);
    if (!GenericValidator.isBlankOrNull(backupOffsiteOption)) {
        emailOut.print("    <tr>\n" + "        <td>").print(accessor.getMessage("signup.notRequired"))
                .print("</td>\n" + "        <td>")
                .print(accessor.getMessage("signupCustomizeManagementConfirmation.backupOffsite.prompt"))
                .print("</td>\n" + "        <td>").print(backupOffsiteOption).print("</td>\n" + "    </tr>\n");
    }
    String backupDvdOption = getBackupDvdOption(rootConn, signupCustomizeManagementForm);
    if (!GenericValidator.isBlankOrNull(backupDvdOption)) {
        emailOut.print("    <tr>\n" + "        <td>").print(accessor.getMessage("signup.notRequired"))
                .print("</td>\n" + "        <td>")
                .print(accessor.getMessage("signupCustomizeManagementConfirmation.backupDvd.prompt"))
                .print("</td>\n" + "        <td>").print(backupDvdOption).print("</td>\n" + "    </tr>\n");
    }
    String distributionScanOption = getDistributionScanOption(rootConn, signupCustomizeManagementForm);
    if (!GenericValidator.isBlankOrNull(distributionScanOption)) {
        emailOut.print("    <tr>\n" + "        <td>").print(accessor.getMessage("signup.notRequired"))
                .print("</td>\n" + "        <td>")
                .print(accessor.getMessage("signupCustomizeManagementConfirmation.distributionScan.prompt"))
                .print("</td>\n" + "        <td>").print(distributionScanOption)
                .print("</td>\n" + "    </tr>\n");
    }
    String failoverOption = getFailoverOption(rootConn, signupCustomizeManagementForm);
    if (!GenericValidator.isBlankOrNull(failoverOption)) {
        emailOut.print("    <tr>\n" + "        <td>").print(accessor.getMessage("signup.notRequired"))
                .print("</td>\n" + "        <td>")
                .print(accessor.getMessage("signupCustomizeManagementConfirmation.failover.prompt"))
                .print("</td>\n" + "        <td>").print(failoverOption).print("</td>\n" + "    </tr>\n");
    }
    emailOut.print("    <tr>\n" + "        <td>").print(accessor.getMessage("signup.notRequired"))
            .print("</td>\n" + "        <td>")
            .print(accessor.getMessage("signupCustomizeManagementConfirmation.totalMonthlyRate.prompt"))
            .print("</td>\n" + "        <td>$").print(request.getAttribute("totalMonthlyRate"))
            .print("</td>\n" + "    </tr>\n");
}

From source file:de.knurt.fam.core.persistence.dao.ibatis.UserDao4ibatis.java

/**
 * {@inheritDoc} username must be only lower case with numbers.
 *///w w w.ja v a 2 s. c o m
@Override
public User getUserFromUsername(String username) {
    User result = null;
    if (!GenericValidator.isBlankOrNull(username)) {
        username = username.trim();
        String regexp = "^[a-z0-9]+$";
        if (GenericValidator.matchRegexp(username, regexp)) {
            List<User> users = this.getWhere(String.format("username = '%s'", username));
            if (users != null && users.size() == 1) {
                result = users.get(0);
            } else if (users.size() > 1) {
                FamLog.error(String.format("found %s users with username %s", users.size(), username),
                        201205091021l);
            } else {
                FamLog.info("no user found with username " + username, 201205091338l);
            }
        }
    }
    return result;
}