Search in sources :

Example 1 with Validator

use of org.apache.commons.validator.Validator in project sonarqube by SonarSource.

the class Resources method initValidator.

/**
     * Initialize the <code>Validator</code> to perform validation.
     *
     * @param key         The key that the validation rules are under (the
     *                    form elements name attribute).
     * @param bean        The bean validation is being performed on.
     * @param application servlet context
     * @param request     The current request object.
     * @param errors      The object any errors will be stored in.
     * @param page        This in conjunction with  the page property of a
     *                    <code>Field<code> can control the processing of
     *                    fields.  If the field's page is less than or equal
     *                    to this page value, it will be processed.
     */
public static Validator initValidator(String key, Object bean, ServletContext application, HttpServletRequest request, ActionMessages errors, int page) {
    ValidatorResources resources = Resources.getValidatorResources(application, request);
    Locale locale = RequestUtils.getUserLocale(request, null);
    Validator validator = new Validator(resources, key);
    validator.setUseContextClassLoader(true);
    validator.setPage(page);
    validator.setParameter(SERVLET_CONTEXT_PARAM, application);
    validator.setParameter(HTTP_SERVLET_REQUEST_PARAM, request);
    validator.setParameter(Validator.LOCALE_PARAM, locale);
    validator.setParameter(ACTION_MESSAGES_PARAM, errors);
    validator.setParameter(Validator.BEAN_PARAM, bean);
    return validator;
}
Also used : Locale(java.util.Locale) ValidatorResources(org.apache.commons.validator.ValidatorResources) Validator(org.apache.commons.validator.Validator)

Example 2 with Validator

use of org.apache.commons.validator.Validator in project sonarqube by SonarSource.

the class ValidatorForm method validate.

/**
     * Validate the properties that have been set from this HTTP request, and
     * return an <code>ActionErrors</code> object that encapsulates any
     * validation errors that have been found.  If no errors are found, return
     * <code>null</code> or an <code>ActionErrors</code> object with no
     * recorded error messages.
     *
     * @param mapping The mapping used to select this instance
     * @param request The servlet request we are processing
     * @return <code>ActionErrors</code> object that encapsulates any
     *         validation errors
     */
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ServletContext application = getServlet().getServletContext();
    ActionErrors errors = new ActionErrors();
    String validationKey = getValidationKey(mapping, request);
    Validator validator = Resources.initValidator(validationKey, this, application, request, errors, page);
    try {
        validatorResults = validator.validate();
    } catch (ValidatorException e) {
        log.error(e.getMessage(), e);
    }
    return errors;
}
Also used : ValidatorException(org.apache.commons.validator.ValidatorException) ServletContext(javax.servlet.ServletContext) ActionErrors(org.apache.struts.action.ActionErrors) Validator(org.apache.commons.validator.Validator)

Example 3 with Validator

use of org.apache.commons.validator.Validator in project sonarqube by SonarSource.

the class DynaValidatorForm method validate.

/**
     * Validate the properties that have been set from this HTTP request, and
     * return an <code>ActionErrors</code> object that encapsulates any
     * validation errors that have been found.  If no errors are found, return
     * <code>null</code> or an <code>ActionErrors</code> object with no
     * recorded error messages.
     *
     * @param mapping The mapping used to select this instance.
     * @param request The servlet request we are processing.
     * @return <code>ActionErrors</code> object that encapsulates any
     *         validation errors.
     */
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    this.setPageFromDynaProperty();
    ServletContext application = getServlet().getServletContext();
    ActionErrors errors = new ActionErrors();
    String validationKey = getValidationKey(mapping, request);
    Validator validator = Resources.initValidator(validationKey, this, application, request, errors, page);
    try {
        validatorResults = validator.validate();
    } catch (ValidatorException e) {
        log.error(e.getMessage(), e);
    }
    return errors;
}
Also used : ValidatorException(org.apache.commons.validator.ValidatorException) ServletContext(javax.servlet.ServletContext) ActionErrors(org.apache.struts.action.ActionErrors) Validator(org.apache.commons.validator.Validator)

Aggregations

Validator (org.apache.commons.validator.Validator)3 ServletContext (javax.servlet.ServletContext)2 ValidatorException (org.apache.commons.validator.ValidatorException)2 ActionErrors (org.apache.struts.action.ActionErrors)2 Locale (java.util.Locale)1 ValidatorResources (org.apache.commons.validator.ValidatorResources)1