Example usage for org.apache.wicket.util.string StringValueConversionException StringValueConversionException

List of usage examples for org.apache.wicket.util.string StringValueConversionException StringValueConversionException

Introduction

In this page you can find the example usage for org.apache.wicket.util.string StringValueConversionException StringValueConversionException.

Prototype

public StringValueConversionException(final String message) 

Source Link

Document

Constructor.

Usage

From source file:name.martingeisse.wicket.util.StringValueUtil.java

License:Open Source License

/**
 * Decodes an integer parameter with the specified lower and upper cap. Throws a
 * {@link StringValueConversionException} if the value is empty, malformed,
 * or outside the allowed range. //  w w  w  . j av  a  2 s  . com
 * 
 * @param value the value
 * @param lowerCap the lower bound for the value
 * @param upperCap the upper bound for the value
 * @return the decoded value
 */
public static Integer getMandatoryRangeCappedInteger(StringValue value, int lowerCap, int upperCap) {
    int decoded = value.toInt();
    if (decoded < lowerCap || decoded > upperCap) {
        String lowerCapText = (lowerCap == Integer.MIN_VALUE ? "*" : Integer.toString(lowerCap));
        String upperCapText = (upperCap == Integer.MAX_VALUE ? "*" : Integer.toString(upperCap));
        throw new StringValueConversionException(
                "value " + decoded + " is outside the allowed range: " + lowerCapText + " .. " + upperCapText);
    }
    return decoded;
}

From source file:org.hippoecm.frontend.plugin.config.impl.AbstractPluginDecorator.java

License:Apache License

@Override
public double getDouble(String key) throws StringValueConversionException {
    Object value = get(key);//from ww  w.ja va  2  s . c  o m
    if (value == null) {
        throw new StringValueConversionException("Key '" + key + "' not found");
    }
    if (value instanceof Double) {
        return (Double) value;
    }
    final String s = value.toString();
    try {
        return Double.parseDouble(s);
    } catch (NumberFormatException e) {
        throw new StringValueConversionException("Cannot convert '" + s + "' to double value", e);
    }
}