@Override public void beforeInvocation() { keys.set(new HashMap<Object, String>()); Validation.current.set(new Validation()); }
public ValidationResult valid(Object o) { String key = getLocalName(o); return Validation.valid(key, o); }
public ValidationResult email(Object o) { String key = getLocalName(o); return Validation.email(key, o); }
public ValidationResult equals(Object o, Object to) { String key = getLocalName(o); String otherKey = getLocalName(to); return Validation.equals(key, o, otherKey, to); }
public static void invoke(Http.Request request, Http.Inbound inbound, Http.Outbound outbound) { try { // 1. Easy debugging ... if (Play.mode == Play.Mode.DEV) { WebSocketController.class.getDeclaredField("inbound").set(null, Http.Inbound.current()); WebSocketController.class.getDeclaredField("outbound").set(null, Http.Outbound.current()); WebSocketController.class.getDeclaredField("params").set(null, Scope.Params.current()); WebSocketController.class.getDeclaredField("request").set(null, Http.Request.current()); WebSocketController.class.getDeclaredField("session").set(null, Scope.Session.current()); WebSocketController.class.getDeclaredField("validation").set(null, Validation.current()); } ActionInvoker.invoke(request, null); }catch (PlayException e) { throw e; } catch (Exception e) { throw new UnexpectedException(e); } } }
public static ValidationResult valid(String key, Object o) { ValidCheck check = new ValidCheck(); check.key = key; return applyCheck(check, key, o); }
/** * Add an error * @param field Field name * @param message Message key * @param variables Message variables */ public static void addError(String field, String message, String... variables) { insertError(Validation.current().errors.size(), field, message, variables); }
BeanDescriptor beanDescriptor = play.data.validation.Validation.getValidator().getConstraintsForClass(classType); if (beanDescriptor != null) { PropertyDescriptor property = beanDescriptor.getConstraintsForProperty(leafKey);
/** * Insert an error at the specified position in this list. * @param index index at which the specified element is to be inserted * @param field Field name * @param message Message key * @param variables Message variables */ public static void insertError(int index, String field, String message, String... variables) { Error error = error(field); if (error == null || !error.message.equals(message)) { Validation.current().errors.add(index, new Error(field, message, variables)); } }
public static void _ifErrors(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) { if (Validation.hasErrors()) { body.call(); TagContext.parent().data.put("_executeNextElse", false); } else { TagContext.parent().data.put("_executeNextElse", true); } }
private static void addValidationError(ParamNode paramNode) { Validation.addError(paramNode.getOriginalKey(), "validation.invalid"); }
static ValidationResult applyCheck(AbstractAnnotationCheck<?> check, String key, Object o) { try { ValidationResult result = new ValidationResult(); if (!check.isSatisfied(o, o, null, null)) { Error error = new Error(key, check.getClass() .getDeclaredField("mes").get(null) + "", check.getMessageVariables() == null ? new String[0] : check.getMessageVariables().values() .toArray(new String[0]), check.getSeverity()); Validation.current().errors.add(error); result.error = error; result.ok = false; } else { result.ok = true; } return result; } catch (Exception e) { throw new UnexpectedException(e); } }
public static ValidationResult past(String key, Object o) { InPastCheck check = new InPastCheck(); check.reference = new Date(); return applyCheck(check, key, o); }
BeanDescriptor beanDescriptor = play.data.validation.Validation.getValidator().getConstraintsForClass(classType); if (beanDescriptor != null) { PropertyDescriptor property = beanDescriptor.getConstraintsForProperty(leafKey);
@SuppressWarnings("unchecked") public <T> T get(Annotation[] annotations, String key, Class<T> type) { try { return (T) Binder.directBind(annotations, get(key), type, null); } catch (Exception e) { Logger.error(e, "Failed to get %s of type %s", key, type); Validation.addError(key, "validation.invalid"); return null; } }
boolean validateObject(String key, Object value) { ValidationPlugin.keys.get().put(value, key); List<ConstraintViolation> violations = new Validator().validate(value); // if (violations.isEmpty()) { return true; } else { for (ConstraintViolation violation : violations) { if (violation.getContext() instanceof FieldContext) { FieldContext ctx = (FieldContext) violation.getContext(); String fkey = (key == null ? "" : key + ".") + ctx.getField().getName(); Error error = new Error( fkey, violation.getMessage(), violation.getMessageVariables() == null ? new String[0] : violation.getMessageVariables().values() .toArray(new String[0]), violation.getSeverity()); Validation.current().errors.add(error); } } return false; } }