myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r698338 - in /myfaces/extensions/validator/branches/jsf_1.1: examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/ examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/...
Date Tue, 23 Sep 2008 20:20:12 GMT
Author: gpetracek
Date: Tue Sep 23 13:20:12 2008
New Revision: 698338

URL: http://svn.apache.org/viewvc?rev=698338&view=rev
Log:
new name for the regex annotation

Added:
    myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/annotation/Pattern.java
    myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/PatternStrategy.java
Removed:
    myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/annotation/Regex.java
    myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/RegexStrategy.java
Modified:
    myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java
    myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java

Modified: myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java?rev=698338&r1=698337&r2=698338&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/examples/adapter_demo/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java
Tue Sep 23 13:20:12 2008
@@ -22,7 +22,7 @@
 import org.apache.myfaces.extensions.validator.crossval.annotation.DateIsType;
 import org.apache.myfaces.extensions.validator.crossval.annotation.NotEquals;
 import org.apache.myfaces.extensions.validator.baseval.annotation.Length;
-import org.apache.myfaces.extensions.validator.baseval.annotation.Regex;
+import org.apache.myfaces.extensions.validator.baseval.annotation.Pattern;
 
 import javax.persistence.Column;
 import javax.persistence.Temporal;
@@ -34,7 +34,7 @@
     @Length(minimum = 2)
     @Column(nullable = false, length = 20)
     @NotEquals("lastName")
-    @Regex("[A-Z][a-z]+")
+    @Pattern("[A-Z][a-z]+")
     private String firstName;
 
     @Length(minimum = 2)

Modified: myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java?rev=698338&r1=698337&r2=698338&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java
(original)
+++ myfaces/extensions/validator/branches/jsf_1.1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/domain/Person.java
Tue Sep 23 13:20:12 2008
@@ -22,7 +22,7 @@
 import org.apache.myfaces.extensions.validator.crossval.annotation.DateIsType;
 import org.apache.myfaces.extensions.validator.crossval.annotation.NotEquals;
 import org.apache.myfaces.extensions.validator.baseval.annotation.Length;
-import org.apache.myfaces.extensions.validator.baseval.annotation.Regex;
+import org.apache.myfaces.extensions.validator.baseval.annotation.Pattern;
 
 import javax.persistence.Column;
 import javax.persistence.Temporal;
@@ -34,7 +34,7 @@
     @Length(minimum = 2)
     @Column(nullable = false, length = 20)
     @NotEquals("lastName")
-    @Regex("[A-Z][a-z]+")
+    @Pattern("[A-Z][a-z]+")
     private String firstName;
 
     @Length(minimum = 2)

Added: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/annotation/Pattern.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/annotation/Pattern.java?rev=698338&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/annotation/Pattern.java
(added)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/annotation/Pattern.java
Tue Sep 23 13:20:12 2008
@@ -0,0 +1,37 @@
+/*
+ * 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.baseval.annotation;
+
+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 Gerhard Petracek
+ */
+@Target( { METHOD, FIELD })
+@Retention(RUNTIME)
+public @interface Pattern
+{
+    String[] value();
+
+    String validationErrorMsgKey() default "no_match";
+}

Added: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/PatternStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/PatternStrategy.java?rev=698338&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/PatternStrategy.java
(added)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/strategy/PatternStrategy.java
Tue Sep 23 13:20:12 2008
@@ -0,0 +1,63 @@
+/*
+ * 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.baseval.strategy;
+
+import org.apache.myfaces.extensions.validator.baseval.annotation.Pattern;
+import org.apache.myfaces.extensions.validator.core.annotation.AnnotationEntry;
+import org.apache.myfaces.extensions.validator.core.validation.strategy.AbstractValidationStrategy;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
+import java.lang.annotation.Annotation;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class PatternStrategy extends AbstractValidationStrategy
+{
+
+    protected void processValidation(FacesContext facesContext,
+            UIComponent uiComponent, AnnotationEntry annotationEntry,
+            Object convertedObject) throws ValidatorException
+    {
+
+        Pattern annotation = annotationEntry.getAnnotation(Pattern.class);
+
+        for (String expression : annotation.value())
+        {
+            if (convertedObject == null
+                    || !java.util.regex.Pattern.compile(expression).matcher(
+                            convertedObject.toString()).matches())
+            {
+                throw new ValidatorException(new FacesMessage(
+                        FacesMessage.SEVERITY_ERROR,
+                        getErrorMessageSummary(annotation),
+                        getErrorMessageDetails(annotation).replace("{0}",
+                                expression)));
+            }
+        }
+    }
+
+    protected String getValidationErrorMsgKey(Annotation annotation)
+    {
+        return ((Pattern) annotation).validationErrorMsgKey();
+    }
+}



Mime
View raw message