changeset 8636:7d1a32a543cb

(issue1755) Extend validation to allow localized error messages.
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 27 Mar 2015 16:54:56 +0100
parents c421c9530aba
children 5a5331dd3e8d
files artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/states/DefaultState.java
diffstat 2 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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) { }
 
--- 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

http://dive4elements.wald.intevation.org