You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2010/05/13 23:57:44 UTC

svn commit: r944028 - in /myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval: annotation/EmptyIf.java strategy/EmptyIfStrategy.java

Author: gpetracek
Date: Thu May 13 21:57:44 2010
New Revision: 944028

URL: http://svn.apache.org/viewvc?rev=944028&view=rev
Log:
EXTVAL-75 thx to Rudy De Busscher

Added:
    myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/EmptyIf.java
    myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/EmptyIfStrategy.java

Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/EmptyIf.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/EmptyIf.java?rev=944028&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/EmptyIf.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/annotation/EmptyIf.java Thu May 13 21:57:44 2010
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.crossval.annotation;
+
+import org.apache.myfaces.extensions.validator.core.validation.parameter.ValidationParameter;
+import org.apache.myfaces.extensions.validator.core.validation.parameter.ViolationSeverity;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * @author Rudy De Busscher
+ */
+@Target({METHOD, FIELD})
+@Retention(RUNTIME)
+@Documented
+@UsageInformation(UsageCategory.API)
+public @interface EmptyIf
+{
+    String[] valueOf();
+
+    /*
+      * optional section
+      */
+
+    RequiredIfType is() default RequiredIfType.not_empty;
+
+    String validationErrorMsgKey() default "field_not_empty";
+
+    Class<? extends ValidationParameter>[] parameters() default ViolationSeverity.Error.class;
+}

Added: myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/EmptyIfStrategy.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/EmptyIfStrategy.java?rev=944028&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/EmptyIfStrategy.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_2_0/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/EmptyIfStrategy.java Thu May 13 21:57:44 2010
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.crossval.strategy;
+
+import org.apache.myfaces.extensions.validator.crossval.annotation.EmptyIf;
+import org.apache.myfaces.extensions.validator.crossval.annotation.RequiredIfType;
+
+/**
+ * @author Rudy De Busscher
+ */
+public class EmptyIfStrategy extends AbstractCompareStrategy<EmptyIf>
+{
+    @Override
+    protected String getValidationErrorMsgKey(EmptyIf annotation, boolean isTargetComponent)
+    {
+        return annotation.validationErrorMsgKey();
+    }
+
+    @Override
+    public String[] getValidationTargets(EmptyIf annotation)
+    {
+        return annotation.valueOf();
+    }
+
+    @Override
+    public boolean isViolation(Object source, Object target, EmptyIf annotation)
+    {
+        boolean violationFound = false;
+
+        if (annotation.is().equals(RequiredIfType.empty))
+        {
+            violationFound = (isTargetEmpty(target) || Boolean.FALSE.equals(target)) && !isSourceEmpty(source);
+        }
+        else if (annotation.is().equals(RequiredIfType.not_empty))
+        {
+            violationFound = (!isSourceEmpty(source) && !isTargetEmpty(target) && !(target instanceof Boolean)) ||
+                    (Boolean.TRUE.equals(target) && !isSourceEmpty(source));
+        }
+
+        return violationFound;
+    }
+
+    private boolean isTargetEmpty(Object target)
+    {
+        return target == null || target.equals("");
+    }
+
+    private boolean isSourceEmpty(Object source)
+    {
+        return source == null || source.equals("");
+    }
+}