[PATCH 1 of 5] (issue1755) Extend validation to allow localized error messages

Wald Commits scm-commit at wald.intevation.org
Fri Mar 27 17:31:20 CET 2015


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1427471696 -3600
# Node ID 7d1a32a543cb5d9b988980efaa8d93ec8fadb9d5
# Parent  c421c9530abacb62abe64164ac3b3388505ea751
(issue1755) Extend validation to allow localized error messages.

diff -r c421c9530aba -r 7d1a32a543cb artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java	Fri Mar 27 14:39:01 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java	Fri Mar 27 16:54:56 2015 +0100
@@ -1078,7 +1078,7 @@
             }
         }
 
-        current.validate(this);
+        current.validate(this, context);
     }
 
 
@@ -1260,9 +1260,12 @@
         DefaultState cur = (DefaultState) getCurrentState(context);
 
         try {
-            if (cur.validate(this)) {
-                return getOutputForState(cur);
+            if (context instanceof CallContext) {
+                /* should be always true */
+                CallContext cc = (CallContext) context;
+                cur.validate(this, cc);
             }
+            return getOutputForState(cur);
         }
         catch (IllegalArgumentException iae) { }
 
diff -r c421c9530aba -r 7d1a32a543cb artifacts/src/main/java/org/dive4elements/river/artifacts/states/DefaultState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/DefaultState.java	Fri Mar 27 14:39:01 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/DefaultState.java	Fri Mar 27 16:54:56 2015 +0100
@@ -419,13 +419,20 @@
     }
 
 
+    /** Override this to do validation.
+     *
+     * Throw an IllegalArgumentException with a localized
+     * error message that should be presented to the user in case
+     * the date provided is invalid. */
+    public void validate(Artifact artifact, CallContext context)
+    throws IllegalArgumentException {
+        validate(artifact); /* For compatibility so that classes that
+                               override this method still work. */
+    }
     /**
-     * This method validates the inserted data and returns true, if everything
-     * was correct, otherwise an exception is thrown.
-     *
-     * @param artifact A reference to the owner artifact.
-     *
-     * @return true, if everything was fine.
+     * This method is deprecated.
+     * Override the function with the callcontext instead to do
+     * localization of error.s
      */
     public boolean validate(Artifact artifact)
     throws IllegalArgumentException


More information about the Dive4Elements-commits mailing list