use of com.dexels.navajo.document.PropertyTypeException in project navajo by Dexels.
the class TypeCheckInteger method verify.
@Override
public String verify(Property p, String value) throws com.dexels.navajo.document.PropertyTypeException {
if (value == null) {
return null;
}
value = value.trim();
if ("".equals(value)) {
return value;
}
try {
int v = Integer.parseInt(value);
// Map m = loadSubtypes(p);
String max = p.getSubType("max");
if (max != null) {
int mx = Integer.parseInt(max);
if (v > mx) {
throw new PropertyTypeException(p, "Integer larger than maximum. (" + mx + ">" + v + ")");
}
}
String min = p.getSubType("min");
if (min != null) {
int mn = Integer.parseInt(min);
if (v < mn) {
throw new PropertyTypeException(p, "Integer smaller than minimum. (" + v + "<" + mn + ")");
}
}
} catch (NumberFormatException ex) {
// This is to prevent breaking old code.
if (p.getSubType() != null) {
throw new PropertyTypeException(ex, p, "Not a valid integer. Value: >" + value + "<");
}
}
return value;
}
use of com.dexels.navajo.document.PropertyTypeException in project navajo by Dexels.
the class TypeCheckMoney method verify.
@Override
public String verify(Property p, String value) throws com.dexels.navajo.document.PropertyTypeException {
if (value == null) {
return null;
}
value = value.trim();
if ("".equals(value)) {
return value;
}
try {
double v = Double.parseDouble(value.replace(',', '.'));
// Map m = loadSubtypes(p);
String max = p.getSubType("max");
if (max != null) {
int mx = Integer.parseInt(max);
if (v > mx) {
throw new PropertyTypeException(p, "Money larger than maximum. (" + mx + ">" + v + ")");
}
}
String min = p.getSubType("min");
if (min != null) {
int mn = Integer.parseInt(min);
if (v < mn) {
throw new PropertyTypeException(p, "Money smaller than minimum. (" + v + "<" + mn + ")");
}
}
} catch (NumberFormatException ex) {
// This is to prevent breaking old code.
if (p.getSubType() != null) {
throw new PropertyTypeException(ex, p, "Not a valid money property!");
} else {
logger.info("Warning. Ignoring invalid money: " + value + " for property: " + p.getName());
}
}
return value;
}
Aggregations