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/04/02 22:12:42 UTC
svn commit: r930369 - in /myfaces/extensions/validator/trunk:
core/src/main/java/org/apache/myfaces/extensions/validator/core/
core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/
test-modules/property-validation-tests/src/test/...
Author: gpetracek
Date: Fri Apr 2 20:12:42 2010
New Revision: 930369
URL: http://svn.apache.org/viewvc?rev=930369&view=rev
Log:
EXTVAL-88 thanks to Rudy De Busscher and minor changes
Added:
myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/EqualsStringTestBean.java
myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/EqualsStringTestCase.java
myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/NotEqualsStringTestBean.java
myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/NotEqualsStringTestCase.java
myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/parameter/
myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/parameter/CaseInsensitive.java
Modified:
myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InvocationOrderComparator.java
myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java
myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/EqualsStrategy.java
Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InvocationOrderComparator.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InvocationOrderComparator.java?rev=930369&r1=930368&r2=930369&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InvocationOrderComparator.java (original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InvocationOrderComparator.java Fri Apr 2 20:12:42 2010
@@ -22,14 +22,17 @@ import org.apache.myfaces.extensions.val
import org.apache.myfaces.extensions.validator.internal.UsageCategory;
import java.util.Comparator;
+import java.io.Serializable;
/**
* @author Gerhard Petracek
* @since x.x.3
*/
@UsageInformation(UsageCategory.INTERNAL)
-public class InvocationOrderComparator<T> implements Comparator<T>
+public class InvocationOrderComparator<T> implements Comparator<T>, Serializable
{
+ private static final long serialVersionUID = 2287258656373616584L;
+
public int compare(T nm1, T nm2)
{
if (hasPriority(nm1) && hasPriority(nm2))
Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java?rev=930369&r1=930368&r2=930369&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java (original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java Fri Apr 2 20:12:42 2010
@@ -283,9 +283,9 @@ public abstract class AbstractValidation
RendererInterceptorPropertyStorage interceptorPropertyStorage = getRendererInterceptorPropertyStorage();
Map<String, Object> properties = getInterceptorProperties(uiComponent);
- for(String key : properties.keySet())
+ for(Map.Entry<String, Object> entry : properties.entrySet())
{
- interceptorPropertyStorage.setProperty(key, properties.get(key));
+ interceptorPropertyStorage.setProperty(entry.getKey(), entry.getValue());
}
}
Added: myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/EqualsStringTestBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/EqualsStringTestBean.java?rev=930369&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/EqualsStringTestBean.java (added)
+++ myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/EqualsStringTestBean.java Fri Apr 2 20:12:42 2010
@@ -0,0 +1,64 @@
+/*
+ * 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.test.propval.crossval;
+
+import org.apache.myfaces.extensions.validator.crossval.annotation.Equals;
+import org.apache.myfaces.extensions.validator.crossval.parameter.CaseInsensitive;
+
+public class EqualsStringTestBean
+{
+ private String property1;
+
+ @Equals(value = "property1")
+ private String property2;
+
+ @Equals(value = "property1", parameters = CaseInsensitive.class)
+ private String property3;
+
+ public String getProperty1()
+ {
+ return property1;
+ }
+
+ public void setProperty1(String property1)
+ {
+ this.property1 = property1;
+ }
+
+ public String getProperty2()
+ {
+ return property2;
+ }
+
+ public void setProperty2(String property2)
+ {
+ this.property2 = property2;
+ }
+
+ public String getProperty3()
+ {
+ return property3;
+ }
+
+ public void setProperty3(String property3)
+ {
+ this.property3 = property3;
+ }
+
+}
Added: myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/EqualsStringTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/EqualsStringTestCase.java?rev=930369&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/EqualsStringTestCase.java (added)
+++ myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/EqualsStringTestCase.java Fri Apr 2 20:12:42 2010
@@ -0,0 +1,147 @@
+/*
+ * 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.test.propval.crossval;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.myfaces.extensions.validator.crossval.CrossValidationPhaseListener;
+import org.apache.myfaces.extensions.validator.test.propval.AbstractPropertyValidationTestCase;
+
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+
+public class EqualsStringTestCase extends AbstractPropertyValidationTestCase
+{
+
+ HtmlInputText inputComponent1 = null;
+ HtmlInputText inputComponent2 = null;
+
+ UIViewRoot rootComponent = null;
+
+ public EqualsStringTestCase(String name)
+ {
+ super(name);
+ inputComponent1 = null;
+ inputComponent2 = null;
+ rootComponent = null;
+ }
+
+
+ public static Test suite()
+ {
+ return new TestSuite(EqualsStringTestCase.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ EqualsStringTestBean bean = new EqualsStringTestBean();
+ createValueBinding(null, "value", "#{testBean}");
+ facesContext.getExternalContext().getRequestMap().put("testBean", bean);
+
+ rootComponent = new UIViewRoot();
+ HtmlForm form = new HtmlForm();
+ form.setId("form");
+ rootComponent.getChildren().add(form);
+ inputComponent1 = new HtmlInputText();
+ form.getChildren().add(inputComponent1);
+ inputComponent1.setId("input1");
+ inputComponent2 = new HtmlInputText();
+ form.getChildren().add(inputComponent2);
+ inputComponent2.setId("input2");
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ public void testEqualsCaseSensitiveSame() throws Exception
+ {
+ createValueBinding(inputComponent1, "value", "#{testBean.property1}");
+ createValueBinding(inputComponent2, "value", "#{testBean.property2}");
+
+ //decode
+ inputComponent1.setSubmittedValue("1d3");
+ inputComponent2.setSubmittedValue("1d3");
+
+ //validate
+ inputComponent1.validate(facesContext);
+ inputComponent2.validate(facesContext);
+
+ processCrossValidation();
+ checkMessageCount(0);
+ }
+
+ public void testEqualsCaseSensitiveDifferent() throws Exception
+ {
+ createValueBinding(inputComponent1, "value", "#{testBean.property1}");
+ createValueBinding(inputComponent2, "value", "#{testBean.property2}");
+
+ //decode
+ inputComponent1.setSubmittedValue("1d3");
+ inputComponent2.setSubmittedValue("1D3");
+
+ //validate
+ inputComponent1.validate(facesContext);
+ inputComponent2.validate(facesContext);
+
+ processCrossValidation();
+ checkMessageCount(2); // For each field a message
+ }
+
+ public void testEqualsCaseInsensitiveSame() throws Exception
+ {
+ createValueBinding(inputComponent1, "value", "#{testBean.property1}");
+ createValueBinding(inputComponent2, "value", "#{testBean.property3}");
+
+ //decode
+ inputComponent1.setSubmittedValue("1d3");
+ inputComponent2.setSubmittedValue("1d3");
+
+ //validate
+ inputComponent1.validate(facesContext);
+ inputComponent2.validate(facesContext);
+
+ processCrossValidation();
+ checkMessageCount(0);
+ }
+
+ public void testEqualsCaseInsensitiveDifferent() throws Exception
+ {
+ createValueBinding(inputComponent1, "value", "#{testBean.property1}");
+ createValueBinding(inputComponent2, "value", "#{testBean.property3}");
+
+ //decode
+ inputComponent1.setSubmittedValue("1d3");
+ inputComponent2.setSubmittedValue("1D3");
+
+ //validate
+ inputComponent1.validate(facesContext);
+ inputComponent2.validate(facesContext);
+
+ processCrossValidation();
+ checkMessageCount(0); // Due to extra parameter attribute, no longer an error.
+ }
+}
Added: myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/NotEqualsStringTestBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/NotEqualsStringTestBean.java?rev=930369&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/NotEqualsStringTestBean.java (added)
+++ myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/NotEqualsStringTestBean.java Fri Apr 2 20:12:42 2010
@@ -0,0 +1,65 @@
+/*
+ * 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.test.propval.crossval;
+
+import org.apache.myfaces.extensions.validator.crossval.annotation.NotEquals;
+import org.apache.myfaces.extensions.validator.crossval.parameter.CaseInsensitive;
+
+public class NotEqualsStringTestBean
+{
+
+ private String property1;
+
+ @NotEquals(value = "property1")
+ private String property2;
+
+ @NotEquals(value = "property1", parameters = CaseInsensitive.class)
+ private String property3;
+
+ public String getProperty1()
+ {
+ return property1;
+ }
+
+ public void setProperty1(String property1)
+ {
+ this.property1 = property1;
+ }
+
+ public String getProperty2()
+ {
+ return property2;
+ }
+
+ public void setProperty2(String property2)
+ {
+ this.property2 = property2;
+ }
+
+ public String getProperty3()
+ {
+ return property3;
+ }
+
+ public void setProperty3(String property3)
+ {
+ this.property3 = property3;
+ }
+
+}
Added: myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/NotEqualsStringTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/NotEqualsStringTestCase.java?rev=930369&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/NotEqualsStringTestCase.java (added)
+++ myfaces/extensions/validator/trunk/test-modules/property-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/propval/crossval/NotEqualsStringTestCase.java Fri Apr 2 20:12:42 2010
@@ -0,0 +1,156 @@
+/*
+ * 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.test.propval.crossval;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.myfaces.extensions.validator.crossval.CrossValidationPhaseListener;
+import org.apache.myfaces.extensions.validator.test.propval.AbstractPropertyValidationTestCase;
+
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+
+public class NotEqualsStringTestCase extends AbstractPropertyValidationTestCase
+{
+
+ HtmlInputText inputComponent1 = null;
+ HtmlInputText inputComponent2 = null;
+
+ UIViewRoot rootComponent = null;
+
+ public NotEqualsStringTestCase(String name)
+ {
+ super(name);
+ inputComponent1 = null;
+ inputComponent2 = null;
+ rootComponent = null;
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(NotEqualsStringTestCase.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ NotEqualsStringTestBean bean = new NotEqualsStringTestBean();
+ createValueBinding(null, "value", "#{testBean}");
+ facesContext.getExternalContext().getRequestMap().put("testBean", bean);
+
+ rootComponent = new UIViewRoot();
+ HtmlForm form = new HtmlForm();
+ form.setId("form");
+ rootComponent.getChildren().add(form);
+ inputComponent1 = new HtmlInputText();
+ form.getChildren().add(inputComponent1);
+ inputComponent1.setId("input1");
+ inputComponent2 = new HtmlInputText();
+ form.getChildren().add(inputComponent2);
+ inputComponent2.setId("input2");
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ public void testEqualsCaseSensitiveSame() throws Exception
+ {
+ createValueBinding(inputComponent1, "value", "#{testBean.property1}");
+ createValueBinding(inputComponent2, "value", "#{testBean.property2}");
+
+ //decode
+ inputComponent1.setSubmittedValue("1d3");
+ inputComponent2.setSubmittedValue("1d3");
+
+ //validate
+ inputComponent1.validate(facesContext);
+ inputComponent2.validate(facesContext);
+
+ processCrossValidation();
+ checkMessageCount(2); // For each field a message
+
+ }
+
+ public void testEqualsCaseSensitiveDifferent() throws Exception
+ {
+ createValueBinding(inputComponent1, "value", "#{testBean.property1}");
+ createValueBinding(inputComponent2, "value", "#{testBean.property2}");
+
+ //decode
+ inputComponent1.setSubmittedValue("1d3");
+ inputComponent2.setSubmittedValue("1D3");
+
+ //validate
+ inputComponent1.validate(facesContext);
+ inputComponent2.validate(facesContext);
+
+ processCrossValidation();
+ checkMessageCount(0);
+
+ }
+
+ public void testEqualsCaseInsensitiveSame() throws Exception
+ {
+ createValueBinding(inputComponent1, "value", "#{testBean.property1}");
+ createValueBinding(inputComponent2, "value", "#{testBean.property3}");
+
+ //decode
+ inputComponent1.setSubmittedValue("1d3");
+ inputComponent2.setSubmittedValue("1d3");
+
+ //validate
+ inputComponent1.validate(facesContext);
+ inputComponent2.validate(facesContext);
+
+ processCrossValidation();
+ checkMessageCount(2);// For each field a message
+
+ }
+
+ public void testEqualsCaseInsensitiveDifferent() throws Exception
+ {
+ createValueBinding(inputComponent1, "value", "#{testBean.property1}");
+ createValueBinding(inputComponent2, "value", "#{testBean.property3}");
+
+ //decode
+ inputComponent1.setSubmittedValue("1d3");
+ inputComponent2.setSubmittedValue("1D3");
+
+ //validate
+ inputComponent1.validate(facesContext);
+ inputComponent2.validate(facesContext);
+
+ processCrossValidation();
+ checkMessageCount(2); // For each field a message, due to the extra parameter now evaluated as same and thus error
+
+ }
+
+ protected void processCrossValidation()
+ {
+ new CrossValidationPhaseListener().afterPhase(new PhaseEvent(
+ facesContext, PhaseId.ANY_PHASE, lifecycle));
+ }
+}
Added: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/parameter/CaseInsensitive.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/parameter/CaseInsensitive.java?rev=930369&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/parameter/CaseInsensitive.java (added)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/parameter/CaseInsensitive.java Fri Apr 2 20:12:42 2010
@@ -0,0 +1,32 @@
+/*
+ * 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.parameter;
+
+import org.apache.myfaces.extensions.validator.core.validation.parameter.ValidationParameter;
+
+/**
+ * Allows to perform a case insensitive comparison of Strings in Equals and
+ * NotEquals. Specify it as a parameter.
+ *
+ * @author Rudy De Busscher
+ * @since x.x.4
+ */
+public interface CaseInsensitive extends ValidationParameter
+{
+}
Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/EqualsStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/EqualsStrategy.java?rev=930369&r1=930368&r2=930369&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/EqualsStrategy.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/EqualsStrategy.java Fri Apr 2 20:12:42 2010
@@ -18,13 +18,15 @@
*/
package org.apache.myfaces.extensions.validator.crossval.strategy;
-import org.apache.myfaces.extensions.validator.crossval.storage.CrossValidationStorageEntry;
-import org.apache.myfaces.extensions.validator.crossval.annotation.Equals;
import org.apache.myfaces.extensions.validator.baseval.annotation.SkipValidationSupport;
-import org.apache.myfaces.extensions.validator.internal.UsageInformation;
-import org.apache.myfaces.extensions.validator.internal.UsageCategory;
-import org.apache.myfaces.extensions.validator.core.validation.NullValueAwareValidationStrategy;
import org.apache.myfaces.extensions.validator.core.validation.EmptyValueAwareValidationStrategy;
+import org.apache.myfaces.extensions.validator.core.validation.NullValueAwareValidationStrategy;
+import org.apache.myfaces.extensions.validator.crossval.annotation.Equals;
+import org.apache.myfaces.extensions.validator.crossval.parameter.CaseInsensitive;
+import org.apache.myfaces.extensions.validator.crossval.storage.CrossValidationStorageEntry;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
import java.lang.annotation.Annotation;
@@ -51,6 +53,13 @@ public class EqualsStrategy extends Abst
public boolean isViolation(Object object1, Object object2, Annotation annotation)
{
+ if (object1 instanceof String && object2 instanceof String)
+ {
+ if (!isCaseSensitiveCompare(annotation))
+ {
+ return !((String) object1).equalsIgnoreCase((String) object2);
+ }
+ }
return object1 != null && !object1.equals(object2);
}
@@ -58,4 +67,11 @@ public class EqualsStrategy extends Abst
{
return ((Equals) annotation).value();
}
+
+ protected boolean isCaseSensitiveCompare(Annotation annotation)
+ {
+ return !ExtValUtils.getValidationParameterExtractor()
+ .extract(annotation, ExtValUtils.getValidationParameterClassFor(CaseInsensitive.class))
+ .iterator().hasNext();
+ }
}
\ No newline at end of file