use of com.haulmont.cuba.gui.components.ValidationException in project cuba by cuba-platform.
the class DoubleValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
boolean result;
if (value instanceof String) {
try {
Datatype<Double> datatype = Datatypes.getNN(Double.class);
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
Double num = datatype.parse((String) value, sessionSource.getLocale());
result = checkDoubleOnPositive(num);
} catch (ParseException e) {
result = false;
}
} else {
result = (value instanceof Double && checkDoubleOnPositive((Double) value)) || (value instanceof BigDecimal && checkBigDecimalOnPositive((BigDecimal) value));
}
if (!result) {
String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'";
throw new ValidationException(String.format(msg, value));
}
}
use of com.haulmont.cuba.gui.components.ValidationException in project cuba by cuba-platform.
the class IntegerValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
boolean result;
if (value instanceof String) {
try {
Datatype<Integer> datatype = Datatypes.getNN(Integer.class);
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
Integer num = datatype.parse((String) value, sessionSource.getLocale());
result = checkIntegerOnPositive(num);
} catch (ParseException e) {
result = false;
}
} else {
result = value instanceof Integer && checkIntegerOnPositive((Integer) value);
}
if (!result) {
String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'";
throw new ValidationException(String.format(msg, value));
}
}
use of com.haulmont.cuba.gui.components.ValidationException in project cuba by cuba-platform.
the class LongValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
boolean result;
if (value instanceof String) {
try {
Datatype<Long> datatype = Datatypes.getNN(Long.class);
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
Long num = datatype.parse((String) value, sessionSource.getLocale());
result = checkPositive(num);
} catch (ParseException e) {
result = false;
}
} else {
result = value instanceof Long && checkPositive((Long) value);
}
if (!result) {
String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'";
throw new ValidationException(String.format(msg, value));
}
}
use of com.haulmont.cuba.gui.components.ValidationException in project cuba by cuba-platform.
the class SizeWithUnitValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
if (value == null) {
return;
}
MessageTools messages = AppBeans.get(MessageTools.NAME);
if (!(value instanceof String)) {
throw new ValidationException(messages.loadString(messagesPack, message));
}
String s = (String) value;
s = s.trim();
if ("".equals(value)) {
return;
}
Matcher matcher = Pattern.compile(SIZE_PATTERN).matcher(s);
if (!matcher.find()) {
throw new ValidationException(messages.loadString(messagesPack, message));
}
double size = Double.parseDouble(matcher.group(1));
String symbol = matcher.group(2);
if ("%".equals(symbol)) {
if (size < 1 || size > MAX_SIZE_PERCENTS) {
throw new ValidationException(messages.loadString(messagesPack, message));
}
} else if ("px".equals(symbol) || symbol == null) {
if (size < 1 || size > MAX_SIZE_PIXELS) {
throw new ValidationException(messages.loadString(messagesPack, message));
}
}
}
use of com.haulmont.cuba.gui.components.ValidationException in project cuba by cuba-platform.
the class CronValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
if (value != null) {
ServerInfoService serverInfoService = AppBeans.get(ServerInfoService.NAME);
Messages messages = AppBeans.get(Messages.NAME);
try {
new CronSequenceGenerator(value.toString(), serverInfoService.getTimeZone());
} catch (Exception e) {
throw new ValidationException(messages.getMessage(CronValidator.class, "validation.cronInvalid"));
}
}
}
Aggregations