// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/exception/InvalidRequestParameterException.java
// public class InvalidRequestParameterException extends MissingRequestParameterException {
// 
//     private static final long serialVersionUID = 1L;
//     private final String _parameterValue;
// 
//     public InvalidRequestParameterException(String parameterName, String parameterValue) {
//         super(parameterName, "Invalid request parameter: " + parameterName + " = " + parameterValue);
//         _parameterValue = parameterValue;
//     }
// 
//     public InvalidRequestParameterException(String parameterName, String parameterValue, Throwable cause) {
//         super(parameterName, "Invalid request parameter: " + parameterName + " = " + parameterValue, cause);
//         _parameterValue = parameterValue;
//     }
// 
//     public String getParameterValue() {
//         return _parameterValue;
//     }
// }
// 
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/exception/MissingRequestParameterException.java
// public class MissingRequestParameterException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
//     private final String _parameterName;
// 
//     public MissingRequestParameterException(String parameterName) {
//         super("Missing request parameter: " + parameterName + ".");
//         _parameterName = parameterName;
//     }
// 
//     public MissingRequestParameterException(String parameterName, String message) {
//         super(message);
//         _parameterName = parameterName;
//     }
// 
//     public MissingRequestParameterException(String parameterName, String message, Throwable cause) {
//         super(message, cause);
//         _parameterName = parameterName;
//     }
// 
//     public String getParameterName() {
//         return _parameterName;
//     }
// }


import com.switchfly.inputvalidation.exception.InvalidRequestParameterException;
import com.switchfly.inputvalidation.exception.MissingRequestParameterException;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
/*
 * Copyright 2012 Switchfly
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.switchfly.inputvalidation;


public class RequestParameter extends Parameter<String> {

    public RequestParameter(String name, String value) {
        super(name, value);
        validateWith(ValidationStrategy.DEFAULT_WEB_CONTENT_VALIDATION);
    }

    public boolean isBlank() {
        return StringUtils.isBlank(getValue());
    }

    @Override
    public boolean isEmpty() {
        return isBlank();
    }

    @Override
    public RequestParameter validateWith(ValidationStrategy<String> validationStrategy) {
        super.validateWith(validationStrategy);
        return this;
    }

    @Override
    public String toString() {
        return validate();
    }

    public String toString(String defaultValue) {
        return validate(defaultValue);
    }

    public Double toDouble() {
        String value = toString();
        try {
            return Double.parseDouble(value);
        } catch (NumberFormatException e) {
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/exception/InvalidRequestParameterException.java
// public class InvalidRequestParameterException extends MissingRequestParameterException {
// 
//     private static final long serialVersionUID = 1L;
//     private final String _parameterValue;
// 
//     public InvalidRequestParameterException(String parameterName, String parameterValue) {
//         super(parameterName, "Invalid request parameter: " + parameterName + " = " + parameterValue);
//         _parameterValue = parameterValue;
//     }
// 
//     public InvalidRequestParameterException(String parameterName, String parameterValue, Throwable cause) {
//         super(parameterName, "Invalid request parameter: " + parameterName + " = " + parameterValue, cause);
//         _parameterValue = parameterValue;
//     }
// 
//     public String getParameterValue() {
//         return _parameterValue;
//     }
// }
// 
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/exception/MissingRequestParameterException.java
// public class MissingRequestParameterException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
//     private final String _parameterName;
// 
//     public MissingRequestParameterException(String parameterName) {
//         super("Missing request parameter: " + parameterName + ".");
//         _parameterName = parameterName;
//     }
// 
//     public MissingRequestParameterException(String parameterName, String message) {
//         super(message);
//         _parameterName = parameterName;
//     }
// 
//     public MissingRequestParameterException(String parameterName, String message, Throwable cause) {
//         super(message, cause);
//         _parameterName = parameterName;
//     }
// 
//     public String getParameterName() {
//         return _parameterName;
//     }
// }


// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/RequestParameter.java
import com.switchfly.inputvalidation.exception.InvalidRequestParameterException;
import com.switchfly.inputvalidation.exception.MissingRequestParameterException;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;

/*
 * Copyright 2012 Switchfly
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.switchfly.inputvalidation;


public class RequestParameter extends Parameter<String> {

    public RequestParameter(String name, String value) {
        super(name, value);
        validateWith(ValidationStrategy.DEFAULT_WEB_CONTENT_VALIDATION);
    }

    public boolean isBlank() {
        return StringUtils.isBlank(getValue());
    }

    @Override
    public boolean isEmpty() {
        return isBlank();
    }

    @Override
    public RequestParameter validateWith(ValidationStrategy<String> validationStrategy) {
        super.validateWith(validationStrategy);
        return this;
    }

    @Override
    public String toString() {
        return validate();
    }

    public String toString(String defaultValue) {
        return validate(defaultValue);
    }

    public Double toDouble() {
        String value = toString();
        try {
            return Double.parseDouble(value);
        } catch (NumberFormatException e) {
            throw new InvalidRequestParameterException(getName(), value);