All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.plugins.pmd.util.ThresholdValidator Maven / Gradle / Ivy

Go to download

This plug-in generates the trend report for PMD, an open source static code analysis program.

There is a newer version: 3.12
Show newest version
package hudson.plugins.pmd.util;

import hudson.util.FormFieldValidator;

import java.io.IOException;

import javax.servlet.ServletException;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

/**
 * Validates a threshold parameter. A threshold must be an integer value greater
 * or equal 0.
 *
 * @author Ulli Hafner
 */
public class ThresholdValidator extends FormFieldValidator {
    /** Error message. */
    private static final String MESSAGE = "Threshold must be an integer value greater or equal 0.";

    /**
     * Creates a new instance of NumberValidator.
     * @param request
     *            Stapler request
     * @param response
     *            Stapler response
     */
    public ThresholdValidator(final StaplerRequest request, final StaplerResponse response) {
        super(request, response, false);
    }

    /** {@inheritDoc} */
    @Override
    protected void check() throws IOException, ServletException {
        String value = request.getParameter("value");
        if (!StringUtils.isEmpty(value)) {
            try {
                int integer = Integer.valueOf(value);
                if (integer < 0) {
                    error(MESSAGE);
                }
            }
            catch (NumberFormatException exception) {
                error(MESSAGE);
            }
        }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy