myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdebussc...@apache.org
Subject svn commit: r1066037 - in /myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main: java/org/apache/myfaces/extensions/validator/crossval/annotation/ java/org/apache/myfaces/extensions/validator/crossval...
Date Tue, 01 Feb 2011 13:00:00 GMT
Author: rdebusscher
Date: Tue Feb  1 12:59:59 2011
New Revision: 1066037

URL: http://svn.apache.org/viewvc?rev=1066037&view=rev
Log:
EXTVAL-124, EXTVAL-125, EXTVAL-126

Modified:
    myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/DateIs.java
    myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/DateIsType.java
    myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java
    myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/resources/org/apache/myfaces/extensions/validator/crossval/message/bundle/validation_messages.properties

Modified: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/DateIs.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/DateIs.java?rev=1066037&r1=1066036&r2=1066037&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/DateIs.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/DateIs.java
Tue Feb  1 12:59:59 2011
@@ -57,9 +57,15 @@ public @interface DateIs
 
     String notAfterErrorMsgKey() default "wrong_date_not_after";
 
+    String notBeforeOrSameErrorMsgKey() default "wrong_date_not_before_or_same";
+
+    String notAfterOrSameErrorMsgKey() default "wrong_date_not_after_or_same";
+
     String notEqualErrorMsgKey() default "wrong_date_not_equal";
 
     int errorMessageDateStyle() default DateFormat.MEDIUM;
 
+    String errorMessageDatePattern() default "";
+
     Class<? extends ValidationParameter>[] parameters() default ViolationSeverity.Error.class;
 }

Modified: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/DateIsType.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/DateIsType.java?rev=1066037&r1=1066036&r2=1066037&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/DateIsType.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/DateIsType.java
Tue Feb  1 12:59:59 2011
@@ -18,8 +18,6 @@
  */
 package org.apache.myfaces.extensions.validator.crossval.annotation;
 
-import org.apache.myfaces.extensions.validator.internal.ToDo;
-import org.apache.myfaces.extensions.validator.internal.Priority;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
 
@@ -27,9 +25,8 @@ import org.apache.myfaces.extensions.val
  * @author Gerhard Petracek
  * @since 1.x.1
  */
-@ToDo(value = Priority.MEDIUM, description = "beforeOrSame, afterOrSame")
 @UsageInformation(UsageCategory.API)
 public enum DateIsType
 {
-    before, after, same
+    before, after, same, beforeOrSame, afterOrSame
 }

Modified: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java?rev=1066037&r1=1066036&r2=1066037&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java
Tue Feb  1 12:59:59 2011
@@ -19,7 +19,6 @@
 package org.apache.myfaces.extensions.validator.crossval.strategy;
 
 import org.apache.myfaces.extensions.validator.crossval.annotation.DateIs;
-import org.apache.myfaces.extensions.validator.crossval.annotation.DateIsType;
 import org.apache.myfaces.extensions.validator.crossval.annotation.MessageTarget;
 import org.apache.myfaces.extensions.validator.baseval.annotation.SkipValidationSupport;
 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
@@ -27,6 +26,7 @@ import org.apache.myfaces.extensions.val
 
 import javax.faces.context.FacesContext;
 import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.MissingResourceException;
 import java.util.logging.Level;
@@ -41,6 +41,8 @@ public class DateIsStrategy extends Abst
 {
     protected static final String TOO_EARLY = "early";
     protected static final String TOO_LATE = "late";
+    protected static final String TOO_EARLY_SAME = "earlyNotSame";
+    protected static final String TOO_LATE_SAME = "lateNotSame";
     protected static final String NOT_EQUAL_DATE_TIME = "not equal";
     protected static final String RESULT_KEY = "result";
     protected static final String COMPARED_VALUE_KEY = "target value";
@@ -53,36 +55,55 @@ public class DateIsStrategy extends Abst
 
     public boolean isViolation(Object object1, Object object2, DateIs annotation)
     {
-        boolean violationFound;
-
-        if (annotation.type().equals(DateIsType.same))
+        boolean violationFound = false;
+        switch (annotation.type())
         {
-            violationFound = object1 != null && !object1.equals(object2);
-
-            if (violationFound)
-            {
-                this.violationResultStorage.put(RESULT_KEY, NOT_EQUAL_DATE_TIME);
-            }
-        }
-        else if (annotation.type().equals(DateIsType.before))
-        {
-            violationFound = object1 != null && object2 != null &&
-                            (!new Date(((Date) object1).getTime()).before((Date) object2)
|| object1.equals(object2));
-
-            if (violationFound)
-            {
-                this.violationResultStorage.put(RESULT_KEY, TOO_LATE);
-            }
-        }
-        else
-        {
-            violationFound = object1 != null && object2 != null &&
-                            (!new Date(((Date) object1).getTime()).after((Date) object2)
|| object1.equals(object2));
-
-            if (violationFound)
-            {
-                this.violationResultStorage.put(RESULT_KEY, TOO_EARLY);
-            }
+            case before:
+                violationFound = object1 != null && object2 != null &&
+                              (!new Date(((Date) object1).getTime()).before((Date) object2)
|| object1.equals(object2));
+
+                if (violationFound)
+                {
+                    this.violationResultStorage.put(RESULT_KEY, TOO_LATE);
+                }
+                break;
+            case after:
+                violationFound = object1 != null && object2 != null &&
+                               (!new Date(((Date) object1).getTime()).after((Date) object2)
|| object1.equals(object2));
+
+                if (violationFound)
+                {
+                    this.violationResultStorage.put(RESULT_KEY, TOO_EARLY);
+                }
+                break;
+            case same:
+                violationFound = object1 != null && !object1.equals(object2);
+
+                if (violationFound)
+                {
+                    this.violationResultStorage.put(RESULT_KEY, NOT_EQUAL_DATE_TIME);
+                }
+                break;
+            case beforeOrSame:
+                violationFound = object1 != null && object2 != null &&
+                                new Date(((Date) object1).getTime()).after((Date) object2);
+
+                if (violationFound)
+                {
+                    this.violationResultStorage.put(RESULT_KEY, TOO_LATE_SAME);
+                }
+                break;
+            case afterOrSame:
+                violationFound = object1 != null && object2 != null &&
+                                new Date(((Date) object1).getTime()).before((Date) object2);
+
+                if (violationFound)
+                {
+                    this.violationResultStorage.put(RESULT_KEY, TOO_EARLY_SAME);
+                }
+                break;
+            default:
+                // Nothing to do.
         }
 
         if (violationFound)
@@ -115,10 +136,18 @@ public class DateIsStrategy extends Abst
         {
             return getNotAfterErrorMsgKey(annotation);
         }
+        else if (TOO_EARLY_SAME.equals(result))
+        {
+            return getNotAfterOrSameErrorMsgKey(annotation);
+        }
         else if (TOO_LATE.equals(result))
         {
             return getNotBeforeErrorMsgKey(annotation);
         }
+        else if (TOO_LATE_SAME.equals(result))
+        {
+            return getNotBeforeOrSameErrorMsgKey(annotation);
+        }
         else
         {
             return getNotEqualErrorMsgKey(annotation);
@@ -127,35 +156,47 @@ public class DateIsStrategy extends Abst
 
     private String reverseResult(String result)
     {
+
         if (TOO_EARLY.equals(result))
         {
             return TOO_LATE;
         }
-        else
+        else if (TOO_EARLY_SAME.equals(result))
+        {
+            return TOO_LATE_SAME;
+        }
+        else if (TOO_LATE_SAME.equals(result))
+        {
+            return TOO_EARLY_SAME;
+        }
+        else if (TOO_LATE.equals(result))
         {
             return TOO_EARLY;
         }
+        return result;
     }
 
     @Override
     protected String getErrorMessageSummary(DateIs annotation, boolean isTargetComponent)
     {
+        /*
         if (!isTargetComponent)
         {
             return super.getErrorMessageSummary(annotation, isTargetComponent);
         }
-
+        */
         return getErrorMessage(getValidationErrorMsgKey(annotation, isTargetComponent), annotation,
isTargetComponent);
     }
 
     @Override
     protected String getErrorMessageDetail(DateIs annotation, boolean isTargetComponent)
     {
+        /*
         if (!isTargetComponent)
         {
             return super.getErrorMessageDetail(annotation, isTargetComponent);
         }
-
+        */
         try
         {
             return getErrorMessage(getValidationErrorMsgKey(annotation, isTargetComponent)
@@ -195,8 +236,8 @@ public class DateIsStrategy extends Abst
     {
         String message = resolveMessage(key);
 
-        DateFormat dateFormat = DateFormat.getDateInstance(annotation.errorMessageDateStyle(),
-            FacesContext.getCurrentInstance().getViewRoot().getLocale());
+        DateFormat dateFormat = getDateFormat(annotation.errorMessageDateStyle(),
+                annotation.errorMessageDatePattern());
 
         String result;
 
@@ -215,6 +256,15 @@ public class DateIsStrategy extends Abst
         return result;
     }
 
+    private DateFormat getDateFormat(int dateStyle, String datePattern)
+    {
+        if (datePattern == null || datePattern.length() == 0)
+        {
+            return DateFormat.getDateInstance(dateStyle, FacesContext.getCurrentInstance().getViewRoot().getLocale());
+        }
+        return new SimpleDateFormat(datePattern, FacesContext.getCurrentInstance().getViewRoot().getLocale());
+    }
+
     /*
      * private
      */
@@ -227,6 +277,15 @@ public class DateIsStrategy extends Abst
         return annotation.validationErrorMsgKey();
     }
 
+    private String getNotAfterOrSameErrorMsgKey(DateIs annotation)
+    {
+        if (annotation.validationErrorMsgKey().equals(""))
+        {
+            return annotation.notAfterOrSameErrorMsgKey();
+        }
+        return annotation.validationErrorMsgKey();
+    }
+
     private String getNotBeforeErrorMsgKey(DateIs annotation)
     {
         if (annotation.validationErrorMsgKey().equals(""))
@@ -236,6 +295,15 @@ public class DateIsStrategy extends Abst
         return annotation.validationErrorMsgKey();
     }
 
+    private String getNotBeforeOrSameErrorMsgKey(DateIs annotation)
+    {
+        if (annotation.validationErrorMsgKey().equals(""))
+        {
+            return annotation.notBeforeOrSameErrorMsgKey();
+        }
+        return annotation.validationErrorMsgKey();
+    }
+
     private String getNotEqualErrorMsgKey(DateIs annotation)
     {
         if (annotation.validationErrorMsgKey().equals(""))

Modified: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/resources/org/apache/myfaces/extensions/validator/crossval/message/bundle/validation_messages.properties
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/resources/org/apache/myfaces/extensions/validator/crossval/message/bundle/validation_messages.properties?rev=1066037&r1=1066036&r2=1066037&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/resources/org/apache/myfaces/extensions/validator/crossval/message/bundle/validation_messages.properties
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/resources/org/apache/myfaces/extensions/validator/crossval/message/bundle/validation_messages.properties
Tue Feb  1 12:59:59 2011
@@ -27,8 +27,14 @@ wrong_date_detail=Wrong date
 wrong_date_not_before=Date has to be after {0}
 wrong_date_not_before_detail=Date has to be after {0}
 
+wrong_date_not_before_or_same=Date has to be after or equals to {0}
+wrong_date_not_before_or_same_detail=Date has to be after or equals to {0}
+
 wrong_date_not_after=Date has to be before {0}
 wrong_date_not_after_detail=Date has to be before {0}
 
+wrong_date_not_after_or_same=Date has to be before or equals to {0}
+wrong_date_not_after_or_same_detail=Date has to be before or equals to {0}
+
 wrong_date_not_equal=Date isn't equal to {0}
 wrong_date_not_equal_detail=Date isn't equal to {0}
\ No newline at end of file



Mime
View raw message